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 2022/07/25 09:00:33 UTC

[buildstream] branch tristan/fix-load-cross-project-element created (now 3412f3720)

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

tvb pushed a change to branch tristan/fix-load-cross-project-element
in repository https://gitbox.apache.org/repos/asf/buildstream.git


      at 3412f3720 tests/format/junctions.py: Test complex cross junction include scenario

This branch includes the following new commits:

     new 56c7723c2 _project.py: Allow usage of first stage load options and variables
     new 3412f3720 tests/format/junctions.py: Test complex cross junction include scenario

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[buildstream] 02/02: tests/format/junctions.py: Test complex cross junction include scenario

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/fix-load-cross-project-element
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 3412f3720d1f6e3cd02f225c2c76f86f94287328
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Mon Jul 25 16:15:06 2022 +0900

    tests/format/junctions.py: Test complex cross junction include scenario
    
    In this scenario, loading a file directly across a junction, without using
    a depending toplevel project element, produces stack traces.
---
 tests/format/junctions.py                          | 40 ++++++++++++++++++++++
 .../format/junctions/include-complex/project.conf  | 15 ++++++++
 .../junctions/include-complex/subproject.bst       |  8 +++++
 .../include-complex/subproject/project.conf        | 11 ++++++
 .../include-complex/subproject/target.bst          |  4 +++
 5 files changed, 78 insertions(+)

diff --git a/tests/format/junctions.py b/tests/format/junctions.py
index c9615397c..6f0a5d1de 100644
--- a/tests/format/junctions.py
+++ b/tests/format/junctions.py
@@ -880,3 +880,43 @@ def test_include_vars_optional(cli, datafiles, use_species, expected_result):
     result.assert_success()
     result_vars = _yaml.load_data(result.output)
     assert result_vars.get_str("resolved") == expected_result
+
+
+# This test verifies that project option conditional statements made
+# in an include file are resolved in the context of the project where
+# the include file originates.
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize(
+    "target",
+    ["target.bst", "subproject.bst:target.bst"],
+    ids=["toplevel-target", "subproject-target"],
+)
+@pytest.mark.parametrize(
+    "animal,expected_result",
+    [
+        ("pony", "target pony"),
+        ("horsy", "target horsy"),
+    ],
+    ids=["branch1", "branch2"],
+)
+def test_include_vars_cross_junction_element(cli, datafiles, target, animal, expected_result):
+    project = os.path.join(str(datafiles), "include-complex")
+    result = cli.run(
+        project=project,
+        silent=True,
+        args=[
+            "--option",
+            "animal",
+            animal,
+            "show",
+            "--deps",
+            "none",
+            "--format",
+            "%{vars}",
+            target,
+        ],
+    )
+    result.assert_success()
+    result_vars = _yaml.load_data(result.output)
+    assert result_vars.get_str("target_animal_variable") == expected_result
diff --git a/tests/format/junctions/include-complex/project.conf b/tests/format/junctions/include-complex/project.conf
new file mode 100644
index 000000000..eb7f3c746
--- /dev/null
+++ b/tests/format/junctions/include-complex/project.conf
@@ -0,0 +1,15 @@
+name: test
+min-version: 2.0
+
+(@):
+- subproject.bst:include.yml
+
+options:
+  animal:
+    type: enum
+    description: the animal
+    values:
+    - pony
+    - horsy
+    default: pony
+    variable: animal
diff --git a/tests/format/junctions/include-complex/subproject.bst b/tests/format/junctions/include-complex/subproject.bst
new file mode 100644
index 000000000..daaea3091
--- /dev/null
+++ b/tests/format/junctions/include-complex/subproject.bst
@@ -0,0 +1,8 @@
+kind: junction
+sources:
+- kind: local
+  path: subproject
+
+config:
+  options:
+    target_animal: '%{animal}'
diff --git a/tests/format/junctions/include-complex/subproject/project.conf b/tests/format/junctions/include-complex/subproject/project.conf
new file mode 100644
index 000000000..ad8a3b3de
--- /dev/null
+++ b/tests/format/junctions/include-complex/subproject/project.conf
@@ -0,0 +1,11 @@
+name: subtest
+min-version: 2.0
+
+options:
+  target_animal:
+    type: enum
+    description: the target animal
+    values:
+    - pony
+    - horsy
+    default: pony
diff --git a/tests/format/junctions/include-complex/subproject/target.bst b/tests/format/junctions/include-complex/subproject/target.bst
new file mode 100644
index 000000000..9349a1854
--- /dev/null
+++ b/tests/format/junctions/include-complex/subproject/target.bst
@@ -0,0 +1,4 @@
+kind: stack
+
+(@):
+- include.yml


[buildstream] 01/02: _project.py: Allow usage of first stage load options and variables

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/fix-load-cross-project-element
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 56c7723c22c44cc76af27fc9490280baeef83137
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Mon Jul 25 16:13:29 2022 +0900

    _project.py: Allow usage of first stage load options and variables
    
    For options, it is clear that the first stage load is sufficient in every
    case, it is illegal for options to be resolved differently in the second
    pass.
    
    For variables, we allow usage of the first stage, while the second stage
    might be more complete, in some scenarios we need to access the variables
    from the first stage.
---
 src/buildstream/_project.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index 1ac8fe8b1..683907bd8 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -181,11 +181,20 @@ class Project:
 
     @property
     def options(self):
-        return self.config.options
+        #
+        # We sometimes need the resolved options from the first pass,
+        # but the options from the second pass can never differ from
+        # the options in the first pass.
+        #
+        return self.first_pass_config.options
 
     @property
     def base_variables(self):
-        return self.config.base_variables
+        if isinstance(self.config.base_variables, MappingNode):
+            return self.config.base_variables
+
+        assert isinstance(self.first_pass_config.base_variables, MappingNode)
+        return self.first_pass_config.base_variables
 
     @property
     def element_overrides(self):