You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 08:09:58 UTC

[buildstream] 23/30: Make include path relative to project the including fragment is found.

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch valentindavid/flatpak-demo
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit de2e7fea7d15e06cff49cf07c11f97fcf1718613
Author: Valentin David <va...@codethink.co.uk>
AuthorDate: Fri Jun 29 17:16:01 2018 +0200

    Make include path relative to project the including fragment is found.
---
 buildstream/_includes.py                           | 43 +++++++++++++---------
 tests/format/include.py                            | 19 ++++++++++
 tests/format/include/local_to_junction/element.bst |  1 +
 .../format/include/local_to_junction/project.conf  |  4 ++
 .../local_to_junction/subproject/extra_conf.yml    |  2 +
 .../local_to_junction/subproject/internal.yml      |  2 +
 .../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 fd99a6c..0f68fc9 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 4b26c97..ba8d4a0 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 0000000..4d7f702
--- /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 0000000..4836c5f
--- /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 0000000..1c0b8cc
--- /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 0000000..404ecd6
--- /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 0000000..7a66554
--- /dev/null
+++ b/tests/format/include/local_to_junction/subproject/project.conf
@@ -0,0 +1 @@
+name: test-sub