... |
... |
@@ -29,6 +29,7 @@ import shutil |
29
|
29
|
import subprocess
|
30
|
30
|
from ruamel.yaml.comments import CommentedSet
|
31
|
31
|
from tests.testutils import cli, create_repo, ALL_REPO_KINDS, wait_for_cache_granularity
|
|
32
|
+from tests.testutils import create_artifact_share
|
32
|
33
|
|
33
|
34
|
from buildstream import _yaml
|
34
|
35
|
from buildstream._exceptions import ErrorDomain, LoadError, LoadErrorReason
|
... |
... |
@@ -447,9 +448,12 @@ def test_list(cli, tmpdir, datafiles): |
447
|
448
|
@pytest.mark.datafiles(DATA_DIR)
|
448
|
449
|
@pytest.mark.parametrize("kind", repo_kinds)
|
449
|
450
|
@pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
|
450
|
|
-def test_build(cli, tmpdir, datafiles, kind, strict):
|
|
451
|
+@pytest.mark.parametrize("call_from", [("project"), ("workspace")])
|
|
452
|
+def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
|
|
453
|
+ tmpdir = tmpdir_factory.mktemp('')
|
451
|
454
|
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
|
452
|
455
|
checkout = os.path.join(str(tmpdir), 'checkout')
|
|
456
|
+ args_pre = ['-C', workspace] if call_from == "project" else []
|
453
|
457
|
|
454
|
458
|
# Modify workspace
|
455
|
459
|
shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
|
... |
... |
@@ -472,15 +476,14 @@ def test_build(cli, tmpdir, datafiles, kind, strict): |
472
|
476
|
# Build modified workspace
|
473
|
477
|
assert cli.get_element_state(project, element_name) == 'buildable'
|
474
|
478
|
assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
|
475
|
|
- result = cli.run(project=project, args=['build', element_name])
|
|
479
|
+ result = cli.run(project=project, args=args_pre + ['build', element_name])
|
476
|
480
|
result.assert_success()
|
477
|
481
|
assert cli.get_element_state(project, element_name) == 'cached'
|
478
|
482
|
assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
|
479
|
483
|
|
480
|
484
|
# Checkout the result
|
481
|
|
- result = cli.run(project=project, args=[
|
482
|
|
- 'checkout', element_name, checkout
|
483
|
|
- ])
|
|
485
|
+ result = cli.run(project=project,
|
|
486
|
+ args=args_pre + ['checkout', element_name, checkout])
|
484
|
487
|
result.assert_success()
|
485
|
488
|
|
486
|
489
|
# Check that the pony.conf from the modified workspace exists
|
... |
... |
@@ -887,3 +890,129 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles): |
887
|
890
|
result = cli.run(project=project, args=["build", element_name])
|
888
|
891
|
assert "BUG" not in result.stderr
|
889
|
892
|
assert cli.get_element_state(project, element_name) != "cached"
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
896
|
+def test_external_fetch(cli, datafiles, tmpdir_factory):
|
|
897
|
+ # Fetching from a workspace outside a project doesn't fail horribly
|
|
898
|
+ tmpdir = tmpdir_factory.mktemp('')
|
|
899
|
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
|
900
|
+
|
|
901
|
+ result = cli.run(project=project, args=['-C', workspace, 'fetch', element_name])
|
|
902
|
+ result.assert_success()
|
|
903
|
+
|
|
904
|
+ # We already fetched it by opening the workspace, but we're also checking
|
|
905
|
+ # `bst show` works here
|
|
906
|
+ assert cli.get_element_state(project, element_name) == 'buildable'
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
910
|
+def test_external_push_pull(cli, datafiles, tmpdir_factory):
|
|
911
|
+ # Pushing and pulling to/from an artifact cache works from an external workspace
|
|
912
|
+ tmpdir = tmpdir_factory.mktemp('')
|
|
913
|
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
|
914
|
+
|
|
915
|
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
|
|
916
|
+ result = cli.run(project=project, args=['-C', workspace, 'build', element_name])
|
|
917
|
+ result.assert_success()
|
|
918
|
+
|
|
919
|
+ cli.configure({
|
|
920
|
+ 'artifacts': {'url': share.repo, 'push': True}
|
|
921
|
+ })
|
|
922
|
+
|
|
923
|
+ result = cli.run(project=project, args=['-C', workspace, 'push', element_name])
|
|
924
|
+ result.assert_success()
|
|
925
|
+
|
|
926
|
+ result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all', 'target.bst'])
|
|
927
|
+ result.assert_success()
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
931
|
+def test_external_track(cli, datafiles, tmpdir_factory):
|
|
932
|
+ # Tracking does not get horribly confused
|
|
933
|
+ tmpdir = tmpdir_factory.mktemp('')
|
|
934
|
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
|
|
935
|
+
|
|
936
|
+ # The workspace is necessarily already tracked, so we only care that
|
|
937
|
+ # there's no weird errors.
|
|
938
|
+ result = cli.run(project=project, args=['-C', workspace, 'track', element_name])
|
|
939
|
+ result.assert_success()
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
943
|
+def test_external_open_other(cli, datafiles, tmpdir_factory):
|
|
944
|
+ # From inside an external workspace, open another workspace
|
|
945
|
+ tmpdir1 = tmpdir_factory.mktemp('')
|
|
946
|
+ tmpdir2 = tmpdir_factory.mktemp('')
|
|
947
|
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
948
|
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
|
|
949
|
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
|
|
950
|
+
|
|
951
|
+ # Closing the other element first, because I'm too lazy to create an
|
|
952
|
+ # element without opening it
|
|
953
|
+ result = cli.run(project=project, args=['workspace', 'close', beta_element])
|
|
954
|
+ result.assert_success()
|
|
955
|
+
|
|
956
|
+ result = cli.run(project=project, args=[
|
|
957
|
+ '-C', alpha_workspace, 'workspace', 'open', '--force', beta_element, beta_workspace
|
|
958
|
+ ])
|
|
959
|
+ result.assert_success()
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
963
|
+def test_external_close_other(cli, datafiles, tmpdir_factory):
|
|
964
|
+ # From inside an external workspace, close the other workspace
|
|
965
|
+ tmpdir1 = tmpdir_factory.mktemp('')
|
|
966
|
+ tmpdir2 = tmpdir_factory.mktemp('')
|
|
967
|
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
968
|
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
|
|
969
|
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
|
|
970
|
+
|
|
971
|
+ result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', beta_element])
|
|
972
|
+ result.assert_success()
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
976
|
+@pytest.mark.parametrize("force", [("force"), ("no-force")])
|
|
977
|
+def test_external_close_self(cli, datafiles, tmpdir_factory, force):
|
|
978
|
+ # From inside an external workspace, close it
|
|
979
|
+ # This is unwise, so is only allowed if --force
|
|
980
|
+ tmpdir1 = tmpdir_factory.mktemp('')
|
|
981
|
+ tmpdir2 = tmpdir_factory.mktemp('')
|
|
982
|
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
983
|
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
|
|
984
|
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
|
|
985
|
+
|
|
986
|
+ args = ['-C', alpha_workspace, 'workspace', 'close']
|
|
987
|
+ if force == "force":
|
|
988
|
+ args.append('--force')
|
|
989
|
+ args.append(alpha_element)
|
|
990
|
+
|
|
991
|
+ result = cli.run(project=project, args=args)
|
|
992
|
+ if force == "force":
|
|
993
|
+ result.assert_success()
|
|
994
|
+ else:
|
|
995
|
+ # TODO: Proper error domain and reason
|
|
996
|
+ result.assert_main_error(ErrorDomain.APP, 'closing-required-workspace')
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
1000
|
+def test_external_reset_other(cli, datafiles, tmpdir_factory):
|
|
1001
|
+ tmpdir1 = tmpdir_factory.mktemp('')
|
|
1002
|
+ tmpdir2 = tmpdir_factory.mktemp('')
|
|
1003
|
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
1004
|
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
|
|
1005
|
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
|
|
1006
|
+
|
|
1007
|
+ result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'reset', beta_element])
|
|
1008
|
+ result.assert_success()
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
1012
|
+def test_external_list(cli, datafiles, tmpdir_factory):
|
|
1013
|
+ tmpdir = tmpdir_factory.mktemp('')
|
|
1014
|
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
|
|
1015
|
+ element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
|
|
1016
|
+
|
|
1017
|
+ result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
|
|
1018
|
+ result.assert_success()
|