[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:

3 changed files:

Changes:

  • NEWS
    ... ... @@ -63,6 +63,9 @@ buildstream 1.3.1
    63 63
     
    
    64 64
       o Added new `bst source-checkout` command to checkout sources of an element.
    
    65 65
     
    
    66
    +  o Opening a workspace now creates a .bstproject.yaml file that allows buildstream
    
    67
    +    commands to be run from a workspace that is not inside a project.
    
    68
    +
    
    66 69
     
    
    67 70
     =================
    
    68 71
     buildstream 1.1.5
    

  • tests/frontend/workspace.py
    ... ... @@ -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,131 @@ 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
    +def test_external_close_self(cli, datafiles, tmpdir_factory):
    
    977
    +    # From inside an external workspace, close it
    
    978
    +    tmpdir1 = tmpdir_factory.mktemp('')
    
    979
    +    tmpdir2 = tmpdir_factory.mktemp('')
    
    980
    +    # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    981
    +    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
    
    982
    +    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
    
    983
    +
    
    984
    +    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', alpha_element])
    
    985
    +    result.assert_success()
    
    986
    +
    
    987
    +
    
    988
    +@pytest.mark.datafiles(DATA_DIR)
    
    989
    +def test_external_reset_other(cli, datafiles, tmpdir_factory):
    
    990
    +    tmpdir1 = tmpdir_factory.mktemp('')
    
    991
    +    tmpdir2 = tmpdir_factory.mktemp('')
    
    992
    +    # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    993
    +    alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
    
    994
    +    beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
    
    995
    +
    
    996
    +    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'reset', beta_element])
    
    997
    +    result.assert_success()
    
    998
    +
    
    999
    +
    
    1000
    +@pytest.mark.datafiles(DATA_DIR)
    
    1001
    +def test_external_reset_self(cli, datafiles, tmpdir):
    
    1002
    +    element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1003
    +
    
    1004
    +    # Command succeeds
    
    1005
    +    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset', element])
    
    1006
    +    result.assert_success()
    
    1007
    +
    
    1008
    +    # Successive commands still work (i.e. .bstproject.yaml hasn't been deleted)
    
    1009
    +    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
    
    1010
    +    result.assert_success()
    
    1011
    +
    
    1012
    +
    
    1013
    +@pytest.mark.datafiles(DATA_DIR)
    
    1014
    +def test_external_list(cli, datafiles, tmpdir_factory):
    
    1015
    +    tmpdir = tmpdir_factory.mktemp('')
    
    1016
    +    # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    1017
    +    element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1018
    +
    
    1019
    +    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
    
    1020
    +    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', element_name, workspace_dir
    
    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]