diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2020-10-31 14:17:24 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2021-01-12 15:51:28 +0000 |
commit | c659be692896f9f36fa46c4955220dc57653f09b (patch) | |
tree | e80d0a29af48ec1046c2e8c499739876c67546c4 /mesonbuild/interpreter.py | |
parent | 4ff020759a3cdedb9d8ff1150ec09313096f6228 (diff) | |
download | meson-c659be692896f9f36fa46c4955220dc57653f09b.zip meson-c659be692896f9f36fa46c4955220dc57653f09b.tar.gz meson-c659be692896f9f36fa46c4955220dc57653f09b.tar.bz2 |
Interpreter: Fix nested subsubproject detection
A sub-subproject can be configured directly from
`subprojects/foo/subprojects/bar/` in the case `bar` is in the same git
repository as `foo` and not downloaded separately into the main
project's `subprojects/`. In that case the nested subproject violation
code was wrong because it is allowed to have more than one "subprojects"
in path (was not possible before Meson 0.56.0).
Example:
- self.environment.source_dir = '/home/user/myproject'
- self.root_subdir = 'subprojects/foo/subprojects/bar'
- project_root = '/home/user/myproject/subprojects/foo/subprojects/bar'
- norm = '/home/user/myproject/subprojects/foo/subprojects/bar/file.c'
We want `norm` path to have `project_root` in its parents and not have
`project_root / 'subprojects'` in its parents. In that case we are sure
`file.c` is within `bar` subproject.
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r-- | mesonbuild/interpreter.py | 48 |
1 files changed, 13 insertions, 35 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 6e04235..9466fe4 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -4786,21 +4786,6 @@ This will probably not work. Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey('b_sanitize')].value), location=self.current_node) - def evaluate_subproject_info(self, path_from_source_root, subproject_dir): - depth = 0 - subproj_name = '' - segs = PurePath(path_from_source_root).parts - segs_spd = PurePath(subproject_dir).parts - while segs and segs[0] == segs_spd[0]: - if len(segs_spd) == 1: - subproj_name = segs[1] - segs = segs[2:] - depth += 1 - else: - segs_spd = segs_spd[1:] - segs = segs[1:] - return (depth, subproj_name) - # Check that the indicated file is within the same subproject # as we currently are. This is to stop people doing # nasty things like: @@ -4812,26 +4797,19 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey # subproject than it is defined in (due to e.g. a # declare_dependency). def validate_within_subproject(self, subdir, fname): - norm = os.path.normpath(os.path.join(subdir, fname)) - if os.path.isabs(norm): - if not norm.startswith(self.environment.source_dir): - # Grabbing files outside the source tree is ok. - # This is for vendor stuff like: - # - # /opt/vendorsdk/src/file_with_license_restrictions.c - return - norm = os.path.relpath(norm, self.environment.source_dir) - assert(not os.path.isabs(norm)) - (num_sps, sproj_name) = self.evaluate_subproject_info(norm, self.subproject_dir) - plain_filename = os.path.basename(norm) - if num_sps == 0: - if not self.is_subproject(): - return - raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % plain_filename) - if num_sps > 1: - raise InterpreterException('Sandbox violation: Tried to grab file %s from a nested subproject.' % plain_filename) - if sproj_name != self.subproject_directory_name: - raise InterpreterException('Sandbox violation: Tried to grab file %s from a different subproject.' % plain_filename) + srcdir = Path(self.environment.source_dir) + norm = Path(srcdir, subdir, fname).resolve() + if srcdir not in norm.parents: + # Grabbing files outside the source tree is ok. + # This is for vendor stuff like: + # + # /opt/vendorsdk/src/file_with_license_restrictions.c + return + project_root = Path(srcdir, self.root_subdir) + if project_root not in norm.parents: + raise InterpreterException('Sandbox violation: Tried to grab file {} outside current (sub)project.'.format(norm.name)) + if project_root / self.subproject_dir in norm.parents: + raise InterpreterException('Sandbox violation: Tried to grab file {} from a nested subproject.'.format(norm.name)) def source_strings_to_files(self, sources: T.List[str]) -> T.List[mesonlib.File]: mesonlib.check_direntry_issues(sources) |