From b49b9f52b29896cce58a1e3dbeb1b6cf54420d45 Mon Sep 17 00:00:00 2001 From: Hemmo Nieminen Date: Fri, 17 Jun 2022 00:00:00 +0300 Subject: [PATCH] interpreter: fix a subproject check with symlinks The check for whether or not a file is allowed to be accessed from a subproject fails if the subproject is accessed via a symlink. Use the absolute path of the subproject without resolving symlinks to fix the check. Extend unit test 106 to check for this in the future. --- mesonbuild/interpreter/interpreter.py | 2 +- test cases/unit/106 subproject symlink/cp.py | 6 ++++++ test cases/unit/106 subproject symlink/meson.build | 11 +++++++++-- .../symlinked_subproject/datadir/datafile | 1 + .../symlinked_subproject/datadir/meson.build | 1 + .../symlinked_subproject/meson.build | 9 ++++++++- 6 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 test cases/unit/106 subproject symlink/cp.py create mode 100644 test cases/unit/106 subproject symlink/symlinked_subproject/datadir/datafile create mode 100644 test cases/unit/106 subproject symlink/symlinked_subproject/datadir/meson.build diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 3bf9b42e5..5cadf5258 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -684,7 +684,7 @@ class Interpreter(InterpreterBase, HoldableObject): 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(p.resolve().parents): + 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) for d in deps: if not isinstance(d, dependencies.Dependency): diff --git a/test cases/unit/106 subproject symlink/cp.py b/test cases/unit/106 subproject symlink/cp.py new file mode 100644 index 000000000..adb0547b8 --- /dev/null +++ b/test cases/unit/106 subproject symlink/cp.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +from sys import argv +from shutil import copy + +copy(argv[1], argv[2]) diff --git a/test cases/unit/106 subproject symlink/meson.build b/test cases/unit/106 subproject symlink/meson.build index 51c78c7ec..6766c8e4a 100644 --- a/test cases/unit/106 subproject symlink/meson.build +++ b/test cases/unit/106 subproject symlink/meson.build @@ -1,8 +1,15 @@ project('foo', 'c') -symlinked_subproject = subproject('symlinked_subproject') +symlinked_subproject = subproject('symlinked_subproject').get_variable('dep') executable('foo', sources : 'main.c', - dependencies : symlinked_subproject.get_variable('dep') + dependencies : symlinked_subproject +) + +custom_target( + input : symlinked_subproject.get_variable('datadir') / 'datafile', + output : 'datafile_copy', + command : [find_program('cp.py'), '@INPUT@', '@OUTPUT@'], + build_always : true ) diff --git a/test cases/unit/106 subproject symlink/symlinked_subproject/datadir/datafile b/test cases/unit/106 subproject symlink/symlinked_subproject/datadir/datafile new file mode 100644 index 000000000..6a682940b --- /dev/null +++ b/test cases/unit/106 subproject symlink/symlinked_subproject/datadir/datafile @@ -0,0 +1 @@ +hello meson diff --git a/test cases/unit/106 subproject symlink/symlinked_subproject/datadir/meson.build b/test cases/unit/106 subproject symlink/symlinked_subproject/datadir/meson.build new file mode 100644 index 000000000..cbeb0a969 --- /dev/null +++ b/test cases/unit/106 subproject symlink/symlinked_subproject/datadir/meson.build @@ -0,0 +1 @@ +install_data('datafile') diff --git a/test cases/unit/106 subproject symlink/symlinked_subproject/meson.build b/test cases/unit/106 subproject symlink/symlinked_subproject/meson.build index 61440c7eb..39304655f 100644 --- a/test cases/unit/106 subproject symlink/symlinked_subproject/meson.build +++ b/test cases/unit/106 subproject symlink/symlinked_subproject/meson.build @@ -1,3 +1,10 @@ project('symlinked_subproject', 'c', version : '1.0.0') -dep = declare_dependency(sources : 'src.c') +dep = declare_dependency( + sources : 'src.c', + variables : { + 'datadir': meson.current_source_dir() / 'datadir' + } +) + +subdir('datadir')