diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index dbc655f6d..c27a4e76e 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -4601,7 +4601,7 @@ different subdirectory. ''') else: try: - self.validate_within_subproject(a, '') + self.validate_within_subproject(self.subdir, a) except InterpreterException: mlog.warning('include_directories sandbox violation!') print(f'''The project is trying to access the directory {a} which belongs to a different @@ -4830,6 +4830,8 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey # /opt/vendorsdk/src/file_with_license_restrictions.c return project_root = Path(srcdir, self.root_subdir) + if norm == project_root: + return if project_root not in norm.parents: raise InterpreterException(f'Sandbox violation: Tried to grab {inputtype} {norm.name} outside current (sub)project.') if project_root / self.subproject_dir in norm.parents: diff --git a/test cases/common/240 includedir violation/meson.build b/test cases/common/240 includedir violation/meson.build index a82069ef6..0216be6ef 100644 --- a/test cases/common/240 includedir violation/meson.build +++ b/test cases/common/240 includedir violation/meson.build @@ -1,5 +1,9 @@ project('foo', 'c') +# It is fine to include the root source dir +include_directories('.') +subproject('sub') + # This is here rather than in failing because this needs a # transition period to avoid breaking existing projects. # Once this becomes an error, move this under failing tests. diff --git a/test cases/common/240 includedir violation/subprojects/sub/meson.build b/test cases/common/240 includedir violation/subprojects/sub/meson.build index 721101834..352f4a261 100644 --- a/test cases/common/240 includedir violation/subprojects/sub/meson.build +++ b/test cases/common/240 includedir violation/subprojects/sub/meson.build @@ -1,3 +1,3 @@ project('subproj', 'c') -# This is never actually executed, just here for completeness. +include_directories('.') diff --git a/test cases/common/240 includedir violation/test.json b/test cases/common/240 includedir violation/test.json index d6e56a315..fea19a109 100644 --- a/test cases/common/240 includedir violation/test.json +++ b/test cases/common/240 includedir violation/test.json @@ -1,7 +1,9 @@ { "stdout": [ { - "line": "WARNING: include_directories sandbox violation!" + "line": ".*WARNING: include_directories sandbox violation!", + "match": "re", + "count": 1 } ] }