diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | src/buildstream/_frontend/cli.py | 13 | ||||
-rw-r--r-- | tests/frontend/fetch.py | 41 | ||||
-rw-r--r-- | tests/frontend/source-fetch/apples.bst | 6 | ||||
-rw-r--r-- | tests/frontend/source-fetch/bananas.bst | 12 | ||||
-rw-r--r-- | tests/frontend/source-fetch/files/apples | 1 | ||||
-rw-r--r-- | tests/frontend/source-fetch/files/bananas | 1 | ||||
-rw-r--r-- | tests/frontend/source-fetch/files/oranges | 1 | ||||
-rw-r--r-- | tests/frontend/source-fetch/oranges.bst | 6 |
9 files changed, 81 insertions, 1 deletions
@@ -7,6 +7,7 @@ CLI o `bst shell --build` will now automatically fetch missing sources. o `bst build --deps` now also accepts "build" as an input. + o `bst source fetch --deps` now also accepts "build" and "run" as inputs. Format diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index b8fd55b08..f3499a56c 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -813,7 +813,16 @@ def source(): "-d", default=_PipelineSelection.PLAN, show_default=True, - type=FastEnumType(_PipelineSelection, [_PipelineSelection.NONE, _PipelineSelection.PLAN, _PipelineSelection.ALL]), + type=FastEnumType( + _PipelineSelection, + [ + _PipelineSelection.PLAN, + _PipelineSelection.NONE, + _PipelineSelection.BUILD, + _PipelineSelection.RUN, + _PipelineSelection.ALL, + ], + ), help="The dependencies to fetch", ) @click.option( @@ -841,6 +850,8 @@ def source_fetch(app, elements, deps, except_, remote): \b none: No dependencies, just the element itself plan: Only dependencies required for the build plan + run: Runtime dependencies, including the element itself + build: Build time dependencies, excluding the element itself all: All dependencies """ with app.initialized(session_name="Fetch"): diff --git a/tests/frontend/fetch.py b/tests/frontend/fetch.py index d6b28c589..b2c9d64c2 100644 --- a/tests/frontend/fetch.py +++ b/tests/frontend/fetch.py @@ -5,6 +5,7 @@ import os import pytest from buildstream.testing import cli # pylint: disable=unused-import +from buildstream.testing import generate_project from buildstream import _yaml from buildstream.exceptions import ErrorDomain, LoadErrorReason @@ -17,6 +18,46 @@ TOP_DIR = os.path.dirname(os.path.realpath(__file__)) DATA_DIR = os.path.join(TOP_DIR, "project") +# Test all possible choices of the `--deps` option. +# +# NOTE: Elements used in this test must have sources that are not already +# cached. The kind of the sources do not matter so long as they need to +# be fetched from somewhere. +# Currently we use remote sources for this purpose. +# +@pytest.mark.datafiles(os.path.join(TOP_DIR, "source-fetch")) +@pytest.mark.parametrize( + "deps, expected_states", + [ + ("build", ("fetch needed", "buildable", "fetch needed")), + ("none", ("waiting", "fetch needed", "fetch needed")), + ("run", ("waiting", "fetch needed", "buildable")), + ("all", ("waiting", "buildable", "buildable")), + ], +) +def test_fetch_deps(cli, datafiles, deps, expected_states): + project = str(datafiles) + generate_project(project) + generate_project(project, {"aliases": {"project-root": "file:///" + project}}) + + target = "bananas.bst" + build_dep = "apples.bst" + runtime_dep = "oranges.bst" + + # Assert that none of the sources are cached + states = cli.get_element_states(project, [target, build_dep, runtime_dep]) + assert all([state == "fetch needed" for state in states.values()]) + + # Now fetch the specified sources + result = cli.run(project=project, args=["source", "fetch", "--deps", deps, target]) + result.assert_success() + + # Finally assert that we have fetched _only_ the desired sources + states = cli.get_element_states(project, [target, build_dep, runtime_dep]) + states_flattened = (states[target], states[build_dep], states[runtime_dep]) + assert states_flattened == expected_states + + @pytest.mark.datafiles(os.path.join(TOP_DIR, "consistencyerror")) def test_fetch_consistency_error(cli, datafiles): project = str(datafiles) diff --git a/tests/frontend/source-fetch/apples.bst b/tests/frontend/source-fetch/apples.bst new file mode 100644 index 000000000..61a0cdf56 --- /dev/null +++ b/tests/frontend/source-fetch/apples.bst @@ -0,0 +1,6 @@ +kind: import + +sources: +- kind: remote + url: project-root:/files/apples + ref: 39ac5969800f779603237d01dc0be28dd795a33c591af6c7736264482265930a diff --git a/tests/frontend/source-fetch/bananas.bst b/tests/frontend/source-fetch/bananas.bst new file mode 100644 index 000000000..45416106f --- /dev/null +++ b/tests/frontend/source-fetch/bananas.bst @@ -0,0 +1,12 @@ +kind: import + +build-depends: +- apples.bst + +runtime-depends: +- oranges.bst + +sources: +- kind: remote + url: project-root:/files/bananas + ref: e49295702f7da8670778e9b95a281b72b41b31cb16afa376034b45f59a18ea3f diff --git a/tests/frontend/source-fetch/files/apples b/tests/frontend/source-fetch/files/apples new file mode 100644 index 000000000..950a188f0 --- /dev/null +++ b/tests/frontend/source-fetch/files/apples @@ -0,0 +1 @@ +apples diff --git a/tests/frontend/source-fetch/files/bananas b/tests/frontend/source-fetch/files/bananas new file mode 100644 index 000000000..9baf85eb7 --- /dev/null +++ b/tests/frontend/source-fetch/files/bananas @@ -0,0 +1 @@ +bananas diff --git a/tests/frontend/source-fetch/files/oranges b/tests/frontend/source-fetch/files/oranges new file mode 100644 index 000000000..192019cb7 --- /dev/null +++ b/tests/frontend/source-fetch/files/oranges @@ -0,0 +1 @@ +oranges diff --git a/tests/frontend/source-fetch/oranges.bst b/tests/frontend/source-fetch/oranges.bst new file mode 100644 index 000000000..35984edfd --- /dev/null +++ b/tests/frontend/source-fetch/oranges.bst @@ -0,0 +1,6 @@ +kind: import + +sources: +- kind: remote + url: project-root:/files/oranges + ref: b19fe3ce519db5b79021aed3e83d9533631d69b15813f9e198a4ba4a3107deaa |