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:10:02 UTC

[buildstream] 27/30: Always process local includes.

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 52b6b40838ba590de53d181b449fd337730baae0
Author: Valentin David <va...@codethink.co.uk>
AuthorDate: Mon Jul 2 11:55:55 2018 +0200

    Always process local includes.
---
 buildstream/_includes.py                           | 35 +++++++++++-----------
 buildstream/_project.py                            |  3 +-
 tests/format/include.py                            |  6 ++--
 .../format/include/overrides-junction/element.bst  |  1 +
 .../format/include/overrides-junction/project.conf | 20 +++++++++++++
 .../overrides-junction/subproject/extra_conf.yml   | 16 ++++++++++
 .../overrides-junction/subproject/project.conf     |  1 +
 7 files changed, 59 insertions(+), 23 deletions(-)

diff --git a/buildstream/_includes.py b/buildstream/_includes.py
index a357723..3640f7a 100644
--- a/buildstream/_includes.py
+++ b/buildstream/_includes.py
@@ -10,19 +10,10 @@ class Includes:
         self._loader = loader
         self._loaded = {}
 
-    def ignore_includes(self, node):
-        if isinstance(node, Mapping):
-            if '(@)' in node:
-                del node['(@)']
-            for _, value in _yaml.node_items(node):
-                self.ignore_includes(value)
-        elif isinstance(node, list):
-            for value in node:
-                self.ignore_includes(value)
-
     def process(self, node, *,
                 included=set(),
-                current_loader=None):
+                current_loader=None,
+                only_local=False):
         if current_loader is None:
             current_loader = self._loader
 
@@ -32,6 +23,8 @@ class Includes:
 
         if includes:
             for include in includes:
+                if only_local and ':' in include:
+                    continue
                 include_node, file_path, sub_loader = self._include_file(include,
                                                                          current_loader)
                 if file_path in included:
@@ -42,13 +35,15 @@ class Includes:
                 try:
                     included.add(file_path)
                     self.process(include_node, included=included,
-                                 current_loader=sub_loader)
+                                 current_loader=sub_loader,
+                                 only_local=only_local)
                 finally:
                     included.remove(file_path)
                 _yaml.composite(node, include_node)
 
         for _, value in _yaml.node_items(node):
-            self._process_value(value, current_loader=current_loader)
+            self._process_value(value, current_loader=current_loader,
+                                only_local=only_local)
 
     def _include_file(self, include, loader):
         shortname = include
@@ -68,12 +63,16 @@ class Includes:
                                            project=project)
         return self._loaded[key], file_path, current_loader
 
-    def _process_value(self, value, *, current_loader=None):
+    def _process_value(self, value, *,
+                       current_loader=None,
+                       only_local=False):
         if isinstance(value, Mapping):
-            self.process(value, current_loader=current_loader)
+            self.process(value, current_loader=current_loader, only_local=only_local)
         elif isinstance(value, list):
-            self._process_list(value, current_loader=current_loader)
+            self._process_list(value, current_loader=current_loader, only_local=only_local)
 
-    def _process_list(self, values, *, current_loader=None):
+    def _process_list(self, values, *,
+                      current_loader=None,
+                      only_local=False):
         for value in values:
-            self._process_value(value, current_loader=current_loader)
+            self._process_value(value, current_loader=current_loader, only_local=only_local)
diff --git a/buildstream/_project.py b/buildstream/_project.py
index 5156539..5e89f88 100644
--- a/buildstream/_project.py
+++ b/buildstream/_project.py
@@ -301,7 +301,6 @@ class Project():
     def source_overrides(self):
         return self.config.source_overrides
 
-
     # translate_url():
     #
     # Translates the given url which may be specified with an alias
@@ -459,7 +458,7 @@ class Project():
         self._project_includes = Includes(self.loader)
 
         config_no_include = _yaml.node_copy(self._config_node)
-        self._project_includes.ignore_includes(config_no_include)
+        self._project_includes.process(config_no_include, only_local=True)
 
         self._load_pass(config_no_include, self.first_pass_config, True)
 
diff --git a/tests/format/include.py b/tests/format/include.py
index ba8d4a0..938b987 100644
--- a/tests/format/include.py
+++ b/tests/format/include.py
@@ -93,7 +93,7 @@ def test_junction_element_partial_project_project(cli, tmpdir, datafiles):
 
 
 @pytest.mark.datafiles(DATA_DIR)
-def test_junction_element_partial_project_file(cli, tmpdir, datafiles):
+def test_junction_element_not_partial_project_file(cli, tmpdir, datafiles):
     """
     Junction elements never depend on fully include processed project.
     """
@@ -122,7 +122,7 @@ def test_junction_element_partial_project_file(cli, tmpdir, datafiles):
         'junction.bst'])
     result.assert_success()
     loaded = _yaml.load_data(result.output)
-    assert 'included' not in loaded
+    assert 'included' in loaded
 
 
 @pytest.mark.datafiles(DATA_DIR)
@@ -171,7 +171,7 @@ def test_include_element_overrides_sub_include(cli, tmpdir, datafiles):
 
 @pytest.mark.datafiles(DATA_DIR)
 def test_junction_do_not_use_included_overrides(cli, tmpdir, datafiles):
-    project = os.path.join(str(datafiles), 'overrides')
+    project = os.path.join(str(datafiles), 'overrides-junction')
 
     generate_junction(tmpdir,
                       os.path.join(project, 'subproject'),
diff --git a/tests/format/include/overrides-junction/element.bst b/tests/format/include/overrides-junction/element.bst
new file mode 100644
index 0000000..4d7f702
--- /dev/null
+++ b/tests/format/include/overrides-junction/element.bst
@@ -0,0 +1 @@
+kind: manual
diff --git a/tests/format/include/overrides-junction/project.conf b/tests/format/include/overrides-junction/project.conf
new file mode 100644
index 0000000..d03bec6
--- /dev/null
+++ b/tests/format/include/overrides-junction/project.conf
@@ -0,0 +1,20 @@
+name: test
+
+elements:
+  junction:
+    variables:
+      main_override: True
+  manual:
+    variables:
+      manual_main_override: True
+    config:
+      build-commands:
+        - "first"
+
+sources:
+  git:
+    variables:
+      from_main: True
+
+(@):
+  - junction.bst:extra_conf.yml
diff --git a/tests/format/include/overrides-junction/subproject/extra_conf.yml b/tests/format/include/overrides-junction/subproject/extra_conf.yml
new file mode 100644
index 0000000..3cd3530
--- /dev/null
+++ b/tests/format/include/overrides-junction/subproject/extra_conf.yml
@@ -0,0 +1,16 @@
+elements:
+  junction:
+    variables:
+      included_override: True
+  manual:
+    variables:
+      manual_included_override: True
+    config:
+      build-commands:
+        (>):
+          - "second"
+
+sources:
+  git:
+    variables:
+      from_included: True
diff --git a/tests/format/include/overrides-junction/subproject/project.conf b/tests/format/include/overrides-junction/subproject/project.conf
new file mode 100644
index 0000000..7a66554
--- /dev/null
+++ b/tests/format/include/overrides-junction/subproject/project.conf
@@ -0,0 +1 @@
+name: test-sub