diff options
author | bst-marge-bot <marge-bot@buildstream.build> | 2020-09-09 12:47:11 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-09-09 12:47:11 +0000 |
commit | eca24ae1fbc03503ffcf60ca2600dbc8fefc484f (patch) | |
tree | cebc28e5dfaeb31ad5299a71c58b7e3c68dc1949 | |
parent | f884b111dd238d3c6ed824716300d3facda900bf (diff) | |
parent | d2265d2535f02ecb9a6a8e3dc9e6649ffea8bd3c (diff) | |
download | buildstream-eca24ae1fbc03503ffcf60ca2600dbc8fefc484f.tar.gz |
Merge branch 'juerg/cache-key' into 'master'
element.py: Fix dependency cache key check in non-strict mode
See merge request BuildStream/buildstream!2061
-rw-r--r-- | src/buildstream/element.py | 11 | ||||
-rw-r--r-- | tests/frontend/buildcheckout.py | 34 |
2 files changed, 40 insertions, 5 deletions
diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 442920b75..bdac7054d 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -2066,6 +2066,10 @@ class Element(Plugin): # # Calculates the cache key # + # Args: + # dependencies (List[List[str]]): list of dependencies with project name, + # element name and optional cache key + # # Returns: # (str): A hex digest cache key for this Element, or None # @@ -2073,7 +2077,7 @@ class Element(Plugin): # def _calculate_cache_key(self, dependencies): # No cache keys for dependencies which have no cache keys - if None in dependencies: + if any(not all(dep) for dep in dependencies): return None # Generate dict that is used as base for all cache keys @@ -3001,10 +3005,7 @@ class Element(Plugin): return if self.__strict_cache_key is None: - dependencies = [ - [e.project_name, e.name, e.__strict_cache_key] if e.__strict_cache_key is not None else None - for e in self._dependencies(_Scope.BUILD) - ] + dependencies = [[e.project_name, e.name, e.__strict_cache_key] for e in self._dependencies(_Scope.BUILD)] self.__strict_cache_key = self._calculate_cache_key(dependencies) if self.__strict_cache_key is not None: diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py index 7c1f910b6..5afa5216d 100644 --- a/tests/frontend/buildcheckout.py +++ b/tests/frontend/buildcheckout.py @@ -115,6 +115,40 @@ def test_non_strict_build_strict_checkout(datafiles, cli): @pytest.mark.datafiles(DATA_DIR) +def test_non_strict_pull_build_strict_checkout(datafiles, cli, tmpdir): + project = str(datafiles) + checkout = os.path.join(cli.directory, "checkout") + + # Target with at least one (indirect) build-only dependency + element_name = "target.bst" + + with create_artifact_share(os.path.join(str(tmpdir), "artifactshare")) as share: + + cli.configure({"artifacts": {"url": share.repo}}) + + # First build it in non-strict mode with an artifact server configured. + # With this configuration BuildStream will attempt to pull the build-only + # dependencies after attempting to pull the target element. This means + # that the cache key calculation of the target element has to be deferred + # until the pull attempt of the build-only dependencies, exercising a + # different code path. + # As this is a clean build from scratch, the result and also the cache keys + # should be identical to a build in strict mode. + result = cli.run(project=project, args=["--no-strict", "build", element_name]) + result.assert_success() + + # Now check it out in strict mode. + # This verifies that the clean build in non-strict mode produced an artifact + # matching the strict cache key. + result = cli.run(project=project, args=["artifact", "checkout", element_name, "--directory", checkout]) + result.assert_success() + + # Check that the executable hello file is found in the checkout + filename = os.path.join(checkout, "usr", "bin", "hello") + assert os.path.exists(filename) + + +@pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("strict,hardlinks", [("non-strict", "hardlinks"),]) def test_build_invalid_suffix(datafiles, cli, strict, hardlinks): project = str(datafiles) |