diff --git a/buildstream/_loader/loadelement.py b/buildstream/_loader/loadelement.py index 1c520f6faa5ec0176595a919946a558f44ed9580..def24373a7efd72d502363cbfd7b4cf0293d7d7d 100644 --- a/buildstream/_loader/loadelement.py +++ b/buildstream/_loader/loadelement.py @@ -150,7 +150,13 @@ def _extract_depends_from_node(node, *, key=None): dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[index]) 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): if default_dep_type: diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py index 03bba0b26a284eb6e69734d15d355678c85a5d90..589d724b8af2f9227caa4004e2f8e255a2b50df9 100644 --- a/tests/frontend/buildcheckout.py +++ b/tests/frontend/buildcheckout.py @@ -593,3 +593,45 @@ def test_build_checkout_cross_junction(datafiles, cli, tmpdir): filename = os.path.join(checkout, 'etc', 'animal.conf') 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'