diff options
author | Jürg Billeter <j@bitron.ch> | 2020-10-14 18:45:01 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-10-27 08:12:46 +0100 |
commit | f972a189b386455d8967a611b40767d575aff78a (patch) | |
tree | 378f8d91a1e11cd79a2e1b8026ffa8b56da4464e | |
parent | e1b40faef1ee3cabe42a71e1afdd7b65a7d8425b (diff) | |
download | buildstream-f972a189b386455d8967a611b40767d575aff78a.tar.gz |
_frontend/cli.py: Drop support for bst shell --use-buildtree=try
`--use-buildtree` is now a boolean option for `bst shell`. If no
buildtree is available, an error is raised.
-rw-r--r-- | src/buildstream/_frontend/cli.py | 11 | ||||
-rw-r--r-- | src/buildstream/_stream.py | 22 | ||||
-rw-r--r-- | tests/integration/shellbuildtrees.py | 86 | ||||
-rw-r--r-- | tests/integration/workspace.py | 10 | ||||
-rw-r--r-- | tests/remoteexecution/buildtree.py | 4 | ||||
-rw-r--r-- | tests/remoteexecution/workspace.py | 3 |
6 files changed, 29 insertions, 107 deletions
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 3f804c2af..5e42bda68 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -578,12 +578,9 @@ def show(app, elements, deps, except_, order, format_): "--use-buildtree", "-t", "cli_buildtree", - type=click.Choice(["try", "always", "never"]), - default="never", - show_default=True, + is_flag=True, help=( - "Stage a buildtree. If `always` is set, will always fail to " - "build if a buildtree is not available." + "Stage a buildtree. Will fail if a buildtree is not available." " --pull and pull-buildtrees configuration is needed " "if trying to query for remotely cached buildtrees." ), @@ -618,10 +615,8 @@ def shell(app, element, mount, isolate, build_, cli_buildtree, pull_, command): from .._project import HostMount # Buildtree can only be used with build shells - if cli_buildtree != "never": + if cli_buildtree: build_ = True - else: - cli_buildtree = None scope = _Scope.BUILD if build_ else _Scope.RUN diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 234211c49..af0537fe1 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -173,7 +173,7 @@ class Stream: # mounts (list of HostMount): Additional directories to mount into the sandbox # isolate (bool): Whether to isolate the environment like we do in builds # command (list): An argv to launch in the sandbox, or None - # usebuildtree (str): Whether to use a buildtree as the source, given cli option + # usebuildtree (bool): Whether to use a buildtree as the source, given cli option # pull_ (bool): Whether to attempt to pull missing or incomplete artifacts # unique_id: (str): Whether to use a unique_id to load an Element instance # @@ -189,7 +189,7 @@ class Stream: mounts=None, isolate=False, command=None, - usebuildtree=None, + usebuildtree=False, pull_=False, unique_id=None ): @@ -222,7 +222,6 @@ class Stream: detail="\n".join(list(map(lambda x: x._get_full_name(), missing_deps))), ) - buildtree = False # Check if we require a pull queue attempt, with given artifact state and context if usebuildtree: if not element._cached_buildtree(): @@ -233,24 +232,19 @@ class Stream: message = "Buildtree is not cached locally" + remotes_message else: message = "Artifact was created without buildtree" - if usebuildtree == "always": - raise StreamError(message) + raise StreamError(message) - self._message(MessageType.WARN, message + ", shell will be loaded without it") - else: - buildtree = True - - # Raise warning if the element is cached in a failed state - if element._cached_failure(): - self._message(MessageType.WARN, "using a buildtree from a failed build.") + # Raise warning if the element is cached in a failed state + if element._cached_failure(): + self._message(MessageType.WARN, "using a buildtree from a failed build.") # Ensure we have our sources if we are launching a build shell - if scope == _Scope.BUILD and not buildtree: + if scope == _Scope.BUILD and not usebuildtree: self._fetch([element]) self._pipeline.assert_sources_cached([element]) return element._shell( - scope, mounts=mounts, isolate=isolate, prompt=prompt(element), command=command, usebuildtree=buildtree + scope, mounts=mounts, isolate=isolate, prompt=prompt(element), command=command, usebuildtree=usebuildtree ) # build() diff --git a/tests/integration/shellbuildtrees.py b/tests/integration/shellbuildtrees.py index f4f13268a..5164c0209 100644 --- a/tests/integration/shellbuildtrees.py +++ b/tests/integration/shellbuildtrees.py @@ -46,7 +46,7 @@ def test_buildtree_staged_forced_true(cli_integration, datafiles): res.assert_success() res = cli_integration.run( - project=project, args=["shell", "--build", "--use-buildtree", "always", element_name, "--", "cat", "test"] + project=project, args=["shell", "--build", "--use-buildtree", element_name, "--", "cat", "test"] ) res.assert_success() assert "Hi" in res.output @@ -67,54 +67,11 @@ def test_buildtree_staged_warn_empty_cached(cli_integration, tmpdir, datafiles): res.assert_success() res = cli_integration.run( - project=project, args=["shell", "--build", "--use-buildtree", "always", element_name, "--", "cat", "test"] + project=project, args=["shell", "--build", "--use-buildtree", element_name, "--", "cat", "test"] ) res.assert_main_error(ErrorDomain.APP, None) assert "Error launching shell: Artifact was created without buildtree" in res.stderr - # Now attempt the same with the try option, this should not attempt to find a buildtree - # and just launch the shell, however the cat should still fail. - res = cli_integration.run( - project=project, args=["shell", "--build", "--use-buildtree", "try", element_name, "--", "cat", "test"] - ) - assert "Artifact was created without buildtree, shell will be loaded without it" in res.stderr - assert "Hi" not in res.output - - -@pytest.mark.datafiles(DATA_DIR) -@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox") -def test_buildtree_staged_if_available(cli_integration, datafiles): - # Test that a build tree can be correctly detected. - project = str(datafiles) - element_name = "build-shell/buildtree.bst" - - res = cli_integration.run(project=project, args=["--cache-buildtrees", "always", "build", element_name]) - res.assert_success() - - res = cli_integration.run( - project=project, args=["shell", "--build", "--use-buildtree", "try", element_name, "--", "cat", "test"] - ) - res.assert_success() - assert "Hi" in res.output - - -@pytest.mark.datafiles(DATA_DIR) -@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox") -def test_buildtree_staged_forced_false(cli_integration, datafiles): - # Test that if we ask not to have a build tree it is not there - project = str(datafiles) - element_name = "build-shell/buildtree.bst" - - res = cli_integration.run(project=project, args=["--cache-buildtrees", "always", "build", element_name]) - res.assert_success() - - res = cli_integration.run( - project=project, args=["shell", "--build", "--use-buildtree", "never", element_name, "--", "cat", "test"] - ) - res.assert_shell_error() - - assert "Hi" not in res.output - @pytest.mark.datafiles(DATA_DIR) @pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox") @@ -128,7 +85,7 @@ def test_buildtree_from_failure(cli_integration, datafiles): # Assert that file has expected contents res = cli_integration.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "cat", "test"] + project=project, args=["shell", "--build", element_name, "--use-buildtree", "--", "cat", "test"] ) res.assert_success() assert "WARNING using a buildtree from a failed build" in res.stderr @@ -150,7 +107,7 @@ def test_buildtree_from_failure_option_never(cli_integration, tmpdir, datafiles) res.assert_main_error(ErrorDomain.STREAM, None) res = cli_integration.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "cat", "test"] + project=project, args=["shell", "--build", element_name, "--use-buildtree", "--", "cat", "test"] ) res.assert_main_error(ErrorDomain.APP, None) assert "Error launching shell: Artifact was created without buildtree" in res.stderr @@ -172,7 +129,7 @@ def test_buildtree_from_failure_option_always(cli_integration, tmpdir, datafiles res.assert_main_error(ErrorDomain.STREAM, None) res = cli_integration.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "cat", "test"] + project=project, args=["shell", "--build", element_name, "--use-buildtree", "--", "cat", "test"] ) res.assert_success() assert "WARNING using a buildtree from a failed build" in res.stderr @@ -206,9 +163,7 @@ def test_buildtree_pulled(cli, tmpdir, datafiles): result.assert_success() # Check it's using the cached build tree - res = cli.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "cat", "test"] - ) + res = cli.run(project=project, args=["shell", "--build", element_name, "--use-buildtree", "--", "cat", "test"]) res.assert_success() @@ -237,9 +192,7 @@ def test_buildtree_options(cli, tmpdir, datafiles): result.assert_success() # Check it's not using the cached build tree - res = cli.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "never", "--", "cat", "test"] - ) + res = cli.run(project=project, args=["shell", "--build", element_name, "--", "cat", "test"]) res.assert_shell_error() assert "Hi" not in res.output @@ -249,17 +202,7 @@ def test_buildtree_options(cli, tmpdir, datafiles): res.assert_shell_error() assert "Hi" not in res.output - # Check correctly handling the lack of buildtree, with 'try' not attempting to - # pull the buildtree as the user context is by default set to not pull them - # and --pull not given - res = cli.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "try", "--", "cat", "test"] - ) - assert "Hi" not in res.output - assert "Attempting to fetch missing artifact buildtrees" not in res.stderr - assert "WARNING Buildtree is not cached locally" in res.stderr - - # Check correctly handling the lack of buildtree, with 'try' attempting and succeeding + # Check correctly handling the lack of buildtree, with '--use-buildtree' attempting and succeeding # to pull the buildtree as the user context allow the pulling of buildtrees and it is # available in the remote and --pull given res = cli.run( @@ -271,7 +214,6 @@ def test_buildtree_options(cli, tmpdir, datafiles): element_name, "--pull", "--use-buildtree", - "try", "--", "cat", "test", @@ -282,19 +224,17 @@ def test_buildtree_options(cli, tmpdir, datafiles): shutil.rmtree(os.path.join(os.path.join(str(tmpdir), "cache", "artifacts"))) assert cli.get_element_state(project, element_name) != "cached" - # Check it's not loading the shell at all with always set for the buildtree, when the + # Check it's not loading the shell at all with `--use-buildtree`, when the # user context does not allow for buildtree pulling and --pull is not given result = cli.run(project=project, args=["artifact", "pull", "--deps", "all", element_name]) result.assert_success() - res = cli.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "cat", "test"] - ) + res = cli.run(project=project, args=["shell", "--build", element_name, "--use-buildtree", "--", "cat", "test"]) res.assert_main_error(ErrorDomain.APP, None) assert "Buildtree is not cached locally" in res.stderr assert "Hi" not in res.output # Check that when user context is set to pull buildtrees and a remote has the buildtree, - # 'always' will attempt and succeed at pulling the missing buildtree with --pull set. + # '--use-buildtree' will attempt and succeed at pulling the missing buildtree with --pull set. res = cli.run( project=project, args=[ @@ -304,7 +244,6 @@ def test_buildtree_options(cli, tmpdir, datafiles): element_name, "--pull", "--use-buildtree", - "always", "--", "cat", "test", @@ -337,7 +276,7 @@ def test_pull_buildtree_pulled(cli, tmpdir, datafiles): # and pull-buildtrees were not both set res = cli.run( project=project, - args=["shell", "--build", element_name, "--pull", "--use-buildtree", "always", "--", "cat", "test",], + args=["shell", "--build", element_name, "--pull", "--use-buildtree", "--", "cat", "test",], ) res.assert_main_error(ErrorDomain.APP, None) assert "Buildtree is not cached locally" in res.stderr @@ -353,7 +292,6 @@ def test_pull_buildtree_pulled(cli, tmpdir, datafiles): element_name, "--pull", "--use-buildtree", - "always", "--", "cat", "test", diff --git a/tests/integration/workspace.py b/tests/integration/workspace.py index a2ea4841a..fab45b123 100644 --- a/tests/integration/workspace.py +++ b/tests/integration/workspace.py @@ -80,7 +80,7 @@ def test_workspace_commanddir(cli, datafiles): # using the cached buildtree. res = cli.run( project=project, - args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "find", "..", "-mindepth", "1",], + args=["shell", "--build", element_name, "--use-buildtree", "--", "find", "..", "-mindepth", "1",], ) res.assert_success() @@ -290,7 +290,7 @@ def test_incremental_configure_commands_run_only_once(cli, datafiles): # the configure should have been run in the sandbox, so check the buildtree res = cli.run( project=project, - args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "find", ".", "-mindepth", "1",], + args=["shell", "--build", element_name, "--use-buildtree", "--", "find", ".", "-mindepth", "1",], ) res.assert_success() @@ -311,7 +311,7 @@ def test_incremental_configure_commands_run_only_once(cli, datafiles): assert not os.path.exists(os.path.join(workspace, "prepared-again")) res = cli.run( project=project, - args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "find", ".", "-mindepth", "1",], + args=["shell", "--build", element_name, "--use-buildtree", "--", "find", ".", "-mindepth", "1",], ) res.assert_success() @@ -382,9 +382,7 @@ def test_workspace_failed_logs(cli, datafiles): def get_buildtree_file_contents(cli, project, element_name, filename): - res = cli.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "cat", filename,], - ) + res = cli.run(project=project, args=["shell", "--build", element_name, "--use-buildtree", "--", "cat", filename,],) res.assert_success() return res.output diff --git a/tests/remoteexecution/buildtree.py b/tests/remoteexecution/buildtree.py index 57e25cd14..317747fe8 100644 --- a/tests/remoteexecution/buildtree.py +++ b/tests/remoteexecution/buildtree.py @@ -63,8 +63,6 @@ def test_buildtree_remote(cli, tmpdir, datafiles): res.assert_success() # check it works this time - res = cli.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "cat", "test"] - ) + res = cli.run(project=project, args=["shell", "--build", element_name, "--use-buildtree", "--", "cat", "test"]) res.assert_success() assert "Hi" in res.output diff --git a/tests/remoteexecution/workspace.py b/tests/remoteexecution/workspace.py index b525cefcd..cf8587230 100644 --- a/tests/remoteexecution/workspace.py +++ b/tests/remoteexecution/workspace.py @@ -115,7 +115,6 @@ def check_buildtree( "--build", element_name, "--use-buildtree", - "always", "--", "find", ".", @@ -176,7 +175,7 @@ def check_buildtree( def get_timemark(cli, project, element_name, marker): result = cli.run( - project=project, args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "cat", marker[1:]], + project=project, args=["shell", "--build", element_name, "--use-buildtree", "--", "cat", marker[1:]], ) result.assert_success() marker_time = int(result.output) |