diff options
author | Tristan van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-06-01 20:06:12 +0900 |
---|---|---|
committer | Tristan van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-06-01 23:11:04 +0900 |
commit | e5d0e0c8ab134a874b74176b308f45b440a6f07b (patch) | |
tree | 9e1484dc517e608ad9f4793030dd75911201decb | |
parent | 6ec85d2942ea5a4adb7fbd9f9cd8e8d6beb41435 (diff) | |
download | buildstream-e5d0e0c8ab134a874b74176b308f45b440a6f07b.tar.gz |
junctions: Remove all traces of the `target` option
This removes:
* The `target` feature from the junction plugin
* Special case code in the loader for the `target` feature
* The `target` related cases in tests/format/junctions.py
This also adjusts the `target` related documentation in
the `junction` element to suggest using a `link` element for
the purpose of using a subproject junction configuration to
access a common sub-subproject.
15 files changed, 13 insertions, 167 deletions
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py index ed0d345a3..b73f5b862 100644 --- a/src/buildstream/_loader/loader.py +++ b/src/buildstream/_loader/loader.py @@ -274,18 +274,6 @@ class Loader: element = Element._new_from_meta(meta_element) element._initialize_state() - # If this junction element points to a sub-sub-project, we need to - # find loader for that project. - if element.target: - subproject_loader = self.get_loader( - element.target_junction, rewritable=rewritable, ticker=ticker, level=level, provenance=provenance - ) - loader = subproject_loader.get_loader( - element.target_element, rewritable=rewritable, ticker=ticker, level=level, provenance=provenance - ) - self._loaders[filename] = loader - return loader - # Handle the case where a subproject has no ref # if not element._has_all_sources_resolved(): diff --git a/src/buildstream/plugins/elements/junction.py b/src/buildstream/plugins/elements/junction.py index 86d1de8f8..c9e78632f 100644 --- a/src/buildstream/plugins/elements/junction.py +++ b/src/buildstream/plugins/elements/junction.py @@ -48,13 +48,6 @@ Overview # Optionally look in a subpath of the source repository for the project path: projects/hello - # Optionally specify another junction element to serve as a target for - # this element. Target should be defined using the syntax - # ``{junction-name}:{element-name}``. - # - # Note that this option cannot be used in conjunction with sources. - target: sub-project.bst:sub-sub-project.bst - # Optionally declare whether elements within the junction project # should interact with project remotes (default: False). cache-junction-elements: False @@ -132,29 +125,24 @@ simply use one junction and ignore the others. Due to this, BuildStream requires the user to resolve possibly conflicting nested junctions by creating a junction with the same name in the top-level project, which then takes precedence. -Targeting other junctions -~~~~~~~~~~~~~~~~~~~~~~~~~ -When working with nested junctions, you can also create a junction element that -targets another junction element in the sub-project. This can be useful if you -need to ensure that both the top-level project and the sub-project are using -the same version of the sub-sub-project. +Linking to other junctions +~~~~~~~~~~~~~~~~~~~~~~~~~~ +When working with nested junctions, you often need to ensure that multiple +projects are using the same version of a given subproject. + +In order to ensure that your project is using a junction to a sub-subproject +declared by a direct subproject, then you can use a :mod:`link <elements.link>` +element in place of declaring a junction. -This can be done using the ``target`` configuration option. See below for an -example: +This lets you create a link to a junction in the subproject, which you +can then treat as a regular junction in your toplevel project. .. code:: yaml - kind: junction + kind: link config: target: subproject.bst:subsubproject.bst - -In the above example, this junction element would be targeting the junction -element named ``subsubproject.bst`` in the subproject referred to by -``subproject.bst``. - -Note that when targeting another junction, the names of the junction element -must not be the same as the name of the target. """ from buildstream import Element, ElementError @@ -173,39 +161,15 @@ class JunctionElement(Element): def configure(self, node): - node.validate_keys(["path", "options", "target", "cache-junction-elements", "ignore-junction-remotes"]) + node.validate_keys(["path", "options", "cache-junction-elements", "ignore-junction-remotes"]) self.path = node.get_str("path", default="") self.options = node.get_mapping("options", default={}) - self.target = node.get_str("target", default=None) - self.target_element = None - self.target_junction = None self.cache_junction_elements = node.get_bool("cache-junction-elements", default=False) self.ignore_junction_remotes = node.get_bool("ignore-junction-remotes", default=False) def preflight(self): - # "target" cannot be used in conjunction with: - # 1. sources - # 2. config['options'] - # 3. config['path'] - if self.target and any(self.sources()): - raise ElementError("junction elements cannot define both 'sources' and 'target' config option") - if self.target and any(self.options.items()): - raise ElementError("junction elements cannot define both 'options' and 'target'") - if self.target and self.path: - raise ElementError("junction elements cannot define both 'path' and 'target'") - - # Validate format of target, if defined - if self.target: - try: - self.target_junction, self.target_element = self.target.split(":") - except ValueError: - raise ElementError("'target' option must be in format '{junction-name}:{element-name}'") - - # We cannot target a junction that has the same name as us, since that - # will cause an infinite recursion while trying to load it. - if self.name == self.target_element: - raise ElementError("junction elements cannot target an element with the same name") + pass def get_unique_key(self): # Junctions do not produce artifacts. get_unique_key() implementation diff --git a/tests/format/junctions.py b/tests/format/junctions.py index 70572ee3e..f097e0b8b 100644 --- a/tests/format/junctions.py +++ b/tests/format/junctions.py @@ -411,60 +411,6 @@ def test_build_git_cross_junction_names(cli, tmpdir, datafiles): @pytest.mark.datafiles(DATA_DIR) -def test_config_target(cli, tmpdir, datafiles): - project = os.path.join(str(datafiles), "config-target") - checkoutdir = os.path.join(str(tmpdir), "checkout") - - # Build, checkout - result = cli.run(project=project, args=["build", "target.bst"]) - result.assert_success() - result = cli.run(project=project, args=["artifact", "checkout", "target.bst", "--directory", checkoutdir]) - result.assert_success() - - # Check that the checkout contains the expected files from sub-sub-project - assert os.path.exists(os.path.join(checkoutdir, "hello.txt")) - - -@pytest.mark.datafiles(DATA_DIR) -def test_invalid_sources_and_target(cli, tmpdir, datafiles): - project = os.path.join(str(datafiles), "config-target") - - result = cli.run(project=project, args=["show", "invalid-source-target.bst"]) - result.assert_main_error(ErrorDomain.ELEMENT, None) - - assert "junction elements cannot define both 'sources' and 'target' config option" in result.stderr - - -@pytest.mark.datafiles(DATA_DIR) -def test_invalid_target_name(cli, tmpdir, datafiles): - project = os.path.join(str(datafiles), "config-target") - - # Rename our junction element to the same name as its target - old_path = os.path.join(project, "elements/subsubproject.bst") - new_path = os.path.join(project, "elements/subsubproject-junction.bst") - os.rename(old_path, new_path) - - # This should fail now - result = cli.run(project=project, args=["show", "subsubproject-junction.bst"]) - result.assert_main_error(ErrorDomain.ELEMENT, None) - - assert "junction elements cannot target an element with the same name" in result.stderr - - -# We cannot exhaustively test all possible ways in which this can go wrong, so -# test a couple of common ways in which we expect this to go wrong. -@pytest.mark.parametrize("target", ["no-junction.bst", "nested-junction-target.bst"]) -@pytest.mark.datafiles(DATA_DIR) -def test_invalid_target_format(cli, tmpdir, datafiles, target): - project = os.path.join(str(datafiles), "config-target") - - result = cli.run(project=project, args=["show", target]) - result.assert_main_error(ErrorDomain.ELEMENT, None) - - assert "'target' option must be in format '{junction-name}:{element-name}'" in result.stderr - - -@pytest.mark.datafiles(DATA_DIR) def test_junction_show(cli, tmpdir, datafiles): project = os.path.join(str(datafiles), "foo") copy_subprojects(project, datafiles, ["base"]) diff --git a/tests/format/junctions/config-target/elements/invalid-source-target.bst b/tests/format/junctions/config-target/elements/invalid-source-target.bst deleted file mode 100644 index b97d09034..000000000 --- a/tests/format/junctions/config-target/elements/invalid-source-target.bst +++ /dev/null @@ -1,8 +0,0 @@ -kind: junction - -sources: -- kind: local - path: subproject/subsubproject - -config: - target: subproject.bst:subsubproject-junction.bst diff --git a/tests/format/junctions/config-target/elements/nested-junction-target.bst b/tests/format/junctions/config-target/elements/nested-junction-target.bst deleted file mode 100644 index f76a264e5..000000000 --- a/tests/format/junctions/config-target/elements/nested-junction-target.bst +++ /dev/null @@ -1,4 +0,0 @@ -kind: junction - -config: - target: subproject.bst:subsubproject.bst:hello.bst diff --git a/tests/format/junctions/config-target/elements/no-junction.bst b/tests/format/junctions/config-target/elements/no-junction.bst deleted file mode 100644 index 15d1842f6..000000000 --- a/tests/format/junctions/config-target/elements/no-junction.bst +++ /dev/null @@ -1,4 +0,0 @@ -kind: junction - -config: - target: subproject.bst diff --git a/tests/format/junctions/config-target/elements/subproject.bst b/tests/format/junctions/config-target/elements/subproject.bst deleted file mode 100644 index 6664eeec6..000000000 --- a/tests/format/junctions/config-target/elements/subproject.bst +++ /dev/null @@ -1,5 +0,0 @@ -kind: junction - -sources: -- kind: local - path: subproject diff --git a/tests/format/junctions/config-target/elements/subsubproject.bst b/tests/format/junctions/config-target/elements/subsubproject.bst deleted file mode 100644 index 20dc4a0c4..000000000 --- a/tests/format/junctions/config-target/elements/subsubproject.bst +++ /dev/null @@ -1,4 +0,0 @@ -kind: junction - -config: - target: subproject.bst:subsubproject-junction.bst diff --git a/tests/format/junctions/config-target/elements/target.bst b/tests/format/junctions/config-target/elements/target.bst deleted file mode 100644 index 50d74489a..000000000 --- a/tests/format/junctions/config-target/elements/target.bst +++ /dev/null @@ -1,4 +0,0 @@ -kind: stack - -depends: -- subsubproject.bst:hello.bst diff --git a/tests/format/junctions/config-target/project.conf b/tests/format/junctions/config-target/project.conf deleted file mode 100644 index d9e1d7a4f..000000000 --- a/tests/format/junctions/config-target/project.conf +++ /dev/null @@ -1,4 +0,0 @@ -name: config-target -min-version: 2.0 - -element-path: elements diff --git a/tests/format/junctions/config-target/subproject/elements/subsubproject-junction.bst b/tests/format/junctions/config-target/subproject/elements/subsubproject-junction.bst deleted file mode 100644 index 018fb8ec4..000000000 --- a/tests/format/junctions/config-target/subproject/elements/subsubproject-junction.bst +++ /dev/null @@ -1,5 +0,0 @@ -kind: junction - -sources: -- kind: local - path: subsubproject diff --git a/tests/format/junctions/config-target/subproject/project.conf b/tests/format/junctions/config-target/subproject/project.conf deleted file mode 100644 index 1529ece04..000000000 --- a/tests/format/junctions/config-target/subproject/project.conf +++ /dev/null @@ -1,4 +0,0 @@ -name: subproject -min-version: 2.0 - -element-path: elements diff --git a/tests/format/junctions/config-target/subproject/subsubproject/elements/hello.bst b/tests/format/junctions/config-target/subproject/subsubproject/elements/hello.bst deleted file mode 100644 index a04a856cd..000000000 --- a/tests/format/junctions/config-target/subproject/subsubproject/elements/hello.bst +++ /dev/null @@ -1,5 +0,0 @@ -kind: import - -sources: -- kind: local - path: files/hello.txt diff --git a/tests/format/junctions/config-target/subproject/subsubproject/files/hello.txt b/tests/format/junctions/config-target/subproject/subsubproject/files/hello.txt deleted file mode 100644 index ce0136250..000000000 --- a/tests/format/junctions/config-target/subproject/subsubproject/files/hello.txt +++ /dev/null @@ -1 +0,0 @@ -hello diff --git a/tests/format/junctions/config-target/subproject/subsubproject/project.conf b/tests/format/junctions/config-target/subproject/subsubproject/project.conf deleted file mode 100644 index 162143c80..000000000 --- a/tests/format/junctions/config-target/subproject/subsubproject/project.conf +++ /dev/null @@ -1,4 +0,0 @@ -name: subsubproject -min-version: 2.0 - -element-path: elements |