[Notes] [Git][BuildStream/buildstream][willsalmon/defaultWorkspaces] 3 commits: Workspace CLI update



Title: GitLab

Will Salmon pushed to branch willsalmon/defaultWorkspaces at BuildStream / buildstream

Commits:

12 changed files:

Changes:

  • buildstream/_context.py
    ... ... @@ -60,6 +60,9 @@ class Context():
    60 60
             # The directory where build sandboxes will be created
    
    61 61
             self.builddir = None
    
    62 62
     
    
    63
    +        # Default root location for workspaces
    
    64
    +        self.workspacedir = None
    
    65
    +
    
    63 66
             # The local binary artifact cache directory
    
    64 67
             self.artifactdir = None
    
    65 68
     
    
    ... ... @@ -161,10 +164,10 @@ class Context():
    161 164
             _yaml.node_validate(defaults, [
    
    162 165
                 'sourcedir', 'builddir', 'artifactdir', 'logdir',
    
    163 166
                 'scheduler', 'artifacts', 'logging', 'projects',
    
    164
    -            'cache'
    
    167
    +            'cache', 'workspacedir',
    
    165 168
             ])
    
    166 169
     
    
    167
    -        for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir']:
    
    170
    +        for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir', 'workspacedir']:
    
    168 171
                 # Allow the ~ tilde expansion and any environment variables in
    
    169 172
                 # path specification in the config files.
    
    170 173
                 #
    

  • buildstream/_frontend/cli.py
    ... ... @@ -678,28 +678,35 @@ def workspace():
    678 678
     @click.option('--no-checkout', default=False, is_flag=True,
    
    679 679
                   help="Do not checkout the source, only link to the given directory")
    
    680 680
     @click.option('--force', '-f', default=False, is_flag=True,
    
    681
    -              help="Overwrite files existing in checkout directory")
    
    681
    +              help="Overwrite files existing in checkout directory and allow workspace to be created if on exists")
    
    682 682
     @click.option('--track', 'track_', default=False, is_flag=True,
    
    683 683
                   help="Track and fetch new source references before checking out the workspace")
    
    684
    -@click.argument('element',
    
    684
    +@click.option('--directory', type=click.Path(file_okay=False), default=None)
    
    685
    +@click.argument('elements', nargs=-1,
    
    685 686
                     type=click.Path(readable=False))
    
    686
    -@click.argument('directory', type=click.Path(file_okay=False))
    
    687 687
     @click.pass_obj
    
    688
    -def workspace_open(app, no_checkout, force, track_, element, directory):
    
    688
    +def workspace_open(app, no_checkout, force, track_, directory, elements):
    
    689 689
         """Open a workspace for manual source modification"""
    
    690
    -
    
    691
    -    if os.path.exists(directory):
    
    692
    -
    
    693
    -        if not os.path.isdir(directory):
    
    694
    -            click.echo("Checkout directory is not a directory: {}".format(directory), err=True)
    
    690
    +    directories = []
    
    691
    +    if directory is not None:
    
    692
    +        if len(elements) > 1:
    
    693
    +            click.echo("Directory option can only be used if a single element is given", err=True)
    
    695 694
                 sys.exit(-1)
    
    695
    +        if os.path.exists(directory):
    
    696
    +            if not os.path.isdir(directory):
    
    697
    +                click.echo("Checkout directory is not a directory: {}".format(directory), err=True)
    
    698
    +                sys.exit(-1)
    
    696 699
     
    
    697
    -        if not (no_checkout or force) and os.listdir(directory):
    
    698
    -            click.echo("Checkout directory is not empty: {}".format(directory), err=True)
    
    699
    -            sys.exit(-1)
    
    700
    +            if not (no_checkout or force) and os.listdir(directory):
    
    701
    +                click.echo("Checkout directory is not empty: {}".format(directory), err=True)
    
    702
    +                sys.exit(-1)
    
    703
    +        directories.append(directory)
    
    704
    +    else:
    
    705
    +        for element in elements:
    
    706
    +            directories.append(element.rstrip('.bst'))
    
    700 707
     
    
    701 708
         with app.initialized():
    
    702
    -        app.stream.workspace_open(element, directory,
    
    709
    +        app.stream.workspace_open(elements, directories,
    
    703 710
                                       no_checkout=no_checkout,
    
    704 711
                                       track_first=track_,
    
    705 712
                                       force=force)
    

  • buildstream/_stream.py
    ... ... @@ -447,67 +447,70 @@ class Stream():
    447 447
         #    track_first (bool): Whether to track and fetch first
    
    448 448
         #    force (bool): Whether to ignore contents in an existing directory
    
    449 449
         #
    
    450
    -    def workspace_open(self, target, directory, *,
    
    450
    +    def workspace_open(self, targets, directories, *,
    
    451 451
                            no_checkout,
    
    452 452
                            track_first,
    
    453 453
                            force):
    
    454 454
     
    
    455 455
             if track_first:
    
    456
    -            track_targets = (target,)
    
    456
    +            track_targets = targets
    
    457 457
             else:
    
    458 458
                 track_targets = ()
    
    459 459
     
    
    460
    -        elements, track_elements = self._load((target,), track_targets,
    
    460
    +        elements, track_elements = self._load(targets, track_targets,
    
    461 461
                                                   selection=PipelineSelection.REDIRECT,
    
    462 462
                                                   track_selection=PipelineSelection.REDIRECT)
    
    463
    -        target = elements[0]
    
    464
    -        directory = os.path.abspath(directory)
    
    465
    -
    
    466
    -        if not list(target.sources()):
    
    467
    -            build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)]
    
    468
    -            if not build_depends:
    
    469
    -                raise StreamError("The given element has no sources")
    
    470
    -            detail = "Try opening a workspace on one of its dependencies instead:\n"
    
    471
    -            detail += "  \n".join(build_depends)
    
    472
    -            raise StreamError("The given element has no sources", detail=detail)
    
    473
    -
    
    474
    -        workspaces = self._context.get_workspaces()
    
    475
    -
    
    476
    -        # Check for workspace config
    
    477
    -        workspace = workspaces.get_workspace(target._get_full_name())
    
    478
    -        if workspace and not force:
    
    479
    -            raise StreamError("Workspace '{}' is already defined at: {}"
    
    480
    -                              .format(target.name, workspace.get_absolute_path()))
    
    481 463
     
    
    482
    -        # If we're going to checkout, we need at least a fetch,
    
    483
    -        # if we were asked to track first, we're going to fetch anyway.
    
    484
    -        #
    
    485
    -        if not no_checkout or track_first:
    
    486
    -            track_elements = []
    
    487
    -            if track_first:
    
    488
    -                track_elements = elements
    
    489
    -            self._fetch(elements, track_elements=track_elements)
    
    464
    +        for target, directory in zip(elements, directories):
    
    465
    +            if not os.path.isabs(directory):
    
    466
    +                directory = os.path.abspath(os.path.join(self._context.workspacedir, directory))
    
    467
    +
    
    468
    +            if not list(target.sources()):
    
    469
    +                build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)]
    
    470
    +                if not build_depends:
    
    471
    +                    raise StreamError("The given element has no sources")
    
    472
    +                detail = "Try opening a workspace on one of its dependencies instead:\n"
    
    473
    +                detail += "  \n".join(build_depends)
    
    474
    +                raise StreamError("The given element has no sources", detail=detail)
    
    475
    +
    
    476
    +            workspaces = self._context.get_workspaces()
    
    477
    +
    
    478
    +            # Check for workspace config
    
    479
    +            workspace = workspaces.get_workspace(target._get_full_name())
    
    480
    +            if workspace and not force:
    
    481
    +                raise StreamError("Workspace '{}' is already defined at: {}"
    
    482
    +                                  .format(target.name, workspace.get_absolute_path()))
    
    483
    +
    
    484
    +            # If we're going to checkout, we need at least a fetch,
    
    485
    +            # if we were asked to track first, we're going to fetch anyway.
    
    486
    +            #
    
    487
    +            if not no_checkout or track_first:
    
    488
    +                track_elements = []
    
    489
    +                if track_first:
    
    490
    +                    track_elements = elements
    
    491
    +                self._fetch(elements, track_elements=track_elements)
    
    492
    +
    
    493
    +            if not no_checkout and target._get_consistency() != Consistency.CACHED:
    
    494
    +                raise StreamError("Could not stage uncached source. " +
    
    495
    +                                  "Use `--track` to track and " +
    
    496
    +                                  "fetch the latest version of the " +
    
    497
    +                                  "source.")
    
    490 498
     
    
    491
    -        if not no_checkout and target._get_consistency() != Consistency.CACHED:
    
    492
    -            raise StreamError("Could not stage uncached source. " +
    
    493
    -                              "Use `--track` to track and " +
    
    494
    -                              "fetch the latest version of the " +
    
    495
    -                              "source.")
    
    496
    -
    
    497
    -        if workspace:
    
    498
    -            workspaces.delete_workspace(target._get_full_name())
    
    499
    -            workspaces.save_config()
    
    500
    -            shutil.rmtree(directory)
    
    501
    -        try:
    
    502
    -            os.makedirs(directory, exist_ok=True)
    
    503
    -        except OSError as e:
    
    504
    -            raise StreamError("Failed to create workspace directory: {}".format(e)) from e
    
    499
    +            if workspace:
    
    500
    +                workspaces.delete_workspace(target._get_full_name())
    
    501
    +                workspaces.save_config()
    
    502
    +                shutil.rmtree(directory)
    
    503
    +            try:
    
    504
    +                os.makedirs(directory, exist_ok=True)
    
    505
    +            except OSError as e:
    
    506
    +                 # should we try to make this more attomic?
    
    507
    +                raise StreamError("Failed to create workspace directory: {}".format(e)) from e
    
    505 508
     
    
    506
    -        workspaces.create_workspace(target._get_full_name(), directory)
    
    509
    +            workspaces.create_workspace(target._get_full_name(), directory)
    
    507 510
     
    
    508
    -        if not no_checkout:
    
    509
    -            with target.timed_activity("Staging sources to {}".format(directory)):
    
    510
    -                target._open_workspace()
    
    511
    +            if not no_checkout:
    
    512
    +                with target.timed_activity("Staging sources to {}".format(directory)):
    
    513
    +                    target._open_workspace()
    
    511 514
     
    
    512 515
             workspaces.save_config()
    
    513 516
             self._message(MessageType.INFO, "Saved workspace configuration")
    

  • buildstream/data/userconfig.yaml
    ... ... @@ -22,6 +22,9 @@ artifactdir: ${XDG_CACHE_HOME}/buildstream/artifacts
    22 22
     # Location to store build logs
    
    23 23
     logdir: ${XDG_CACHE_HOME}/buildstream/logs
    
    24 24
     
    
    25
    +# Default root location for workspacesi, blank for no default set.
    
    26
    +workspacedir: .
    
    27
    +
    
    25 28
     #
    
    26 29
     #    Cache
    
    27 30
     #
    

  • tests/examples/developing.py
    ... ... @@ -55,7 +55,7 @@ def test_open_workspace(cli, tmpdir, datafiles):
    55 55
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    56 56
         workspace_dir = os.path.join(str(tmpdir), "workspace_hello")
    
    57 57
     
    
    58
    -    result = cli.run(project=project, args=['workspace', 'open', '-f', 'hello.bst', workspace_dir])
    
    58
    +    result = cli.run(project=project, args=['workspace', 'open', '-f', '--directory', workspace_dir, 'hello.bst', ])
    
    59 59
         result.assert_success()
    
    60 60
     
    
    61 61
         result = cli.run(project=project, args=['workspace', 'list'])
    
    ... ... @@ -72,7 +72,7 @@ def test_make_change_in_workspace(cli, tmpdir, datafiles):
    72 72
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    73 73
         workspace_dir = os.path.join(str(tmpdir), "workspace_hello")
    
    74 74
     
    
    75
    -    result = cli.run(project=project, args=['workspace', 'open', '-f', 'hello.bst', workspace_dir])
    
    75
    +    result = cli.run(project=project, args=['workspace', 'open', '-f', '--directory', workspace_dir, 'hello.bst'])
    
    76 76
         result.assert_success()
    
    77 77
     
    
    78 78
         result = cli.run(project=project, args=['workspace', 'list'])
    

  • tests/examples/junctions.py
    ... ... @@ -44,7 +44,7 @@ def test_open_cross_junction_workspace(cli, tmpdir, datafiles):
    44 44
         workspace_dir = os.path.join(str(tmpdir), "workspace_hello_junction")
    
    45 45
     
    
    46 46
         result = cli.run(project=project,
    
    47
    -                     args=['workspace', 'open', 'hello-junction.bst:hello.bst', workspace_dir])
    
    47
    +                     args=['workspace', 'open', '--directory', workspace_dir, 'hello-junction.bst:hello.bst'])
    
    48 48
         result.assert_success()
    
    49 49
     
    
    50 50
         result = cli.run(project=project,
    

  • tests/frontend/buildcheckout.py
    ... ... @@ -510,7 +510,7 @@ def test_build_checkout_workspaced_junction(cli, tmpdir, datafiles):
    510 510
     
    
    511 511
         # Now open a workspace on the junction
    
    512 512
         #
    
    513
    -    result = cli.run(project=project, args=['workspace', 'open', 'junction.bst', workspace])
    
    513
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, 'junction.bst'])
    
    514 514
         result.assert_success()
    
    515 515
         filename = os.path.join(workspace, 'files', 'etc-files', 'etc', 'animal.conf')
    
    516 516
     
    

  • tests/frontend/cross_junction_workspace.py
    ... ... @@ -47,7 +47,7 @@ def open_cross_junction(cli, tmpdir):
    47 47
         workspace = tmpdir.join("workspace")
    
    48 48
     
    
    49 49
         element = 'sub.bst:data.bst'
    
    50
    -    args = ['workspace', 'open', element, str(workspace)]
    
    50
    +    args = ['workspace', 'open', '--directory', str(workspace), element]
    
    51 51
         result = cli.run(project=project, args=args)
    
    52 52
         result.assert_success()
    
    53 53
     
    

  • tests/frontend/workspace.py
    ... ... @@ -21,6 +21,7 @@
    21 21
     #           Phillip Smyth <phillip smyth codethink co uk>
    
    22 22
     #           Jonathan Maw <jonathan maw codethink co uk>
    
    23 23
     #           Richard Maw <richard maw codethink co uk>
    
    24
    +#           William Salmon <will salmon codethink co uk>
    
    24 25
     #
    
    25 26
     
    
    26 27
     import os
    
    ... ... @@ -43,65 +44,118 @@ DATA_DIR = os.path.join(
    43 44
     )
    
    44 45
     
    
    45 46
     
    
    46
    -def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
    
    47
    -                   project_path=None, element_attrs=None):
    
    48
    -    if not workspace_dir:
    
    49
    -        workspace_dir = os.path.join(str(tmpdir), 'workspace{}'.format(suffix))
    
    50
    -    if not project_path:
    
    51
    -        project_path = os.path.join(datafiles.dirname, datafiles.basename)
    
    52
    -    else:
    
    53
    -        shutil.copytree(os.path.join(datafiles.dirname, datafiles.basename), project_path)
    
    54
    -    bin_files_path = os.path.join(project_path, 'files', 'bin-files')
    
    55
    -    element_path = os.path.join(project_path, 'elements')
    
    56
    -    element_name = 'workspace-test-{}{}.bst'.format(kind, suffix)
    
    47
    +class WorkspaceCreater():
    
    48
    +    def __init__(self, cli, tmpdir, datafiles, project_path=None):
    
    49
    +        self.cli = cli
    
    50
    +        self.tmpdir = tmpdir
    
    51
    +        self.datafiles = datafiles
    
    52
    +
    
    53
    +        if not project_path:
    
    54
    +            project_path = os.path.join(datafiles.dirname, datafiles.basename)
    
    55
    +        else:
    
    56
    +            shutil.copytree(os.path.join(datafiles.dirname, datafiles.basename), project_path)
    
    57
    +
    
    58
    +        self.project_path = project_path
    
    59
    +        self.bin_files_path = os.path.join(project_path, 'files', 'bin-files')
    
    60
    +
    
    61
    +        self.workspace_cmd = os.path.join(self.project_path, 'workspace_cmd')
    
    62
    +
    
    63
    +    def create_workspace_element(self, kind, track, suffix='', workspace_dir=None,
    
    64
    +                                 element_attrs=None):
    
    65
    +        element_name = 'workspace-test-{}{}.bst'.format(kind, suffix)
    
    66
    +        element_path = os.path.join(self.project_path, 'elements')
    
    67
    +        if not workspace_dir:
    
    68
    +            workspace_dir = os.path.join(self.workspace_cmd, element_name.rstrip('.bst'))
    
    69
    +
    
    70
    +        # Create our repo object of the given source type with
    
    71
    +        # the bin files, and then collect the initial ref.
    
    72
    +        repo = create_repo(kind, str(self.tmpdir))
    
    73
    +        ref = repo.create(self.bin_files_path)
    
    74
    +        if track:
    
    75
    +            ref = None
    
    76
    +
    
    77
    +        # Write out our test target
    
    78
    +        element = {
    
    79
    +            'kind': 'import',
    
    80
    +            'sources': [
    
    81
    +                repo.source_config(ref=ref)
    
    82
    +            ]
    
    83
    +        }
    
    84
    +        if element_attrs:
    
    85
    +            element = {**element, **element_attrs}
    
    86
    +        _yaml.dump(element,
    
    87
    +                   os.path.join(element_path,
    
    88
    +                                element_name))
    
    89
    +        return element_name, element_path, workspace_dir
    
    57 90
     
    
    58
    -    # Create our repo object of the given source type with
    
    59
    -    # the bin files, and then collect the initial ref.
    
    60
    -    #
    
    61
    -    repo = create_repo(kind, str(tmpdir))
    
    62
    -    ref = repo.create(bin_files_path)
    
    63
    -    if track:
    
    64
    -        ref = None
    
    91
    +    def create_workspace_elements(self, kinds, track, suffixs=None, workspace_dir_usr=None,
    
    92
    +                                  element_attrs=None):
    
    65 93
     
    
    66
    -    # Write out our test target
    
    67
    -    element = {
    
    68
    -        'kind': 'import',
    
    69
    -        'sources': [
    
    70
    -            repo.source_config(ref=ref)
    
    71
    -        ]
    
    72
    -    }
    
    73
    -    if element_attrs:
    
    74
    -        element = {**element, **element_attrs}
    
    75
    -    _yaml.dump(element,
    
    76
    -               os.path.join(element_path,
    
    77
    -                            element_name))
    
    94
    +        results = []
    
    78 95
     
    
    79
    -    # Assert that there is no reference, a track & fetch is needed
    
    80
    -    state = cli.get_element_state(project_path, element_name)
    
    81
    -    if track:
    
    82
    -        assert state == 'no reference'
    
    83
    -    else:
    
    84
    -        assert state == 'fetch needed'
    
    96
    +        if suffixs is None:
    
    97
    +            suffixs = ['', ] * len(kinds)
    
    98
    +        else:
    
    99
    +            if len(suffixs) != len(kinds):
    
    100
    +                raise "terable error"
    
    85 101
     
    
    86
    -    # Now open the workspace, this should have the effect of automatically
    
    87
    -    # tracking & fetching the source from the repo.
    
    88
    -    args = ['workspace', 'open']
    
    89
    -    if track:
    
    90
    -        args.append('--track')
    
    91
    -    args.extend([element_name, workspace_dir])
    
    92
    -    result = cli.run(project=project_path, args=args)
    
    102
    +        for suffix, kind in zip(suffixs, kinds):
    
    103
    +            element_name, element_path, workspace_dir = \
    
    104
    +                self.create_workspace_element(kind, track, suffix, workspace_dir_usr,
    
    105
    +                                              element_attrs)
    
    93 106
     
    
    94
    -    result.assert_success()
    
    107
    +            # Assert that there is no reference, a track & fetch is needed
    
    108
    +            state = self.cli.get_element_state(self.project_path, element_name)
    
    109
    +            if track:
    
    110
    +                assert state == 'no reference'
    
    111
    +            else:
    
    112
    +                assert state == 'fetch needed'
    
    113
    +            results.append((element_name, workspace_dir))
    
    95 114
     
    
    96
    -    # Assert that we are now buildable because the source is
    
    97
    -    # now cached.
    
    98
    -    assert cli.get_element_state(project_path, element_name) == 'buildable'
    
    115
    +        return results
    
    99 116
     
    
    100
    -    # Check that the executable hello file is found in the workspace
    
    101
    -    filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
    
    102
    -    assert os.path.exists(filename)
    
    117
    +    def open_workspaces(self, kinds, track, suffixs=None, workspace_dir=None,
    
    118
    +                        element_attrs=None):
    
    119
    +
    
    120
    +        results = self.create_workspace_elements(kinds, track, suffixs, workspace_dir,
    
    121
    +                                                 element_attrs)
    
    122
    +        os.makedirs(self.workspace_cmd, exist_ok=True)
    
    103 123
     
    
    104
    -    return (element_name, project_path, workspace_dir)
    
    124
    +        # Now open the workspace, this should have the effect of automatically
    
    125
    +        # tracking & fetching the source from the repo.
    
    126
    +        args = ['workspace', 'open']
    
    127
    +        if track:
    
    128
    +            args.append('--track')
    
    129
    +        if workspace_dir is not None:
    
    130
    +            assert len(results) == 1, "test logic error"
    
    131
    +            _, workspace_dir = results[0]
    
    132
    +            args.extend(['--directory', workspace_dir])
    
    133
    +
    
    134
    +        args.extend([element_name for element_name, workspace_dir_suffix in results])
    
    135
    +        result = self.cli.run(cwd=self.workspace_cmd, project=self.project_path, args=args)
    
    136
    +
    
    137
    +        result.assert_success()
    
    138
    +
    
    139
    +        for element_name, workspace_dir in results:
    
    140
    +            # Assert that we are now buildable because the source is
    
    141
    +            # now cached.
    
    142
    +            assert self.cli.get_element_state(self.project_path, element_name) == 'buildable'
    
    143
    +
    
    144
    +            # Check that the executable hello file is found in the workspace
    
    145
    +            filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
    
    146
    +            assert os.path.exists(filename)
    
    147
    +
    
    148
    +        return results
    
    149
    +
    
    150
    +
    
    151
    +def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
    
    152
    +                   project_path=None, element_attrs=None):
    
    153
    +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles, project_path)
    
    154
    +    workspaces = workspace_object.open_workspaces((kind, ), track, (suffix, ), workspace_dir,
    
    155
    +                                                  element_attrs)
    
    156
    +    assert len(workspaces) == 1
    
    157
    +    element_name, workspace = workspaces[0]
    
    158
    +    return element_name, workspace_object.project_path, workspace
    
    105 159
     
    
    106 160
     
    
    107 161
     @pytest.mark.datafiles(DATA_DIR)
    
    ... ... @@ -110,6 +164,44 @@ def test_open(cli, tmpdir, datafiles, kind):
    110 164
         open_workspace(cli, tmpdir, datafiles, kind, False)
    
    111 165
     
    
    112 166
     
    
    167
    +@pytest.mark.datafiles(DATA_DIR)
    
    168
    +def test_open_multi(cli, tmpdir, datafiles):
    
    169
    +
    
    170
    +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
    
    171
    +    workspaces = workspace_object.open_workspaces(repo_kinds, False)
    
    172
    +
    
    173
    +    for (elname, workspace), kind in zip(workspaces, repo_kinds):
    
    174
    +        assert kind in elname
    
    175
    +        workspace_lsdir = os.listdir(workspace)
    
    176
    +        if kind == 'git':
    
    177
    +            assert('.git' in workspace_lsdir)
    
    178
    +        elif kind == 'bzr':
    
    179
    +            assert('.bzr' in workspace_lsdir)
    
    180
    +        else:
    
    181
    +            assert not ('.git' in workspace_lsdir)
    
    182
    +            assert not ('.bzr' in workspace_lsdir)
    
    183
    +
    
    184
    +
    
    185
    +@pytest.mark.datafiles(DATA_DIR)
    
    186
    +def test_open_multi_with_directory(cli, tmpdir, datafiles):
    
    187
    +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
    
    188
    +
    
    189
    +    results = workspace_object.create_workspace_elements(repo_kinds, False, repo_kinds)
    
    190
    +    os.makedirs(workspace_object.workspace_cmd, exist_ok=True)
    
    191
    +
    
    192
    +    # Now open the workspace, this should have the effect of automatically
    
    193
    +    # tracking & fetching the source from the repo.
    
    194
    +    args = ['workspace', 'open']
    
    195
    +    args.extend(['--directory', 'any/dir/should/fail'])
    
    196
    +
    
    197
    +    args.extend([element_name for element_name, workspace_dir_suffix in results])
    
    198
    +    result = workspace_object.cli.run(cwd=workspace_object.workspace_cmd, project=workspace_object.project_path,
    
    199
    +                                      args=args)
    
    200
    +
    
    201
    +    result.assert_main_error(ErrorDomain.ARTIFACT, None)
    
    202
    +    assert ("Directory option can only be used if a single element is given" in result.stderr)
    
    203
    +
    
    204
    +
    
    113 205
     @pytest.mark.datafiles(DATA_DIR)
    
    114 206
     def test_open_bzr_customize(cli, tmpdir, datafiles):
    
    115 207
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "bzr", False)
    
    ... ... @@ -150,7 +242,7 @@ def test_open_force(cli, tmpdir, datafiles, kind):
    150 242
     
    
    151 243
         # Now open the workspace again with --force, this should happily succeed
    
    152 244
         result = cli.run(project=project, args=[
    
    153
    -        'workspace', 'open', '--force', element_name, workspace
    
    245
    +        'workspace', 'open', '--force', '--directory', workspace, element_name
    
    154 246
         ])
    
    155 247
         result.assert_success()
    
    156 248
     
    
    ... ... @@ -165,7 +257,7 @@ def test_open_force_open(cli, tmpdir, datafiles, kind):
    165 257
     
    
    166 258
         # Now open the workspace again with --force, this should happily succeed
    
    167 259
         result = cli.run(project=project, args=[
    
    168
    -        'workspace', 'open', '--force', element_name, workspace
    
    260
    +        'workspace', 'open', '--force', '--directory', workspace, element_name
    
    169 261
         ])
    
    170 262
         result.assert_success()
    
    171 263
     
    
    ... ... @@ -196,7 +288,7 @@ def test_open_force_different_workspace(cli, tmpdir, datafiles, kind):
    196 288
     
    
    197 289
         # Now open the workspace again with --force, this should happily succeed
    
    198 290
         result = cli.run(project=project, args=[
    
    199
    -        'workspace', 'open', '--force', element_name2, workspace
    
    291
    +        'workspace', 'open', '--force', '--directory', workspace, element_name2
    
    200 292
         ])
    
    201 293
     
    
    202 294
         # Assert that the file in workspace 1 has been replaced
    
    ... ... @@ -504,7 +596,7 @@ def test_buildable_no_ref(cli, tmpdir, datafiles):
    504 596
         # Now open the workspace. We don't need to checkout the source though.
    
    505 597
         workspace = os.path.join(str(tmpdir), 'workspace-no-ref')
    
    506 598
         os.makedirs(workspace)
    
    507
    -    args = ['workspace', 'open', '--no-checkout', element_name, workspace]
    
    599
    +    args = ['workspace', 'open', '--no-checkout', '--directory', workspace, element_name]
    
    508 600
         result = cli.run(project=project, args=args)
    
    509 601
         result.assert_success()
    
    510 602
     
    
    ... ... @@ -766,7 +858,7 @@ def test_list_supported_workspace(cli, tmpdir, datafiles, workspace_cfg, expecte
    766 858
                                 element_name))
    
    767 859
     
    
    768 860
         # Make a change to the workspaces file
    
    769
    -    result = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    861
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    770 862
         result.assert_success()
    
    771 863
         result = cli.run(project=project, args=['workspace', 'close', '--remove-dir', element_name])
    
    772 864
         result.assert_success()
    

  • tests/integration/shell.py
    ... ... @@ -278,7 +278,7 @@ def test_workspace_visible(cli, tmpdir, datafiles):
    278 278
     
    
    279 279
         # Open a workspace on our build failing element
    
    280 280
         #
    
    281
    -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    281
    +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    282 282
         assert res.exit_code == 0
    
    283 283
     
    
    284 284
         # Ensure the dependencies of our build failing element are built
    
    ... ... @@ -312,7 +312,7 @@ def test_sysroot_workspace_visible(cli, tmpdir, datafiles):
    312 312
     
    
    313 313
         # Open a workspace on our build failing element
    
    314 314
         #
    
    315
    -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    315
    +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    316 316
         assert res.exit_code == 0
    
    317 317
     
    
    318 318
         # Ensure the dependencies of our build failing element are built
    

  • tests/integration/workspace.py
    ... ... @@ -23,7 +23,7 @@ def test_workspace_mount(cli, tmpdir, datafiles):
    23 23
         workspace = os.path.join(cli.directory, 'workspace')
    
    24 24
         element_name = 'workspace/workspace-mount.bst'
    
    25 25
     
    
    26
    -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    26
    +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    27 27
         assert res.exit_code == 0
    
    28 28
     
    
    29 29
         res = cli.run(project=project, args=['build', element_name])
    
    ... ... @@ -39,7 +39,7 @@ def test_workspace_commanddir(cli, tmpdir, datafiles):
    39 39
         workspace = os.path.join(cli.directory, 'workspace')
    
    40 40
         element_name = 'workspace/workspace-commanddir.bst'
    
    41 41
     
    
    42
    -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    42
    +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    43 43
         assert res.exit_code == 0
    
    44 44
     
    
    45 45
         res = cli.run(project=project, args=['build', element_name])
    
    ... ... @@ -75,7 +75,7 @@ def test_workspace_updated_dependency(cli, tmpdir, datafiles):
    75 75
         _yaml.dump(dependency, os.path.join(element_path, dep_name))
    
    76 76
     
    
    77 77
         # First open the workspace
    
    78
    -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    78
    +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    79 79
         assert res.exit_code == 0
    
    80 80
     
    
    81 81
         # We build the workspaced element, so that we have an artifact
    
    ... ... @@ -130,7 +130,7 @@ def test_workspace_update_dependency_failed(cli, tmpdir, datafiles):
    130 130
         _yaml.dump(dependency, os.path.join(element_path, dep_name))
    
    131 131
     
    
    132 132
         # First open the workspace
    
    133
    -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    133
    +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    134 134
         assert res.exit_code == 0
    
    135 135
     
    
    136 136
         # We build the workspaced element, so that we have an artifact
    
    ... ... @@ -205,7 +205,7 @@ def test_updated_dependency_nested(cli, tmpdir, datafiles):
    205 205
         _yaml.dump(dependency, os.path.join(element_path, dep_name))
    
    206 206
     
    
    207 207
         # First open the workspace
    
    208
    -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    208
    +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    209 209
         assert res.exit_code == 0
    
    210 210
     
    
    211 211
         # We build the workspaced element, so that we have an artifact
    
    ... ... @@ -258,7 +258,7 @@ def test_incremental_configure_commands_run_only_once(cli, tmpdir, datafiles):
    258 258
         _yaml.dump(element, os.path.join(element_path, element_name))
    
    259 259
     
    
    260 260
         # We open a workspace on the above element
    
    261
    -    res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    261
    +    res = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    262 262
         res.assert_success()
    
    263 263
     
    
    264 264
         # Then we build, and check whether the configure step succeeded
    

  • tests/plugins/filter.py
    ... ... @@ -108,7 +108,7 @@ def test_filter_forbid_also_rdep(datafiles, cli):
    108 108
     def test_filter_workspace_open(datafiles, cli, tmpdir):
    
    109 109
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    110 110
         workspace_dir = os.path.join(tmpdir.dirname, tmpdir.basename, "workspace")
    
    111
    -    result = cli.run(project=project, args=['workspace', 'open', 'deps-permitted.bst', workspace_dir])
    
    111
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'deps-permitted.bst'])
    
    112 112
         result.assert_success()
    
    113 113
         assert os.path.exists(os.path.join(workspace_dir, "foo"))
    
    114 114
         assert os.path.exists(os.path.join(workspace_dir, "bar"))
    
    ... ... @@ -120,7 +120,7 @@ def test_filter_workspace_build(datafiles, cli, tmpdir):
    120 120
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    121 121
         tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
    
    122 122
         workspace_dir = os.path.join(tempdir, "workspace")
    
    123
    -    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
    
    123
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'output-orphans.bst'])
    
    124 124
         result.assert_success()
    
    125 125
         src = os.path.join(workspace_dir, "foo")
    
    126 126
         dst = os.path.join(workspace_dir, "quux")
    
    ... ... @@ -138,7 +138,7 @@ def test_filter_workspace_close(datafiles, cli, tmpdir):
    138 138
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    139 139
         tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
    
    140 140
         workspace_dir = os.path.join(tempdir, "workspace")
    
    141
    -    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
    
    141
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'output-orphans.bst'])
    
    142 142
         result.assert_success()
    
    143 143
         src = os.path.join(workspace_dir, "foo")
    
    144 144
         dst = os.path.join(workspace_dir, "quux")
    
    ... ... @@ -158,7 +158,7 @@ def test_filter_workspace_reset(datafiles, cli, tmpdir):
    158 158
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    159 159
         tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
    
    160 160
         workspace_dir = os.path.join(tempdir, "workspace")
    
    161
    -    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
    
    161
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'output-orphans.bst'])
    
    162 162
         result.assert_success()
    
    163 163
         src = os.path.join(workspace_dir, "foo")
    
    164 164
         dst = os.path.join(workspace_dir, "quux")
    



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