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 09:50:05 UTC

[buildstream] 02/02: tests/plugin/loading.py: Regression test for complex cross junction scenario

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

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

commit 5da8473b98b059d59185cbc8f8a3214f5a2ca464
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Fri Jul 22 18:46:18 2022 +0900

    tests/plugin/loading.py: Regression test for complex cross junction scenario
    
    This sets up a complex test scenario which provokes the junction
    plugin origin to prematurely resolve projects, triggering issues like #1686.
---
 tests/plugins/junction-with-junction/element.bst   |  1 +
 tests/plugins/junction-with-junction/project.conf  | 11 ++++
 .../junction-with-junction/subproject/project.conf |  2 +
 .../subproject/variables.yml                       |  4 ++
 tests/plugins/loading.py                           | 73 ++++++++++++++++++++++
 tests/plugins/sample-plugins/project.conf          | 15 +++++
 6 files changed, 106 insertions(+)

diff --git a/tests/plugins/junction-with-junction/element.bst b/tests/plugins/junction-with-junction/element.bst
new file mode 100644
index 000000000..4d7f70266
--- /dev/null
+++ b/tests/plugins/junction-with-junction/element.bst
@@ -0,0 +1 @@
+kind: manual
diff --git a/tests/plugins/junction-with-junction/project.conf b/tests/plugins/junction-with-junction/project.conf
new file mode 100644
index 000000000..b64a6b1e7
--- /dev/null
+++ b/tests/plugins/junction-with-junction/project.conf
@@ -0,0 +1,11 @@
+name: test
+min-version: 2.0
+
+plugins:
+- origin: junction
+  junction: sample-plugins.bst
+  sources:
+  - git
+
+(@):
+- subproject.bst:variables.yml
diff --git a/tests/plugins/junction-with-junction/subproject/project.conf b/tests/plugins/junction-with-junction/subproject/project.conf
new file mode 100644
index 000000000..7d535b650
--- /dev/null
+++ b/tests/plugins/junction-with-junction/subproject/project.conf
@@ -0,0 +1,2 @@
+name: subproject-test
+min-version: 2.0
diff --git a/tests/plugins/junction-with-junction/subproject/variables.yml b/tests/plugins/junction-with-junction/subproject/variables.yml
new file mode 100644
index 000000000..c5ade0f85
--- /dev/null
+++ b/tests/plugins/junction-with-junction/subproject/variables.yml
@@ -0,0 +1,4 @@
+
+
+variables:
+  animal: pony
diff --git a/tests/plugins/loading.py b/tests/plugins/loading.py
index 2863133dd..b85dbd29b 100644
--- a/tests/plugins/loading.py
+++ b/tests/plugins/loading.py
@@ -12,8 +12,10 @@ import pytest
 
 from buildstream.exceptions import ErrorDomain, LoadErrorReason
 from buildstream._testing import cli  # pylint: disable=unused-import
+from buildstream._testing import create_repo
 from buildstream import _yaml
 
+from tests.testutils.repo.git import Git
 from tests.testutils.site import pip_sample_packages  # pylint: disable=unused-import
 from tests.testutils.site import SAMPLE_PACKAGES_SKIP_REASON
 
@@ -823,3 +825,74 @@ def test_junction_invalid_full_path(cli, datafiles, plugin_type, provenance):
     result = cli.run(project=project, args=["show", "element.bst"])
     result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE)
     assert provenance in result.stderr
+
+
+# Test scenario for junction plugin origins
+# =========================================
+#
+# This is a regression test which ensures that cross junction includes
+# at the project.conf level continues to work even in conjunction with
+# complex cross junction plugin loading scenarios.
+#
+#         main project
+#         /           \
+#        |             |
+#  junction (tar)      |
+#        |             | include a file across this junction
+#        |             |
+#        /             |
+#  git plugin           \
+#                        \
+#                  junction (git)
+#                         |
+#                         |
+#                     subproject
+#
+#
+# `bst source track subproject.bst`
+#
+#
+JUNCTION_DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)))
+
+
+@pytest.mark.datafiles(JUNCTION_DATA_DIR)
+def test_load_junction_via_junctioned_plugin(cli, datafiles, tmpdir):
+    sample_plugins_dir = os.path.join(str(datafiles), "sample-plugins")
+    project = os.path.join(str(datafiles), "junction-with-junction")
+    subproject = os.path.join(str(datafiles), "junction-with-junction", "subproject")
+
+    # Create a tar repo containing the sample plugins
+    #
+    repo = create_repo("tar", str(tmpdir))
+    ref = repo.create(sample_plugins_dir)
+
+    # Generate the junction to the sample plugins
+    #
+    element = {"kind": "junction", "sources": [repo.source_config(ref=ref)]}
+    _yaml.roundtrip_dump(element, os.path.join(project, "sample-plugins.bst"))
+
+    # Create a git repo containing the subproject
+    #
+    subproject_repo = Git(str(tmpdir))
+    subproject_repo.create(subproject)
+
+    # Generate the subproject junction pointing to the git repo with the subproject
+    #
+    element = {"kind": "junction", "sources": [subproject_repo.source_config()]}
+    _yaml.roundtrip_dump(element, os.path.join(project, "subproject.bst"))
+
+    # Track the subproject
+    #
+    result = cli.run(project=project, args=["source", "track", "subproject.bst"])
+    result.assert_success()
+
+    # Check the included variable resolves in the element
+    #
+    result = cli.run(
+        project=project,
+        silent=True,
+        args=["show", "--deps", "none", "--format", "%{vars}", "element.bst"],
+    )
+    result.assert_success()
+    loaded = _yaml.load_data(result.output)
+    assert loaded.get_str("animal") == "pony"
diff --git a/tests/plugins/sample-plugins/project.conf b/tests/plugins/sample-plugins/project.conf
new file mode 100644
index 000000000..60fd37224
--- /dev/null
+++ b/tests/plugins/sample-plugins/project.conf
@@ -0,0 +1,15 @@
+name: sample-plugins
+min-version: 2.0
+
+plugins:
+- origin: local
+  path: src/sample_plugins/elements
+  elements:
+  - autotools
+  - sample
+
+- origin: local
+  path: src/sample_plugins/sources
+  sources:
+  - git
+  - sample