diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 7fb3c923407b..84290598ee06 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -25,7 +25,7 @@ from .. import mesonlib from ..mesonlib import (EnvironmentVariables, ExecutableSerialisation, MesonBugException, MesonException, HoldableObject, FileMode, MachineChoice, OptionKey, listify, - extract_as_list, has_path_sep, path_is_in_root, PerMachine) + extract_as_list, has_path_sep, PerMachine) from ..programs import ExternalProgram, NonExistingExternalProgram from ..dependencies import Dependency from ..depfile import DepFile @@ -2774,57 +2774,32 @@ def build_incdir_object(self, incdir_strings: T.List[str], is_system: bool = Fal absbase_build = os.path.join(build_root, self.subdir) for a in incdir_strings: - if path_is_in_root(Path(a), Path(src_root)): - raise InvalidArguments(textwrap.dedent('''\ - Tried to form an absolute path to a dir in the source tree. - You should not do that but use relative paths instead, for - directories that are part of your project. - - To get include path to any directory relative to the current dir do - - incdir = include_directories(dirname) - - After this incdir will contain both the current source dir as well as the - corresponding build dir. It can then be used in any subdirectory and - Meson will take care of all the busywork to make paths work. - - Dirname can even be '.' to mark the current directory. Though you should - remember that the current source and build directories are always - put in the include directories by default so you only need to do - include_directories('.') if you intend to use the result in a - different subdirectory. - - Note that this error message can also be triggered by - external dependencies being installed within your source - tree - it's not recommended to do this. + try: + self.validate_within_subproject(self.subdir, a) + except InterpreterException: + mlog.warning('include_directories sandbox violation!', location=self.current_node) + print(textwrap.dedent(f'''\ + The project is trying to access the directory {a!r} which belongs to a different + subproject. This is a problem as it hardcodes the relative paths of these two projects. + This makes it impossible to compile the project in any other directory layout and also + prevents the subproject from changing its own directory layout. + + Instead of poking directly at the internals the subproject should be executed and + it should set a variable that the caller can then use. Something like: + + # In subproject + some_dep = declare_dependency(include_directories: include_directories('include')) + + # In subproject wrap file + [provide] + some = some_dep + + # In parent project + some_dep = dependency('some') + executable(..., dependencies: [some_dep]) + + This warning will become a hard error in a future Meson release. ''')) - else: - try: - self.validate_within_subproject(self.subdir, a) - except InterpreterException: - mlog.warning('include_directories sandbox violation!', location=self.current_node) - print(textwrap.dedent(f'''\ - The project is trying to access the directory {a!r} which belongs to a different - subproject. This is a problem as it hardcodes the relative paths of these two projects. - This makes it impossible to compile the project in any other directory layout and also - prevents the subproject from changing its own directory layout. - - Instead of poking directly at the internals the subproject should be executed and - it should set a variable that the caller can then use. Something like: - - # In subproject - some_dep = declare_dependency(include_directories: include_directories('include')) - - # In subproject wrap file - [provide] - some = some_dep - - # In parent project - some_dep = dependency('some') - executable(..., dependencies: [some_dep]) - - This warning will become a hard error in a future Meson release. - ''')) absdir_src = os.path.join(absbase_src, a) absdir_build = os.path.join(absbase_build, a) if not os.path.isdir(absdir_src) and not os.path.isdir(absdir_build): diff --git a/run_project_tests.py b/run_project_tests.py index 7ff164086678..1cfadcd309ac 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -947,8 +947,6 @@ def gather_tests(testdir: Path, stdout_mandatory: bool, only: T.List[str], skip_ # Filter non-tests files (dot files, etc) if not t.is_dir() or t.name.startswith('.'): continue - if t.name in {'18 includedirxyz'}: - continue if only and not any(t.name.startswith(prefix) for prefix in only): continue test_def = TestDef(t, None, [], skip_category=skip_category) diff --git a/test cases/common/18 includedir/meson.build b/test cases/common/18 includedir/meson.build index 3180587270c6..91a18a9b66d1 100644 --- a/test cases/common/18 includedir/meson.build +++ b/test cases/common/18 includedir/meson.build @@ -1,32 +1,4 @@ project('include dir test', 'c') inc = include_directories('include') -subdir('src') - -errormsg = '''Tried to form an absolute path to a dir in the source tree. -You should not do that but use relative paths instead, for -directories that are part of your project. - -To get include path to any directory relative to the current dir do - -incdir = include_directories(dirname) - -After this incdir will contain both the current source dir as well as the -corresponding build dir. It can then be used in any subdirectory and -Meson will take care of all the busywork to make paths work. - -Dirname can even be '.' to mark the current directory. Though you should -remember that the current source and build directories are always -put in the include directories by default so you only need to do -include_directories('.') if you intend to use the result in a -different subdirectory. - -Note that this error message can also be triggered by -external dependencies being installed within your source -tree - it's not recommended to do this. -''' -testcase expect_error(errormsg) - include_directories(meson.current_source_dir() / 'include') -endtestcase -# Test for issue #12217 -include_directories(meson.current_source_dir() + 'xyz') +subdir('src') \ No newline at end of file diff --git a/test cases/common/18 includedirxyz/do_not_delete b/test cases/common/18 includedirxyz/do_not_delete deleted file mode 100644 index 8bd0f8805a9d..000000000000 --- a/test cases/common/18 includedirxyz/do_not_delete +++ /dev/null @@ -1 +0,0 @@ -This file is to ensure this directory exists diff --git a/test cases/failing/44 abspath to srcdir/meson.build b/test cases/failing/44 abspath to srcdir/meson.build deleted file mode 100644 index 78c61242032f..000000000000 --- a/test cases/failing/44 abspath to srcdir/meson.build +++ /dev/null @@ -1,3 +0,0 @@ -project('meson') - -include_directories(meson.current_source_dir()) diff --git a/test cases/failing/44 abspath to srcdir/test.json b/test cases/failing/44 abspath to srcdir/test.json deleted file mode 100644 index c64ecfbd648c..000000000000 --- a/test cases/failing/44 abspath to srcdir/test.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "stdout": [ - { - "line": "test cases/failing/44 abspath to srcdir/meson.build:3:0: ERROR: Tried to form an absolute path to a dir in the source tree." - } - ] -}