Skip to content

declare_dependency variable's value cannot be an unstatable file #13584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Ericson2314 opened this issue Aug 21, 2024 · 1 comment · Fixed by #14342
Closed

declare_dependency variable's value cannot be an unstatable file #13584

Ericson2314 opened this issue Aug 21, 2024 · 1 comment · Fixed by #14342
Assignees
Labels
bug exception Major bug that raises a python-level exception pathlib upgrading to/downgrading from pathlib.Path--including temporary workarounds for older Python

Comments

@Ericson2314
Copy link
Member

Describe the bug

The declare_dependency extra variable logic does not work with strings that are unreadable files, at least on macOS.

To Reproduce

Given /absolute/path/to/disallowed is a directory without permission to read (I tried chmod 000)

project('foo')

declare_dependency(
  variables: {
    'foo': '/absolute/path/to/disallowed/cant-look-inside-at-me'
  }
)

I get

  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/mesonmain.py", line 270, in run
    return msetup.run(['--reconfigure'] + args[2:])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/msetup.py", line 363, in run
    app.generate()
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/msetup.py", line 187, in generate
    return self._generate(env, capture, vslite_ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/msetup.py", line 226, in _generate
    intr.run()
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/interpreter/interpreter.py", line 3011, in run
    super().run()
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 162, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 188, in evaluate_codeblock
    raise e
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 180, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 194, in evaluate_statement
    return self.function_call(cur)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 520, in function_call
    res = func(node, func_args, kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/interpreterbase/decorators.py", line 53, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/interpreterbase/decorators.py", line 569, in wrapper
    return f(*wrapped_args, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/5s1iy38gicvf90a9k0dn0b2x1kb072zm-meson-1.4.2/lib/python3.11/site-packages/mesonbuild/interpreter/interpreter.py", line 714, in func_declare_dependency
    if p.is_absolute() and p.is_dir() and srcdir / self.root_subdir in [p] + list(Path(os.path.abspath(p)).parents):
                           ^^^^^^^^^^
  File "/nix/store/7m3ii30148dwjmfvl9w0m51idnv3y91m-python3-3.11.9/lib/python3.11/pathlib.py", line 1250, in is_dir
    return S_ISDIR(self.stat().st_mode)
                   ^^^^^^^^^^^
  File "/nix/store/7m3ii30148dwjmfvl9w0m51idnv3y91m-python3-3.11.9/lib/python3.11/pathlib.py", line 1013, in stat
    return os.stat(self, follow_symlinks=follow_symlinks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/Users/jcericson/src/nix/build/secret/asdf'

ERROR: Unhandled python OSError. This is probably not a Meson bug, but an issue with your build environment.

Expected behavior

Variable works, can be queried later.

*system parameters

Meson 1.4.2 on macOS

$ sw_vers
ProductName:		macOS
ProductVersion:		13.4.1
BuildVersion:		22F82
@Ericson2314
Copy link
Member Author

(minimized from NixOS/nix#11302 (comment))

@bonzini bonzini self-assigned this Mar 7, 2025
bonzini added a commit to bonzini/meson that referenced this issue Mar 7, 2025
If a directory that is passed to declare_dependency is not accessible
(a parent has the x permission cleared), this can result in an OSError:

    ERROR: Unhandled python OSError. This is probably not a Meson bug, but an issue with your build environment.

This can cause false positives, for example, if the directory is
under /var and root-owned.  Do the is_dir() test last, once it's known
that the directory is related to the source directory, to avoid the
false positives.

Fixes: mesonbuild#13584
@bonzini bonzini added bug exception Major bug that raises a python-level exception labels Mar 7, 2025
@bonzini bonzini added the pathlib upgrading to/downgrading from pathlib.Path--including temporary workarounds for older Python label Mar 10, 2025
Ericson2314 added a commit to NixOS/nix that referenced this issue Apr 24, 2025
Upstream bug is mesonbuild/meson#13584.

This PR will fail for now, but eventually after Meson is bumped in
Nixpkgs, it will succeed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug exception Major bug that raises a python-level exception pathlib upgrading to/downgrading from pathlib.Path--including temporary workarounds for older Python
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants