Skip to content
Snippets Groups Projects
Commit 4ee156ac authored by Jonathan Maw's avatar Jonathan Maw
Browse files

tests: Test bst commands from an external workspace

parent 3e0234f2
No related branches found
No related tags found
No related merge requests found
Pipeline #36578094 passed
......@@ -29,6 +29,7 @@ import shutil
import subprocess
from ruamel.yaml.comments import CommentedSet
from tests.testutils import cli, create_repo, ALL_REPO_KINDS, wait_for_cache_granularity
from tests.testutils import create_artifact_share
from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadError, LoadErrorReason
......@@ -447,9 +448,12 @@ def test_list(cli, tmpdir, datafiles):
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("kind", repo_kinds)
@pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
def test_build(cli, tmpdir, datafiles, kind, strict):
@pytest.mark.parametrize("call_from", [("project"), ("workspace")])
def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
tmpdir = tmpdir_factory.mktemp('')
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
checkout = os.path.join(str(tmpdir), 'checkout')
args_pre = ['-C', workspace] if call_from == "project" else []
# Modify workspace
shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
......@@ -472,15 +476,14 @@ def test_build(cli, tmpdir, datafiles, kind, strict):
# Build modified workspace
assert cli.get_element_state(project, element_name) == 'buildable'
assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
result = cli.run(project=project, args=['build', element_name])
result = cli.run(project=project, args=args_pre + ['build', element_name])
result.assert_success()
assert cli.get_element_state(project, element_name) == 'cached'
assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
# Checkout the result
result = cli.run(project=project, args=[
'checkout', element_name, checkout
])
result = cli.run(project=project,
args=args_pre + ['checkout', element_name, checkout])
result.assert_success()
# Check that the pony.conf from the modified workspace exists
......@@ -887,3 +890,128 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles):
result = cli.run(project=project, args=["build", element_name])
assert "BUG" not in result.stderr
assert cli.get_element_state(project, element_name) != "cached"
@pytest.mark.datafiles(DATA_DIR)
def test_external_fetch(cli, datafiles, tmpdir_factory):
# Fetching from a workspace outside a project doesn't fail horribly
tmpdir = tmpdir_factory.mktemp('')
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
result = cli.run(project=project, args=['-C', workspace, 'fetch', element_name])
result.assert_success()
# We already fetched it by opening the workspace, but we're also checking
# `bst show` works here
assert cli.get_element_state(project, element_name) == 'buildable'
@pytest.mark.datafiles(DATA_DIR)
def test_external_push_pull(cli, datafiles, tmpdir_factory):
# Pushing and pulling to/from an artifact cache works from an external workspace
tmpdir = tmpdir_factory.mktemp('')
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
result = cli.run(project=project, args=['-C', workspace, 'build', element_name])
result.assert_success()
cli.configure({
'artifacts': {'url': share.repo, 'push': True}
})
result = cli.run(project=project, args=['-C', workspace, 'push', element_name])
result.assert_success()
result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all', 'target.bst'])
result.assert_success()
@pytest.mark.datafiles(DATA_DIR)
def test_external_track(cli, datafiles, tmpdir_factory):
# Tracking does not get horribly confused
tmpdir = tmpdir_factory.mktemp('')
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
# The workspace is necessarily already tracked, so we only care that
# there's no weird errors.
result = cli.run(project=project, args=['-C', workspace, 'track', element_name])
result.assert_success()
@pytest.mark.datafiles(DATA_DIR)
def test_external_open_other(cli, datafiles, tmpdir_factory):
# From inside an external workspace, open another workspace
tmpdir1 = tmpdir_factory.mktemp('')
tmpdir2 = tmpdir_factory.mktemp('')
# Making use of the assumption that it's the same project in both invocations of open_workspace
alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
# Closing the other element first, because I'm too lazy to create an
# element without opening it
result = cli.run(project=project, args=['workspace', 'close', beta_element])
result.assert_success()
result = cli.run(project=project, args=[
'-C', alpha_workspace, 'workspace', 'open', '--force', beta_element, beta_workspace
])
result.assert_success()
@pytest.mark.datafiles(DATA_DIR)
def test_external_close_other(cli, datafiles, tmpdir_factory):
# From inside an external workspace, close the other workspace
tmpdir1 = tmpdir_factory.mktemp('')
tmpdir2 = tmpdir_factory.mktemp('')
# Making use of the assumption that it's the same project in both invocations of open_workspace
alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', beta_element])
result.assert_success()
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("force", [("force"), ("no-force")])
def test_external_close_self(cli, datafiles, tmpdir_factory, force):
# From inside an external workspace, close it
# This is unwise, so is only allowed if --force
tmpdir1 = tmpdir_factory.mktemp('')
tmpdir2 = tmpdir_factory.mktemp('')
# Making use of the assumption that it's the same project in both invocations of open_workspace
alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
args = ['-C', alpha_workspace, 'workspace', 'close']
if force == "force":
args.append('--force')
args.append(alpha_element)
result = cli.run(project=project, args=args)
if force == "force":
result.assert_success()
else:
result.assert_main_error(ErrorDomain.APP, 'closing-required-workspace')
@pytest.mark.datafiles(DATA_DIR)
def test_external_reset_other(cli, datafiles, tmpdir_factory):
tmpdir1 = tmpdir_factory.mktemp('')
tmpdir2 = tmpdir_factory.mktemp('')
# Making use of the assumption that it's the same project in both invocations of open_workspace
alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'reset', beta_element])
result.assert_success()
@pytest.mark.datafiles(DATA_DIR)
def test_external_list(cli, datafiles, tmpdir_factory):
tmpdir = tmpdir_factory.mktemp('')
# Making use of the assumption that it's the same project in both invocations of open_workspace
element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
result.assert_success()
......@@ -339,3 +339,28 @@ def test_integration_devices(cli, tmpdir, datafiles):
result = execute_shell(cli, project, ["true"], element=element_name)
assert result.exit_code == 0
# Test that a shell can be opened from an external workspace
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("build_shell", [("build"), ("nobuild")])
def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell):
tmpdir = tmpdir_factory.mktemp("")
project = os.path.join(datafiles.dirname, datafiles.basename)
element_name = 'autotools/amhello.bst'
workspace_dir = os.path.join(str(tmpdir), 'workspace')
result = cli.run(project=project, args=[
'workspace', 'open', element_name, workspace_dir
])
result.assert_success()
result = cli.run(project=project, args=['-C', workspace_dir, 'build', element_name])
result.assert_success()
command = ['shell']
if build_shell == 'build':
command.append('--build')
command.extend([element_name, '--', 'true'])
result = cli.run(project=project, cwd=workspace_dir, args=command)
result.assert_success()
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