diff options
author | Valentin David <valentin.david@codethink.co.uk> | 2018-06-29 17:16:01 +0200 |
---|---|---|
committer | Valentin David <valentin.david@codethink.co.uk> | 2018-07-02 16:25:58 +0200 |
commit | de2e7fea7d15e06cff49cf07c11f97fcf1718613 (patch) | |
tree | 8841663bdb25965b05e133c9392866290c173f74 | |
parent | 5b644425e710793eae8cb951fae872c4613acf77 (diff) | |
download | buildstream-de2e7fea7d15e06cff49cf07c11f97fcf1718613.tar.gz |
Make include path relative to project the including fragment is found.
-rw-r--r-- | buildstream/_includes.py | 43 | ||||
-rw-r--r-- | tests/format/include.py | 19 | ||||
-rw-r--r-- | tests/format/include/local_to_junction/element.bst | 1 | ||||
-rw-r--r-- | tests/format/include/local_to_junction/project.conf | 4 | ||||
-rw-r--r-- | tests/format/include/local_to_junction/subproject/extra_conf.yml | 2 | ||||
-rw-r--r-- | tests/format/include/local_to_junction/subproject/internal.yml | 2 | ||||
-rw-r--r-- | tests/format/include/local_to_junction/subproject/project.conf | 1 |
7 files changed, 55 insertions, 17 deletions
diff --git a/buildstream/_includes.py b/buildstream/_includes.py index fd99a6c44..0f68fc971 100644 --- a/buildstream/_includes.py +++ b/buildstream/_includes.py @@ -20,14 +20,20 @@ class Includes: for value in node: self.ignore_includes(value) - def process(self, node, *, included=set()): + def process(self, node, *, + included=set(), + current_loader=None): + if current_loader is None: + current_loader = self._loader + includes = _yaml.node_get(node, list, '(@)', default_value=None) if '(@)' in node: del node['(@)'] if includes: for include in includes: - include_node, file_path = self._include_file(include) + include_node, file_path, sub_loader = self._include_file(include, + current_loader) if file_path in included: provenance = _yaml.node_get_provenance(node) raise LoadError(LoadErrorReason.RECURSIVE_INCLUDE, @@ -35,36 +41,39 @@ class Includes: file_path)) try: included.add(file_path) - self.process(include_node, included=included) + self.process(include_node, included=included, + current_loader=sub_loader) finally: included.remove(file_path) _yaml.composite(node, include_node) for _, value in _yaml.node_items(node): - self._process_value(value) + self._process_value(value, current_loader=current_loader) - def _include_file(self, include): + def _include_file(self, include, loader): shortname = include if ':' in include: junction, include = include.split(':', 1) - junction_loader = self._loader._get_loader(junction, fetch_subprojects=True) - project = junction_loader.project + junction_loader = loader._get_loader(junction, fetch_subprojects=True) + current_loader = junction_loader else: - project = self._loader.project + current_loader = loader + project = current_loader.project directory = project.directory file_path = os.path.join(directory, include) + key = (current_loader, file_path) if file_path not in self._loaded: - self._loaded[file_path] = _yaml.load(os.path.join(directory, include), - shortname=shortname, - project=project) - return self._loaded[file_path], file_path + self._loaded[key] = _yaml.load(os.path.join(directory, include), + shortname=shortname, + project=project) + return self._loaded[key], file_path, current_loader - def _process_value(self, value): + def _process_value(self, value, *, current_loader=None): if isinstance(value, Mapping): - self.process(value) + self.process(value, current_loader=current_loader) elif isinstance(value, list): - self._process_list(value) + self._process_list(value, current_loader=current_loader) - def _process_list(self, values): + def _process_list(self, values, *, current_loader=None): for value in values: - self._process_value(value) + self._process_value(value, current_loader=current_loader) diff --git a/tests/format/include.py b/tests/format/include.py index 4b26c9780..ba8d4a08d 100644 --- a/tests/format/include.py +++ b/tests/format/include.py @@ -229,3 +229,22 @@ def test_inner(cli, datafiles): result.assert_success() loaded = _yaml.load_data(result.output) assert loaded['build_arch'] == 'x86_64' + + +@pytest.mark.datafiles(DATA_DIR) +def test_local_to_junction(cli, tmpdir, datafiles): + project = os.path.join(str(datafiles), 'local_to_junction') + + generate_junction(tmpdir, + os.path.join(project, 'subproject'), + os.path.join(project, 'junction.bst'), + store_ref=True) + + result = cli.run(project=project, args=[ + 'show', + '--deps', 'none', + '--format', '%{vars}', + 'element.bst']) + result.assert_success() + loaded = _yaml.load_data(result.output) + assert loaded['included'] == 'True' diff --git a/tests/format/include/local_to_junction/element.bst b/tests/format/include/local_to_junction/element.bst new file mode 100644 index 000000000..4d7f70266 --- /dev/null +++ b/tests/format/include/local_to_junction/element.bst @@ -0,0 +1 @@ +kind: manual diff --git a/tests/format/include/local_to_junction/project.conf b/tests/format/include/local_to_junction/project.conf new file mode 100644 index 000000000..4836c5f8b --- /dev/null +++ b/tests/format/include/local_to_junction/project.conf @@ -0,0 +1,4 @@ +name: test + +(@): + - junction.bst:extra_conf.yml diff --git a/tests/format/include/local_to_junction/subproject/extra_conf.yml b/tests/format/include/local_to_junction/subproject/extra_conf.yml new file mode 100644 index 000000000..1c0b8ccdd --- /dev/null +++ b/tests/format/include/local_to_junction/subproject/extra_conf.yml @@ -0,0 +1,2 @@ +(@): + - internal.yml diff --git a/tests/format/include/local_to_junction/subproject/internal.yml b/tests/format/include/local_to_junction/subproject/internal.yml new file mode 100644 index 000000000..404ecd6dd --- /dev/null +++ b/tests/format/include/local_to_junction/subproject/internal.yml @@ -0,0 +1,2 @@ +variables: + included: 'True' diff --git a/tests/format/include/local_to_junction/subproject/project.conf b/tests/format/include/local_to_junction/subproject/project.conf new file mode 100644 index 000000000..7a6655421 --- /dev/null +++ b/tests/format/include/local_to_junction/subproject/project.conf @@ -0,0 +1 @@ +name: test-sub |