Skip to content
Snippets Groups Projects
Commit 224a1249 authored by Chandan Singh's avatar Chandan Singh
Browse files

loader: Allow dependencies to use ":" to refer to junctioned elements

This will allow cross-junction dependencies to be listed as strings on a
single line.

Fixes #809.
parent 32a101f6
No related branches found
No related tags found
No related merge requests found
Pipeline #41703102 passed
...@@ -150,7 +150,13 @@ def _extract_depends_from_node(node, *, key=None): ...@@ -150,7 +150,13 @@ def _extract_depends_from_node(node, *, key=None):
dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[index]) dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[index])
if isinstance(dep, str): if isinstance(dep, str):
dependency = Dependency(dep, provenance=dep_provenance, dep_type=default_dep_type) junction_path = dep.rsplit(":", 1)
filename = junction_path[-1]
junction = None if len(junction_path) == 1 else junction_path[-2]
dependency = Dependency(filename,
junction=junction,
dep_type=default_dep_type,
provenance=dep_provenance)
elif isinstance(dep, Mapping): elif isinstance(dep, Mapping):
if default_dep_type: if default_dep_type:
......
...@@ -593,3 +593,45 @@ def test_build_checkout_cross_junction(datafiles, cli, tmpdir): ...@@ -593,3 +593,45 @@ def test_build_checkout_cross_junction(datafiles, cli, tmpdir):
filename = os.path.join(checkout, 'etc', 'animal.conf') filename = os.path.join(checkout, 'etc', 'animal.conf')
assert os.path.exists(filename) assert os.path.exists(filename)
@pytest.mark.datafiles(DATA_DIR)
def test_build_junction_short_notation(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
subproject_path = os.path.join(project, 'files', 'sub-project')
junction_path = os.path.join(project, 'elements', 'junction.bst')
element_path = os.path.join(project, 'elements', 'junction-dep.bst')
workspace = os.path.join(cli.directory, 'workspace')
checkout = os.path.join(cli.directory, 'checkout')
# Create a repo to hold the subproject and generate a junction element for it
ref = generate_junction(tmpdir, subproject_path, junction_path)
# Create a stack element to depend on a cross junction element, using
# colon (:) as the separator
element = {
'kind': 'stack',
'depends': ['junction.bst:import-etc.bst']
}
_yaml.dump(element, element_path)
# Now try to build it, this should automatically result in fetching
# the junction itself at load time.
result = cli.run(project=project, args=['build', 'junction-dep.bst'])
result.assert_success()
# Assert that it's cached now
assert cli.get_element_state(project, 'junction-dep.bst') == 'cached'
# Now check it out
result = cli.run(project=project, args=[
'checkout', 'junction-dep.bst', checkout
])
result.assert_success()
# Assert the content of /etc/animal.conf
filename = os.path.join(checkout, 'etc', 'animal.conf')
assert os.path.exists(filename)
with open(filename, 'r') as f:
contents = f.read()
assert contents == 'animal=Pony\n'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment