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/22 05:28:21 UTC

[buildstream] branch tristan/resolve-conditionals-project-root created (now 574db6dd0)

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

tvb pushed a change to branch tristan/resolve-conditionals-project-root
in repository https://gitbox.apache.org/repos/asf/buildstream.git


      at 574db6dd0 tests/format/optionprojectroot.py: Test option resolution in element overrides

This branch includes the following new commits:

     new bb42fa014 _project.py: Allow option conditional resolution at project toplevel.
     new dcc689890 tests/format/optionprojectroot.py: Test project root conditional resolution
     new 574db6dd0 tests/format/optionprojectroot.py: Test option resolution in element overrides

The 3 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/03: tests/format/optionprojectroot.py: Test project root conditional resolution

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

tvb pushed a commit to branch tristan/resolve-conditionals-project-root
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit dcc6898902a9a2619900304a764cf3db3cf72185
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Fri Jul 22 14:17:42 2022 +0900

    tests/format/optionprojectroot.py: Test project root conditional resolution
---
 tests/format/option-project-root/element.bst  |  1 +
 tests/format/option-project-root/project.conf | 19 ++++++++++++++++
 tests/format/optionprojectroot.py             | 32 +++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)

diff --git a/tests/format/option-project-root/element.bst b/tests/format/option-project-root/element.bst
new file mode 100644
index 000000000..4d7f70266
--- /dev/null
+++ b/tests/format/option-project-root/element.bst
@@ -0,0 +1 @@
+kind: manual
diff --git a/tests/format/option-project-root/project.conf b/tests/format/option-project-root/project.conf
new file mode 100644
index 000000000..eb254bc2c
--- /dev/null
+++ b/tests/format/option-project-root/project.conf
@@ -0,0 +1,19 @@
+name: test
+min-version: 2.0
+
+options:
+  animal:
+    type: enum
+    description: The kind of animal
+    values:
+    - pony
+    - horsy
+    default: pony
+
+(?):
+- animal == "pony":
+    variables:
+      result: "a pony"
+- animal == "horsy":
+    variables:
+      result: "a horsy"
diff --git a/tests/format/optionprojectroot.py b/tests/format/optionprojectroot.py
new file mode 100644
index 000000000..05f0d2d06
--- /dev/null
+++ b/tests/format/optionprojectroot.py
@@ -0,0 +1,32 @@
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+from buildstream import _yaml
+from buildstream.exceptions import ErrorDomain, LoadErrorReason
+from buildstream._testing.runcli import cli  # pylint: disable=unused-import
+
+# Project directory
+DATA_DIR = os.path.dirname(os.path.realpath(__file__))
+
+
+#
+# Test that project option conditionals can be resolved in the project root
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize(
+    "value,expected",
+    [ ("pony", "a pony"), ("horsy", "a horsy") ],
+    ids=["pony", "horsy"]
+)
+def test_resolve_project_root_conditional(cli, datafiles, value, expected):
+    project = os.path.join(datafiles.dirname, datafiles.basename, "option-project-root")
+    result = cli.run(
+        project=project,
+        silent=True,
+        args=["--option", "animal", value, "show", "--deps", "none", "--format", "%{vars}", "element.bst"],
+    )
+    result.assert_success()
+    loaded = _yaml.load_data(result.output)
+    assert loaded.get_str("result") == expected


[buildstream] 03/03: tests/format/optionprojectroot.py: Test option resolution in element overrides

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

tvb pushed a commit to branch tristan/resolve-conditionals-project-root
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 574db6dd077961473abc2e930dfeae9eba99a473
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Fri Jul 22 14:27:31 2022 +0900

    tests/format/optionprojectroot.py: Test option resolution in element overrides
    
    This already appears to be working fine, but let's just add another test
    to be sure.
---
 tests/format/option-element-override/element.bst  |  1 +
 tests/format/option-element-override/project.conf | 24 +++++++++++++++++++++++
 tests/format/optionprojectroot.py                 | 21 ++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/tests/format/option-element-override/element.bst b/tests/format/option-element-override/element.bst
new file mode 100644
index 000000000..4d7f70266
--- /dev/null
+++ b/tests/format/option-element-override/element.bst
@@ -0,0 +1 @@
+kind: manual
diff --git a/tests/format/option-element-override/project.conf b/tests/format/option-element-override/project.conf
new file mode 100644
index 000000000..63df718a6
--- /dev/null
+++ b/tests/format/option-element-override/project.conf
@@ -0,0 +1,24 @@
+name: test
+min-version: 2.0
+
+options:
+  animal:
+    type: enum
+    description: The kind of animal
+    values:
+    - pony
+    - horsy
+    default: pony
+
+variables:
+  result: "a sloppy joe"
+
+elements:
+  manual:
+    (?):
+    - animal == "pony":
+        variables:
+          result: "a pony"
+    - animal == "horsy":
+        variables:
+          result: "a horsy"
diff --git a/tests/format/optionprojectroot.py b/tests/format/optionprojectroot.py
index 05f0d2d06..2504aff3f 100644
--- a/tests/format/optionprojectroot.py
+++ b/tests/format/optionprojectroot.py
@@ -30,3 +30,24 @@ def test_resolve_project_root_conditional(cli, datafiles, value, expected):
     result.assert_success()
     loaded = _yaml.load_data(result.output)
     assert loaded.get_str("result") == expected
+
+
+#
+# Test that project option conditionals can be resolved in element overrides
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize(
+    "value,expected",
+    [ ("pony", "a pony"), ("horsy", "a horsy") ],
+    ids=["pony", "horsy"]
+)
+def test_resolve_element_override_conditional(cli, datafiles, value, expected):
+    project = os.path.join(datafiles.dirname, datafiles.basename, "option-element-override")
+    result = cli.run(
+        project=project,
+        silent=True,
+        args=["--option", "animal", value, "show", "--deps", "none", "--format", "%{vars}", "element.bst"],
+    )
+    result.assert_success()
+    loaded = _yaml.load_data(result.output)
+    assert loaded.get_str("result") == expected


[buildstream] 01/03: _project.py: Allow option conditional resolution at project toplevel.

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

tvb pushed a commit to branch tristan/resolve-conditionals-project-root
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit bb42fa01415241b46292dcb5cbfbccd08f31f92a
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Fri Jul 22 14:15:11 2022 +0900

    _project.py: Allow option conditional resolution at project toplevel.
    
    There are some early loaded essentials which do not support option
    conditionals, like the declaration of options, declaration of plugins,
    project name cannot be optional, etc.
    
    However generally speaking after the essentials have been parsed out
    the options should be resolved with this.
    
    Fixes #1683
---
 src/buildstream/_project.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index 62956ee4b..31c0f963a 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -646,6 +646,7 @@ class Project:
                 "source-caches",
                 "junctions",
                 "(@)",
+                "(?)",
             ]
         )