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/15 09:56:16 UTC

[buildstream] branch tristan/validate-cross-project-include-vars updated (ec5e2d5c6 -> 0ef365aaa)

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

tvb pushed a change to branch tristan/validate-cross-project-include-vars
in repository https://gitbox.apache.org/repos/asf/buildstream.git


 discard ec5e2d5c6 tests/format/junctions.py: Test that variables in include files are resolved correctly
     new b64364771 src/buildstream/_includes.py: Resolve variables in the context of the included file
     new 0ef365aaa tests/format/junctions.py: Test that variables in include files are resolved correctly

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (ec5e2d5c6)
            \
             N -- N -- N   refs/heads/tristan/validate-cross-project-include-vars (0ef365aaa)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 src/buildstream/_includes.py | 8 ++++++++
 tests/format/junctions.py    | 4 +++-
 2 files changed, 11 insertions(+), 1 deletion(-)


[buildstream] 02/02: tests/format/junctions.py: Test that variables in include files are resolved correctly

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

tvb pushed a commit to branch tristan/validate-cross-project-include-vars
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 0ef365aaa4c070a2d2940737f5b0b1a59f697a01
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Fri Jul 15 18:35:42 2022 +0900

    tests/format/junctions.py: Test that variables in include files are resolved correctly
    
    Ensure that they are resolved in the context of the project where they are
    declared, rather than in the context of the including project.
---
 tests/format/junctions.py                                 | 15 +++++++++++++++
 tests/format/junctions/include-vars/project.conf          |  5 +++++
 tests/format/junctions/include-vars/subproject.bst        |  4 ++++
 .../format/junctions/include-vars/subproject/include.yml  |  3 +++
 .../format/junctions/include-vars/subproject/project.conf |  5 +++++
 tests/format/junctions/include-vars/target.bst            |  3 +++
 6 files changed, 35 insertions(+)

diff --git a/tests/format/junctions.py b/tests/format/junctions.py
index d17d47f5e..8c418622d 100644
--- a/tests/format/junctions.py
+++ b/tests/format/junctions.py
@@ -817,3 +817,18 @@ def test_internal(cli, tmpdir, datafiles, project_dir, expected_files):
     # Check that the checkout contains the expected file
     for expected in expected_files:
         assert os.path.exists(os.path.join(checkoutdir, expected))
+
+
+# This test verifies that variables declared in subproject include files
+# are resolved in their respective subproject, rather than being imported
+# literally and resolved in the including project.
+#
+@pytest.mark.datafiles(DATA_DIR)
+def test_include_vars(cli, datafiles):
+    project = os.path.join(str(datafiles), "include-vars")
+    result = cli.run(
+        project=project, silent=True, args=["show", "--deps", "none", "--format", "%{vars}", "target.bst"]
+    )
+    result.assert_success()
+    result_vars = _yaml.load_data(result.output)
+    assert result_vars.get_str("resolved") == "The animal is a horsy"
diff --git a/tests/format/junctions/include-vars/project.conf b/tests/format/junctions/include-vars/project.conf
new file mode 100644
index 000000000..fc19db826
--- /dev/null
+++ b/tests/format/junctions/include-vars/project.conf
@@ -0,0 +1,5 @@
+name: test
+min-version: 2.0
+
+variables:
+  animal: pony
diff --git a/tests/format/junctions/include-vars/subproject.bst b/tests/format/junctions/include-vars/subproject.bst
new file mode 100644
index 000000000..c88189cb0
--- /dev/null
+++ b/tests/format/junctions/include-vars/subproject.bst
@@ -0,0 +1,4 @@
+kind: junction
+sources:
+- kind: local
+  path: subproject
diff --git a/tests/format/junctions/include-vars/subproject/include.yml b/tests/format/junctions/include-vars/subproject/include.yml
new file mode 100644
index 000000000..e56ec5dd3
--- /dev/null
+++ b/tests/format/junctions/include-vars/subproject/include.yml
@@ -0,0 +1,3 @@
+
+variables:
+  resolved: The animal is a %{animal}
diff --git a/tests/format/junctions/include-vars/subproject/project.conf b/tests/format/junctions/include-vars/subproject/project.conf
new file mode 100644
index 000000000..6d73e9e57
--- /dev/null
+++ b/tests/format/junctions/include-vars/subproject/project.conf
@@ -0,0 +1,5 @@
+name: subtest
+min-version: 2.0
+
+variables:
+  animal: horsy
diff --git a/tests/format/junctions/include-vars/target.bst b/tests/format/junctions/include-vars/target.bst
new file mode 100644
index 000000000..7c3ca3c76
--- /dev/null
+++ b/tests/format/junctions/include-vars/target.bst
@@ -0,0 +1,3 @@
+kind: stack
+
+(@): subproject.bst:include.yml


[buildstream] 01/02: src/buildstream/_includes.py: Resolve variables in the context of the included file

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

tvb pushed a commit to branch tristan/validate-cross-project-include-vars
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit b64364771a16f617dcd4d0dd6d9a707fc67d85ab
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Fri Jul 15 18:54:29 2022 +0900

    src/buildstream/_includes.py: Resolve variables in the context of the included file
    
    Fixes #1485
---
 src/buildstream/_includes.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/buildstream/_includes.py b/src/buildstream/_includes.py
index 9542003ad..77923e71e 100644
--- a/src/buildstream/_includes.py
+++ b/src/buildstream/_includes.py
@@ -1,6 +1,7 @@
 import os
 from . import _yaml
 from .node import MappingNode, ScalarNode, SequenceNode
+from ._variables import Variables
 from ._exceptions import LoadError
 from .exceptions import LoadErrorReason
 
@@ -153,6 +154,13 @@ class Includes:
             except LoadError as e:
                 raise LoadError("{}: {}".format(include.get_provenance(), e), e.reason, detail=e.detail) from e
 
+            # Resolve the included YAML fragment's variables in the context of the
+            # project where the include file originates from.
+            #
+            variables_node = current_loader.project.base_variables.clone()
+            variables = Variables(variables_node)
+            variables.expand(self._loaded[key])
+
         return self._loaded[key], file_path, current_loader
 
     # _process_value()