[Notes] [Git][BuildStream/buildstream][jonathan/workspace-fragment-create] 2 commits: tests: Test bst commands from an external workspace



Title: GitLab

Jonathan Maw pushed to branch jonathan/workspace-fragment-create at BuildStream / buildstream

Commits:

4 changed files:

Changes:

  • NEWS
    ... ... @@ -83,6 +83,10 @@ buildstream 1.3.1
    83 83
         plugin has now a tag tracking feature instead. This can be enabled
    
    84 84
         by setting 'track-tags'.
    
    85 85
     
    
    86
    +  o Opening a workspace now creates a .bstproject.yaml file that allows buildstream
    
    87
    +    commands to be run from a workspace that is not inside a project.
    
    88
    +
    
    89
    +
    
    86 90
     =================
    
    87 91
     buildstream 1.1.5
    
    88 92
     =================
    

  • tests/frontend/cross_junction_workspace.py
    ... ... @@ -115,3 +115,23 @@ def test_close_all_cross_junction(cli, tmpdir):
    115 115
         assert isinstance(loaded.get('workspaces'), list)
    
    116 116
         workspaces = loaded['workspaces']
    
    117 117
         assert len(workspaces) == 0
    
    118
    +
    
    119
    +
    
    120
    +def test_subdir_command_cross_junction(cli, tmpdir):
    
    121
    +    # i.e. commands can be run successfully from a subdirectory of the
    
    122
    +    # junction's workspace, in case project loading logic has gone wrong
    
    123
    +    project = prepare_junction_project(cli, tmpdir)
    
    124
    +    workspace = os.path.join(str(tmpdir), 'workspace')
    
    125
    +    junction_element = 'sub.bst'
    
    126
    +
    
    127
    +    # Open the junction as a workspace
    
    128
    +    args = ['workspace', 'open', '--directory', workspace, junction_element]
    
    129
    +    result = cli.run(project=project, args=args)
    
    130
    +    result.assert_success()
    
    131
    +
    
    132
    +    # Run commands from a subdirectory of the workspace
    
    133
    +    newdir = os.path.join(str(workspace), "newdir")
    
    134
    +    element_name = 'data.bst'
    
    135
    +    os.makedirs(newdir)
    
    136
    +    result = cli.run(project=str(workspace), args=['-C', newdir, 'show', element_name])
    
    137
    +    result.assert_success()

  • tests/frontend/workspace.py
    ... ... @@ -31,6 +31,7 @@ import shutil
    31 31
     import subprocess
    
    32 32
     from ruamel.yaml.comments import CommentedSet
    
    33 33
     from tests.testutils import cli, create_repo, ALL_REPO_KINDS, wait_for_cache_granularity
    
    34
    +from tests.testutils import create_artifact_share
    
    34 35
     
    
    35 36
     from buildstream import _yaml
    
    36 37
     from buildstream._exceptions import ErrorDomain, LoadError, LoadErrorReason
    
    ... ... @@ -615,9 +616,12 @@ def test_list(cli, tmpdir, datafiles):
    615 616
     @pytest.mark.datafiles(DATA_DIR)
    
    616 617
     @pytest.mark.parametrize("kind", repo_kinds)
    
    617 618
     @pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
    
    618
    -def test_build(cli, tmpdir, datafiles, kind, strict):
    
    619
    +@pytest.mark.parametrize("call_from", [("project"), ("workspace")])
    
    620
    +def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
    
    621
    +    tmpdir = tmpdir_factory.mktemp('')
    
    619 622
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
    
    620 623
         checkout = os.path.join(str(tmpdir), 'checkout')
    
    624
    +    args_pre = ['-C', workspace] if call_from == "workspace" else []
    
    621 625
     
    
    622 626
         # Modify workspace
    
    623 627
         shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
    
    ... ... @@ -640,15 +644,14 @@ def test_build(cli, tmpdir, datafiles, kind, strict):
    640 644
         # Build modified workspace
    
    641 645
         assert cli.get_element_state(project, element_name) == 'buildable'
    
    642 646
         assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
    
    643
    -    result = cli.run(project=project, args=['build', element_name])
    
    647
    +    result = cli.run(project=project, args=args_pre + ['build', element_name])
    
    644 648
         result.assert_success()
    
    645 649
         assert cli.get_element_state(project, element_name) == 'cached'
    
    646 650
         assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
    
    647 651
     
    
    648 652
         # Checkout the result
    
    649
    -    result = cli.run(project=project, args=[
    
    650
    -        'checkout', element_name, checkout
    
    651
    -    ])
    
    653
    +    result = cli.run(project=project,
    
    654
    +                     args=args_pre + ['checkout', element_name, checkout])
    
    652 655
         result.assert_success()
    
    653 656
     
    
    654 657
         # Check that the pony.conf from the modified workspace exists
    
    ... ... @@ -1055,3 +1058,137 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles):
    1055 1058
             result = cli.run(project=project, args=["build", element_name])
    
    1056 1059
             assert "BUG" not in result.stderr
    
    1057 1060
             assert cli.get_element_state(project, element_name) != "cached"
    
    1061
    +
    
    1062
    +
    
    1063
    +@pytest.mark.datafiles(DATA_DIR)
    
    1064
    +@pytest.mark.parametrize('subdir', [True, False], ids=["subdir", "no-subdir"])
    
    1065
    +def test_external_fetch(cli, datafiles, tmpdir_factory, subdir):
    
    1066
    +    # Fetching from a workspace outside a project doesn't fail horribly
    
    1067
    +    tmpdir = tmpdir_factory.mktemp('')
    
    1068
    +    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1069
    +
    
    1070
    +    if subdir:
    
    1071
    +        call_dir = os.path.join(workspace, 'usr')
    
    1072
    +    else:
    
    1073
    +        call_dir = workspace
    
    1074
    +
    
    1075
    +    result = cli.run(project=project, args=['-C', call_dir, 'fetch', element_name])
    
    1076
    +    result.assert_success()
    
    1077
    +
    
    1078
    +    # We already fetched it by opening the workspace, but we're also checking
    
    1079
    +    # `bst show` works here
    
    1080
    +    assert cli.get_element_state(project, element_name) == 'buildable'
    
    1081
    +
    
    1082
    +
    
    1083
    +@pytest.mark.datafiles(DATA_DIR)
    
    1084
    +def test_external_push_pull(cli, datafiles, tmpdir_factory):
    
    1085
    +    # Pushing and pulling to/from an artifact cache works from an external workspace
    
    1086
    +    tmpdir = tmpdir_factory.mktemp('')
    
    1087
    +    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1088
    +
    
    1089
    +    with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
    
    1090
    +        result = cli.run(project=project, args=['-C', workspace, 'build', element_name])
    
    1091
    +        result.assert_success()
    
    1092
    +
    
    1093
    +        cli.configure({
    
    1094
    +            'artifacts': {'url': share.repo, 'push': True}
    
    1095
    +        })
    
    1096
    +
    
    1097
    +        result = cli.run(project=project, args=['-C', workspace, 'push', element_name])
    
    1098
    +        result.assert_success()
    
    1099
    +
    
    1100
    +        result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all', element_name])
    
    1101
    +        result.assert_success()
    
    1102
    +
    
    1103
    +
    
    1104
    +@pytest.mark.datafiles(DATA_DIR)
    
    1105
    +def test_external_track(cli, datafiles, tmpdir_factory):
    
    1106
    +    # Tracking does not get horribly confused
    
    1107
    +    tmpdir = tmpdir_factory.mktemp('')
    
    1108
    +    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
    
    1109
    +
    
    1110
    +    # The workspace is necessarily already tracked, so we only care that
    
    1111
    +    # there's no weird errors.
    
    1112
    +    result = cli.run(project=project, args=['-C', workspace, 'track', element_name])
    
    1113
    +    result.assert_success()
    
    1114
    +
    
    1115
    +
    
    1116
    +@pytest.mark.datafiles(DATA_DIR)
    
    1117
    +def test_external_open_other(cli, datafiles, tmpdir_factory):
    
    1118
    +    # >From inside an external workspace, open another workspace
    
    1119
    +    tmpdir1 = tmpdir_factory.mktemp('')
    
    1120
    +    tmpdir2 = tmpdir_factory.mktemp('')
    
    1121
    +    # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    1122
    +    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
    
    1123
    +    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
    
    1124
    +
    
    1125
    +    # Closing the other element first, because I'm too lazy to create an
    
    1126
    +    # element without opening it
    
    1127
    +    result = cli.run(project=project, args=['workspace', 'close', beta_element])
    
    1128
    +    result.assert_success()
    
    1129
    +
    
    1130
    +    result = cli.run(project=project, args=[
    
    1131
    +        '-C', alpha_workspace, 'workspace', 'open', '--force', '--directory', beta_workspace, beta_element
    
    1132
    +    ])
    
    1133
    +    result.assert_success()
    
    1134
    +
    
    1135
    +
    
    1136
    +@pytest.mark.datafiles(DATA_DIR)
    
    1137
    +def test_external_close_other(cli, datafiles, tmpdir_factory):
    
    1138
    +    # >From inside an external workspace, close the other workspace
    
    1139
    +    tmpdir1 = tmpdir_factory.mktemp('')
    
    1140
    +    tmpdir2 = tmpdir_factory.mktemp('')
    
    1141
    +    # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    1142
    +    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
    
    1143
    +    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
    
    1144
    +
    
    1145
    +    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', beta_element])
    
    1146
    +    result.assert_success()
    
    1147
    +
    
    1148
    +
    
    1149
    +@pytest.mark.datafiles(DATA_DIR)
    
    1150
    +def test_external_close_self(cli, datafiles, tmpdir_factory):
    
    1151
    +    # >From inside an external workspace, close it
    
    1152
    +    tmpdir1 = tmpdir_factory.mktemp('')
    
    1153
    +    tmpdir2 = tmpdir_factory.mktemp('')
    
    1154
    +    # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    1155
    +    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
    
    1156
    +    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
    
    1157
    +
    
    1158
    +    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', alpha_element])
    
    1159
    +    result.assert_success()
    
    1160
    +
    
    1161
    +
    
    1162
    +@pytest.mark.datafiles(DATA_DIR)
    
    1163
    +def test_external_reset_other(cli, datafiles, tmpdir_factory):
    
    1164
    +    tmpdir1 = tmpdir_factory.mktemp('')
    
    1165
    +    tmpdir2 = tmpdir_factory.mktemp('')
    
    1166
    +    # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    1167
    +    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
    
    1168
    +    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
    
    1169
    +
    
    1170
    +    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'reset', beta_element])
    
    1171
    +    result.assert_success()
    
    1172
    +
    
    1173
    +
    
    1174
    +@pytest.mark.datafiles(DATA_DIR)
    
    1175
    +def test_external_reset_self(cli, datafiles, tmpdir):
    
    1176
    +    element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1177
    +
    
    1178
    +    # Command succeeds
    
    1179
    +    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset', element])
    
    1180
    +    result.assert_success()
    
    1181
    +
    
    1182
    +    # Successive commands still work (i.e. .bstproject.yaml hasn't been deleted)
    
    1183
    +    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
    
    1184
    +    result.assert_success()
    
    1185
    +
    
    1186
    +
    
    1187
    +@pytest.mark.datafiles(DATA_DIR)
    
    1188
    +def test_external_list(cli, datafiles, tmpdir_factory):
    
    1189
    +    tmpdir = tmpdir_factory.mktemp('')
    
    1190
    +    # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    1191
    +    element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1192
    +
    
    1193
    +    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
    
    1194
    +    result.assert_success()

  • tests/integration/shell.py
    ... ... @@ -353,3 +353,29 @@ def test_integration_devices(cli, tmpdir, datafiles):
    353 353
     
    
    354 354
         result = execute_shell(cli, project, ["true"], element=element_name)
    
    355 355
         assert result.exit_code == 0
    
    356
    +
    
    357
    +
    
    358
    +# Test that a shell can be opened from an external workspace
    
    359
    +@pytest.mark.datafiles(DATA_DIR)
    
    360
    +@pytest.mark.parametrize("build_shell", [("build"), ("nobuild")])
    
    361
    +@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
    
    362
    +def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell):
    
    363
    +    tmpdir = tmpdir_factory.mktemp("")
    
    364
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    365
    +    element_name = 'autotools/amhello.bst'
    
    366
    +    workspace_dir = os.path.join(str(tmpdir), 'workspace')
    
    367
    +
    
    368
    +    result = cli.run(project=project, args=[
    
    369
    +        'workspace', 'open', '--directory', workspace_dir, element_name
    
    370
    +    ])
    
    371
    +    result.assert_success()
    
    372
    +
    
    373
    +    result = cli.run(project=project, args=['-C', workspace_dir, 'build', element_name])
    
    374
    +    result.assert_success()
    
    375
    +
    
    376
    +    command = ['shell']
    
    377
    +    if build_shell == 'build':
    
    378
    +        command.append('--build')
    
    379
    +    command.extend([element_name, '--', 'true'])
    
    380
    +    result = cli.run(project=project, cwd=workspace_dir, args=command)
    
    381
    +    result.assert_success()



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]