Skip to content

Commit e6eb60b

Browse files
committed
interpreter: reorder tests for DependencyVariableString creation
Do the is_dir() test last, once it's known that the directory is related to the source directory. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 22d970d commit e6eb60b

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

mesonbuild/interpreter/interpreter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,14 @@ def func_declare_dependency(self, node: mparser.BaseNode, args: T.List[TYPE_var]
722722
except ValueError:
723723
continue
724724
else:
725-
if not self.is_subproject() and srcdir / self.subproject_dir in p.parents:
726-
continue
727-
if p.is_absolute() and p.is_dir() and srcdir / self.root_subdir in [p] + list(Path(os.path.abspath(p)).parents):
725+
# Note that p.is_dir() can raise a PermissionError if a parent does not have
726+
# the executable permission set. Test it last, and only after checking that
727+
# v is within the project's source directory, to avoid false positives for
728+
# e.g. root owned directories under /var.
729+
if p.is_absolute() \
730+
and (self.is_subproject() or srcdir / self.subproject_dir not in p.parents) \
731+
and srcdir / self.root_subdir in [p] + list(Path(os.path.abspath(p)).parents) \
732+
and p.is_dir():
728733
variables[k] = P_OBJ.DependencyVariableString(v)
729734

730735
dep = dependencies.InternalDependency(version, incs, compile_args,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
project('foo')
2+
3+
declare_dependency(
4+
variables: {
5+
'dir': get_option('dir')
6+
}
7+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
option('dir', type: 'string')

unittests/linuxliketests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,18 @@ def test_top_options_in_sp(self):
18681868
testdir = os.path.join(self.unit_test_dir, '124 pkgsubproj')
18691869
self.init(testdir)
18701870

1871+
def test_unreadable_dir_in_declare_dep(self):
1872+
testdir = os.path.join(self.unit_test_dir, '125 declare_dep var')
1873+
tmpdir = Path(tempfile.mkdtemp())
1874+
self.addCleanup(windows_proof_rmtree, tmpdir)
1875+
declaredepdir = tmpdir / 'test'
1876+
declaredepdir.mkdir()
1877+
try:
1878+
tmpdir.chmod(0o444)
1879+
self.init(testdir, extra_args=f'-Ddir={declaredepdir}')
1880+
finally:
1881+
tmpdir.chmod(0o755)
1882+
18711883
def check_has_flag(self, compdb, src, argument):
18721884
for i in compdb:
18731885
if src in i['file']:

0 commit comments

Comments
 (0)