summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-12-10 11:42:36 +0000
committerJürg Billeter <j@bitron.ch>2019-12-10 11:42:36 +0000
commit393fd2d458181cb9cbf30133dc5bbac8659db84b (patch)
treecff511d07c5832d465fd3ad7ab44fac243675931
parentc39c12ec8e5ea99de56f70904408dd41c037820d (diff)
parent10e4aa7c357351f81fa0dd1b3a87df6dea50c37b (diff)
downloadbuildstream-393fd2d458181cb9cbf30133dc5bbac8659db84b.tar.gz
Merge branch 'coldtom/fix-junction-remotes' into 'master'
_project.py: Allow junctions to use parent remote when `ignore-junction-remotes` set See merge request BuildStream/buildstream!1759
-rw-r--r--src/buildstream/_project.py6
-rw-r--r--tests/artifactcache/junctions.py47
2 files changed, 50 insertions, 3 deletions
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index fb2ae1a88..0a9580dbe 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -698,12 +698,12 @@ class Project:
# its elements, append the junction's remotes to the artifact cache specs list
if self.junction:
parent = self.junction._get_project()
- if self.junction.cache_junction_elements:
- self.artifact_cache_specs = parent.artifact_cache_specs + self.artifact_cache_specs
-
if self.junction.ignore_junction_remotes:
self.artifact_cache_specs = []
+ if self.junction.cache_junction_elements:
+ self.artifact_cache_specs = parent.artifact_cache_specs + self.artifact_cache_specs
+
# Load source caches with pull/push config
self.source_cache_specs = SourceCache.specs_from_config_node(config, self.directory)
diff --git a/tests/artifactcache/junctions.py b/tests/artifactcache/junctions.py
index 76ba85fb5..df7ee9473 100644
--- a/tests/artifactcache/junctions.py
+++ b/tests/artifactcache/junctions.py
@@ -192,3 +192,50 @@ def test_ignore_junction_remotes(cli, tmpdir, datafiles):
# We shouldn't be able to download base-element!
state = cli.get_element_state(base_project, "base-element.bst")
assert state != "cached"
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_caching_elements_ignoring_remotes(cli, tmpdir, datafiles):
+ project = os.path.join(str(datafiles), "parent")
+ base_project = os.path.join(str(project), "base")
+
+ # Load the junction element
+ junction_element = os.path.join(project, "base.bst")
+ junction_data = _yaml.roundtrip_load(junction_element)
+
+ # Configure to push everything to the project's remote and nothing to the junction's
+ junction_data["config"] = {"cache-junction-elements": True, "ignore-junction-remotes": True}
+ _yaml.roundtrip_dump(junction_data, junction_element)
+
+ with create_artifact_share(os.path.join(str(tmpdir), "artifactshare-parent")) as share, create_artifact_share(
+ os.path.join(str(tmpdir), "artifactshare-base")
+ ) as base_share:
+
+ # First build it without the artifact cache configured
+ result = cli.run(project=project, args=["build", "target.bst"])
+ assert result.exit_code == 0
+
+ # Assert that we are now cached locally
+ state = cli.get_element_state(project, "target.bst")
+ assert state == "cached"
+ state = cli.get_element_state(base_project, "base-element.bst")
+ assert state == "cached"
+
+ project_set_artifacts(project, share.repo)
+ project_set_artifacts(base_project, base_share.repo)
+
+ # Push to the remote(s))
+ result = cli.run(project=project, args=["artifact", "push", "--deps", "all", "target.bst"])
+ assert result.exit_code == 0
+
+ # And finally assert that the artifacts are in the right shares
+ #
+ # The parent project's cache should *also* contain elements from the junction
+ assert_shared(cli, share, project, "target.bst", project_name="parent")
+ assert_shared(cli, share, project, "app.bst", project_name="parent")
+ assert_shared(cli, share, base_project, "base-element.bst", project_name="base")
+
+ # The junction project's cache should be empty
+ assert_not_shared(cli, base_share, project, "target.bst", project_name="parent")
+ assert_not_shared(cli, base_share, project, "app.bst", project_name="parent")
+ assert_not_shared(cli, base_share, base_project, "base-element.bst", project_name="base")