Commit 314c25d8 authored by Chandan Singh's avatar Chandan Singh Committed by Tristan Van Berkom

element.py: Fix consistency of workspaced elements when ref is missing

Fixes #393.
parent 84a57b2f
Pipeline #22196525 passed with stages
in 29 minutes and 25 seconds
......@@ -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():
#
......
......@@ -355,6 +355,38 @@ def test_build(cli, tmpdir, datafiles, kind, strict):
assert not os.path.exists(os.path.join(checkout, 'usr', 'bin', 'hello'))
@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")])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment