Skip to content

avoid false positive PermissionError in declare_dependency #14342

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

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,20 +703,18 @@ def func_declare_dependency(self, node: mparser.BaseNode, args: T.List[TYPE_var]
version = self.project_version
d_module_versions = kwargs['d_module_versions']
d_import_dirs = self.extract_incdirs(kwargs, 'd_import_dirs')
srcdir = Path(self.environment.source_dir)
srcdir = self.environment.source_dir
subproject_dir = os.path.abspath(os.path.join(srcdir, self.subproject_dir))
project_root = os.path.abspath(os.path.join(srcdir, self.root_subdir))
# convert variables which refer to an -uninstalled.pc style datadir
for k, v in variables.items():
if not v:
FeatureNew.single_use('empty variable value in declare_dependency', '1.4.0', self.subproject, location=node)
try:
p = Path(v)
except ValueError:
continue
else:
if not self.is_subproject() and srcdir / self.subproject_dir in p.parents:
continue
if p.is_absolute() and p.is_dir() and srcdir / self.root_subdir in [p] + list(Path(os.path.abspath(p)).parents):
variables[k] = P_OBJ.DependencyVariableString(v)
if os.path.isabs(v) \
and (self.is_subproject() or not is_parent_path(subproject_dir, v)) \
and is_parent_path(project_root, v) \
and os.path.isdir(v):
variables[k] = P_OBJ.DependencyVariableString(v)

dep = dependencies.InternalDependency(version, incs, compile_args,
link_args, libs, libs_whole, sources, extra_files,
Expand Down
7 changes: 7 additions & 0 deletions test cases/unit/125 declare_dep var/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
project('foo')

declare_dependency(
variables: {
'dir': get_option('dir')
}
)
1 change: 1 addition & 0 deletions test cases/unit/125 declare_dep var/meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('dir', type: 'string')
12 changes: 12 additions & 0 deletions unittests/linuxliketests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,18 @@ def test_top_options_in_sp(self):
testdir = os.path.join(self.unit_test_dir, '124 pkgsubproj')
self.init(testdir)

def test_unreadable_dir_in_declare_dep(self):
testdir = os.path.join(self.unit_test_dir, '125 declare_dep var')
tmpdir = Path(tempfile.mkdtemp())
self.addCleanup(windows_proof_rmtree, tmpdir)
declaredepdir = tmpdir / 'test'
declaredepdir.mkdir()
try:
tmpdir.chmod(0o444)
self.init(testdir, extra_args=f'-Ddir={declaredepdir}')
finally:
tmpdir.chmod(0o755)

Comment on lines +1870 to +1876
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is essentially testing a design bug in the python standard library.

Copy link
Member

@eli-schwartz eli-schwartz Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, the purpose of my comment here is that I'm not convinced we need another unittest in order to check that this case doesn't regress.

I'm not even convinced that we're fixing a bug here at all -- just avoiding a slow op.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just an optimization... But since it was giving a PermissionError it was a buggy optimization which is why I added the test.

def check_has_flag(self, compdb, src, argument):
for i in compdb:
if src in i['file']:
Expand Down
Loading