diff options
author | Chandan Singh <csingh43@bloomberg.net> | 2018-05-11 17:48:28 +0100 |
---|---|---|
committer | Chandan Singh <csingh43@bloomberg.net> | 2018-05-17 11:40:20 +0100 |
commit | ba6eaba60a09f1c1e30145fdbe4b82161bb341a6 (patch) | |
tree | 43b2c997f2fcbb9bbc955c07aeb8a74b730c1e47 | |
parent | e023beb56b180316a58f409d48f158e9dc1ece95 (diff) | |
download | buildstream-chandan/393-fix-workspace-no-reference.tar.gz |
element.py: Fix consistency of workspaced elements when ref is missingchandan/393-fix-workspace-no-reference
Fixes #393.
-rw-r--r-- | buildstream/element.py | 19 | ||||
-rw-r--r-- | tests/frontend/workspace.py | 32 |
2 files changed, 42 insertions, 9 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index 70bee42e6..90cdec640 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -1864,17 +1864,11 @@ class Element(Plugin): if self.__tracking_scheduled: return - # Determine overall consistency of the element - consistency = Consistency.CACHED - for source in self.__sources: - source._update_state() - source_consistency = source._get_consistency() - consistency = min(consistency, source_consistency) - self.__consistency = consistency + self.__consistency = Consistency.CACHED + workspace = self._get_workspace() # Special case for workspaces - workspace = self._get_workspace() - if workspace and self.__consistency > Consistency.INCONSISTENT: + if workspace: # A workspace is considered inconsistent in the case # that it's directory went missing @@ -1882,6 +1876,13 @@ class Element(Plugin): fullpath = workspace.get_absolute_path() if not os.path.exists(fullpath): self.__consistency = Consistency.INCONSISTENT + else: + + # Determine overall consistency of the element + for source in self.__sources: + source._update_state() + source_consistency = source._get_consistency() + self.__consistency = min(self.__consistency, source_consistency) # __calculate_cache_key(): # diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py index e45696d38..90b50613f 100644 --- a/tests/frontend/workspace.py +++ b/tests/frontend/workspace.py @@ -356,6 +356,38 @@ def test_build(cli, tmpdir, datafiles, kind, strict): @pytest.mark.datafiles(DATA_DIR) +def test_buildable_no_ref(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + element_name = 'workspace-test-no-ref.bst' + element_path = os.path.join(project, 'elements') + + # Write out our test target without any source ref + repo = create_repo('git', str(tmpdir)) + element = { + 'kind': 'import', + 'sources': [ + repo.source_config() + ] + } + _yaml.dump(element, + os.path.join(element_path, + element_name)) + + # Assert that this target is not buildable when no workspace is associated. + assert cli.get_element_state(project, element_name) == 'no reference' + + # Now open the workspace. We don't need to checkout the source though. + workspace = os.path.join(str(tmpdir), 'workspace-no-ref') + os.makedirs(workspace) + args = ['workspace', 'open', '--no-checkout', element_name, workspace] + result = cli.run(project=project, args=args) + result.assert_success() + + # Assert that the target is now buildable. + assert cli.get_element_state(project, element_name) == 'buildable' + + +@pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("modification", [("addfile"), ("removefile"), ("modifyfile")]) @pytest.mark.parametrize("strict", [("strict"), ("non-strict")]) def test_detect_modifications(cli, tmpdir, datafiles, modification, strict): |