[Notes] [Git][BuildStream/buildstream][willsalmon/defaultWorkspaces] 9 commits: _yaml: document node_get()'s default_value arg



Title: GitLab

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

Commits:

16 changed files:

Changes:

  • NEWS
    ... ... @@ -45,6 +45,12 @@ buildstream 1.3.1
    45 45
         instead of just a specially-formatted build-root with a `root` and `scratch`
    
    46 46
         subdirectory.
    
    47 47
     
    
    48
    +  o The buildstream.conf file learned new 'prompt.auto-init',
    
    49
    +    'prompt.really-workspace-close-remove-dir', and
    
    50
    +    'prompt.really-workspace-reset-hard' options. These allow users to suppress
    
    51
    +    certain confirmation prompts, e.g. double-checking that the user meant to
    
    52
    +    run the command as typed.
    
    53
    +
    
    48 54
       o Due to the element `build tree` being cached in the respective artifact their
    
    49 55
         size in some cases has significantly increased. In *most* cases the build trees
    
    50 56
         are not utilised when building targets, as such by default bst 'pull' & 'build'
    
    ... ... @@ -56,6 +62,10 @@ buildstream 1.3.1
    56 62
         is expected to have a populated build tree then it must be cached before pushing.
    
    57 63
     
    
    58 64
       o Added new `bst source-checkout` command to checkout sources of an element.
    
    65
    +  
    
    66
    +  o `bst workspace open` now supports the creation of multiple elements and
    
    67
    +    allows the user to set a default location for there creation. This has meant
    
    68
    +    that the new CLI is no longer backwards compatible with buildstream 1.2.
    
    59 69
     
    
    60 70
     
    
    61 71
     =================
    

  • buildstream/_context.py
    ... ... @@ -59,6 +59,9 @@ class Context():
    59 59
             # The directory where build sandboxes will be created
    
    60 60
             self.builddir = None
    
    61 61
     
    
    62
    +        # Default root location for workspaces
    
    63
    +        self.workspacedir = None
    
    64
    +
    
    62 65
             # The local binary artifact cache directory
    
    63 66
             self.artifactdir = None
    
    64 67
     
    
    ... ... @@ -110,6 +113,18 @@ class Context():
    110 113
             # Whether or not to attempt to pull build trees globally
    
    111 114
             self.pull_buildtrees = None
    
    112 115
     
    
    116
    +        # Boolean, whether to offer to create a project for the user, if we are
    
    117
    +        # invoked outside of a directory where we can resolve the project.
    
    118
    +        self.prompt_auto_init = None
    
    119
    +
    
    120
    +        # Boolean, whether we double-check with the user that they meant to
    
    121
    +        # remove a workspace directory.
    
    122
    +        self.prompt_workspace_close_remove_dir = None
    
    123
    +
    
    124
    +        # Boolean, whether we double-check with the user that they meant to do
    
    125
    +        # a hard reset of a workspace, potentially losing changes.
    
    126
    +        self.prompt_workspace_reset_hard = None
    
    127
    +
    
    113 128
             # Whether elements must be rebuilt when their dependencies have changed
    
    114 129
             self._strict_build_plan = None
    
    115 130
     
    
    ... ... @@ -165,10 +180,10 @@ class Context():
    165 180
             _yaml.node_validate(defaults, [
    
    166 181
                 'sourcedir', 'builddir', 'artifactdir', 'logdir',
    
    167 182
                 'scheduler', 'artifacts', 'logging', 'projects',
    
    168
    -            'cache'
    
    183
    +            'cache', 'prompt', 'workspacedir',
    
    169 184
             ])
    
    170 185
     
    
    171
    -        for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir']:
    
    186
    +        for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir', 'workspacedir']:
    
    172 187
                 # Allow the ~ tilde expansion and any environment variables in
    
    173 188
                 # path specification in the config files.
    
    174 189
                 #
    
    ... ... @@ -214,12 +229,34 @@ class Context():
    214 229
                 'on-error', 'fetchers', 'builders',
    
    215 230
                 'pushers', 'network-retries'
    
    216 231
             ])
    
    217
    -        self.sched_error_action = _yaml.node_get(scheduler, str, 'on-error')
    
    232
    +        self.sched_error_action = _node_get_option_str(
    
    233
    +            scheduler, 'on-error', ['continue', 'quit', 'terminate'])
    
    218 234
             self.sched_fetchers = _yaml.node_get(scheduler, int, 'fetchers')
    
    219 235
             self.sched_builders = _yaml.node_get(scheduler, int, 'builders')
    
    220 236
             self.sched_pushers = _yaml.node_get(scheduler, int, 'pushers')
    
    221 237
             self.sched_network_retries = _yaml.node_get(scheduler, int, 'network-retries')
    
    222 238
     
    
    239
    +        # Load prompt preferences
    
    240
    +        #
    
    241
    +        # We convert string options to booleans here, so we can be both user
    
    242
    +        # and coder-friendly. The string options are worded to match the
    
    243
    +        # responses the user would give at the cli, for least surprise. The
    
    244
    +        # booleans are converted here because it's easiest to eyeball that the
    
    245
    +        # strings are right.
    
    246
    +        #
    
    247
    +        prompt = _yaml.node_get(
    
    248
    +            defaults, Mapping, 'prompt')
    
    249
    +        _yaml.node_validate(prompt, [
    
    250
    +            'auto-init', 'really-workspace-close-remove-dir',
    
    251
    +            'really-workspace-reset-hard',
    
    252
    +        ])
    
    253
    +        self.prompt_auto_init = _node_get_option_str(
    
    254
    +            prompt, 'auto-init', ['ask', 'no']) == 'ask'
    
    255
    +        self.prompt_workspace_close_remove_dir = _node_get_option_str(
    
    256
    +            prompt, 'really-workspace-close-remove-dir', ['ask', 'yes']) == 'ask'
    
    257
    +        self.prompt_workspace_reset_hard = _node_get_option_str(
    
    258
    +            prompt, 'really-workspace-reset-hard', ['ask', 'yes']) == 'ask'
    
    259
    +
    
    223 260
             # Load per-projects overrides
    
    224 261
             self._project_overrides = _yaml.node_get(defaults, Mapping, 'projects', default_value={})
    
    225 262
     
    
    ... ... @@ -230,13 +267,6 @@ class Context():
    230 267
     
    
    231 268
             profile_end(Topics.LOAD_CONTEXT, 'load')
    
    232 269
     
    
    233
    -        valid_actions = ['continue', 'quit']
    
    234
    -        if self.sched_error_action not in valid_actions:
    
    235
    -            provenance = _yaml.node_get_provenance(scheduler, 'on-error')
    
    236
    -            raise LoadError(LoadErrorReason.INVALID_DATA,
    
    237
    -                            "{}: on-error should be one of: {}".format(
    
    238
    -                                provenance, ", ".join(valid_actions)))
    
    239
    -
    
    240 270
         @property
    
    241 271
         def artifactcache(self):
    
    242 272
             if not self._artifactcache:
    
    ... ... @@ -589,3 +619,30 @@ class Context():
    589 619
                 os.environ['XDG_CONFIG_HOME'] = os.path.expanduser('~/.config')
    
    590 620
             if not os.environ.get('XDG_DATA_HOME'):
    
    591 621
                 os.environ['XDG_DATA_HOME'] = os.path.expanduser('~/.local/share')
    
    622
    +
    
    623
    +
    
    624
    +# _node_get_option_str()
    
    625
    +#
    
    626
    +# Like _yaml.node_get(), but also checks value is one of the allowed option
    
    627
    +# strings. Fetches a value from a dictionary node, and makes sure it's one of
    
    628
    +# the pre-defined options.
    
    629
    +#
    
    630
    +# Args:
    
    631
    +#    node (dict): The dictionary node
    
    632
    +#    key (str): The key to get a value for in node
    
    633
    +#    allowed_options (iterable): Only accept these values
    
    634
    +#
    
    635
    +# Returns:
    
    636
    +#    The value, if found in 'node'.
    
    637
    +#
    
    638
    +# Raises:
    
    639
    +#    LoadError, when the value is not of the expected type, or is not found.
    
    640
    +#
    
    641
    +def _node_get_option_str(node, key, allowed_options):
    
    642
    +    result = _yaml.node_get(node, str, key)
    
    643
    +    if result not in allowed_options:
    
    644
    +        provenance = _yaml.node_get_provenance(node, key)
    
    645
    +        raise LoadError(LoadErrorReason.INVALID_DATA,
    
    646
    +                        "{}: {} should be one of: {}".format(
    
    647
    +                            provenance, key, ", ".join(allowed_options)))
    
    648
    +    return result

  • buildstream/_frontend/app.py
    ... ... @@ -222,9 +222,10 @@ class App():
    222 222
                 # Let's automatically start a `bst init` session in this case
    
    223 223
                 if e.reason == LoadErrorReason.MISSING_PROJECT_CONF and self.interactive:
    
    224 224
                     click.echo("A project was not detected in the directory: {}".format(directory), err=True)
    
    225
    -                click.echo("", err=True)
    
    226
    -                if click.confirm("Would you like to create a new project here ?"):
    
    227
    -                    self.init_project(None)
    
    225
    +                if self.context.prompt_auto_init:
    
    226
    +                    click.echo("", err=True)
    
    227
    +                    if click.confirm("Would you like to create a new project here?"):
    
    228
    +                        self.init_project(None)
    
    228 229
     
    
    229 230
                 self._error_exit(e, "Error loading project")
    
    230 231
     
    

  • buildstream/_frontend/cli.py
    ... ... @@ -707,31 +707,23 @@ def workspace():
    707 707
     @click.option('--no-checkout', default=False, is_flag=True,
    
    708 708
                   help="Do not checkout the source, only link to the given directory")
    
    709 709
     @click.option('--force', '-f', default=False, is_flag=True,
    
    710
    -              help="Overwrite files existing in checkout directory")
    
    710
    +              help="The workspace will be created even if the directory in which it will be created is not empty " +
    
    711
    +              "or if a workspace for that element already exists")
    
    711 712
     @click.option('--track', 'track_', default=False, is_flag=True,
    
    712 713
                   help="Track and fetch new source references before checking out the workspace")
    
    713
    -@click.argument('element',
    
    714
    -                type=click.Path(readable=False))
    
    715
    -@click.argument('directory', type=click.Path(file_okay=False))
    
    714
    +@click.option('--directory', type=click.Path(file_okay=False), default=None,
    
    715
    +              help="Only for use when a single Element is given: Set the directory to use to create the workspace")
    
    716
    +@click.argument('elements', nargs=-1, type=click.Path(readable=False), required=True)
    
    716 717
     @click.pass_obj
    
    717
    -def workspace_open(app, no_checkout, force, track_, element, directory):
    
    718
    +def workspace_open(app, no_checkout, force, track_, directory, elements):
    
    718 719
         """Open a workspace for manual source modification"""
    
    719 720
     
    
    720
    -    if os.path.exists(directory):
    
    721
    -
    
    722
    -        if not os.path.isdir(directory):
    
    723
    -            click.echo("Checkout directory is not a directory: {}".format(directory), err=True)
    
    724
    -            sys.exit(-1)
    
    725
    -
    
    726
    -        if not (no_checkout or force) and os.listdir(directory):
    
    727
    -            click.echo("Checkout directory is not empty: {}".format(directory), err=True)
    
    728
    -            sys.exit(-1)
    
    729
    -
    
    730 721
         with app.initialized():
    
    731
    -        app.stream.workspace_open(element, directory,
    
    722
    +        app.stream.workspace_open(elements,
    
    732 723
                                       no_checkout=no_checkout,
    
    733 724
                                       track_first=track_,
    
    734
    -                                  force=force)
    
    725
    +                                  force=force,
    
    726
    +                                  custom_dir=directory)
    
    735 727
     
    
    736 728
     
    
    737 729
     ##################################################################
    
    ... ... @@ -772,7 +764,7 @@ def workspace_close(app, remove_dir, all_, elements):
    772 764
             if nonexisting:
    
    773 765
                 raise AppError("Workspace does not exist", detail="\n".join(nonexisting))
    
    774 766
     
    
    775
    -        if app.interactive and remove_dir:
    
    767
    +        if app.interactive and remove_dir and app.context.prompt_workspace_close_remove_dir:
    
    776 768
                 if not click.confirm('This will remove all your changes, are you sure?'):
    
    777 769
                     click.echo('Aborting', err=True)
    
    778 770
                     sys.exit(-1)
    
    ... ... @@ -806,7 +798,7 @@ def workspace_reset(app, soft, track_, all_, elements):
    806 798
             if all_ and not app.stream.workspace_exists():
    
    807 799
                 raise AppError("No open workspaces to reset")
    
    808 800
     
    
    809
    -        if app.interactive and not soft:
    
    801
    +        if app.interactive and not soft and app.context.prompt_workspace_reset_hard:
    
    810 802
                 if not click.confirm('This will remove all your changes, are you sure?'):
    
    811 803
                     click.echo('Aborting', err=True)
    
    812 804
                     sys.exit(-1)
    

  • buildstream/_stream.py
    ... ... @@ -464,44 +464,29 @@ class Stream():
    464 464
         # Open a project workspace
    
    465 465
         #
    
    466 466
         # Args:
    
    467
    -    #    target (str): The target element to open the workspace for
    
    468
    -    #    directory (str): The directory to stage the source in
    
    467
    +    #    target (list): List of target elements to open workspaces for
    
    469 468
         #    no_checkout (bool): Whether to skip checking out the source
    
    470 469
         #    track_first (bool): Whether to track and fetch first
    
    471 470
         #    force (bool): Whether to ignore contents in an existing directory
    
    472 471
         #
    
    473
    -    def workspace_open(self, target, directory, *,
    
    472
    +    def workspace_open(self, targets, *,
    
    474 473
                            no_checkout,
    
    475 474
                            track_first,
    
    476
    -                       force):
    
    475
    +                       force,
    
    476
    +                       custom_dir):
    
    477
    +        # This function is a little funny but it is trying to be as atomic as possible.
    
    477 478
     
    
    478 479
             if track_first:
    
    479
    -            track_targets = (target,)
    
    480
    +            track_targets = targets
    
    480 481
             else:
    
    481 482
                 track_targets = ()
    
    482 483
     
    
    483
    -        elements, track_elements = self._load((target,), track_targets,
    
    484
    +        elements, track_elements = self._load(targets, track_targets,
    
    484 485
                                                   selection=PipelineSelection.REDIRECT,
    
    485 486
                                                   track_selection=PipelineSelection.REDIRECT)
    
    486
    -        target = elements[0]
    
    487
    -        directory = os.path.abspath(directory)
    
    488
    -
    
    489
    -        if not list(target.sources()):
    
    490
    -            build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)]
    
    491
    -            if not build_depends:
    
    492
    -                raise StreamError("The given element has no sources")
    
    493
    -            detail = "Try opening a workspace on one of its dependencies instead:\n"
    
    494
    -            detail += "  \n".join(build_depends)
    
    495
    -            raise StreamError("The given element has no sources", detail=detail)
    
    496 487
     
    
    497 488
             workspaces = self._context.get_workspaces()
    
    498 489
     
    
    499
    -        # Check for workspace config
    
    500
    -        workspace = workspaces.get_workspace(target._get_full_name())
    
    501
    -        if workspace and not force:
    
    502
    -            raise StreamError("Workspace '{}' is already defined at: {}"
    
    503
    -                              .format(target.name, workspace.get_absolute_path()))
    
    504
    -
    
    505 490
             # If we're going to checkout, we need at least a fetch,
    
    506 491
             # if we were asked to track first, we're going to fetch anyway.
    
    507 492
             #
    
    ... ... @@ -511,29 +496,88 @@ class Stream():
    511 496
                     track_elements = elements
    
    512 497
                 self._fetch(elements, track_elements=track_elements)
    
    513 498
     
    
    514
    -        if not no_checkout and target._get_consistency() != Consistency.CACHED:
    
    515
    -            raise StreamError("Could not stage uncached source. " +
    
    516
    -                              "Use `--track` to track and " +
    
    517
    -                              "fetch the latest version of the " +
    
    518
    -                              "source.")
    
    519
    -
    
    520
    -        if workspace:
    
    521
    -            workspaces.delete_workspace(target._get_full_name())
    
    522
    -            workspaces.save_config()
    
    523
    -            shutil.rmtree(directory)
    
    524
    -        try:
    
    525
    -            os.makedirs(directory, exist_ok=True)
    
    526
    -        except OSError as e:
    
    527
    -            raise StreamError("Failed to create workspace directory: {}".format(e)) from e
    
    499
    +        expanded_directories = []
    
    500
    +        #  To try to be more atomic, loop through the elements and raise any errors we can early
    
    501
    +        for target in elements:
    
    502
    +
    
    503
    +            if not list(target.sources()):
    
    504
    +                build_depends = [x.name for x in target.dependencies(Scope.BUILD, recurse=False)]
    
    505
    +                if not build_depends:
    
    506
    +                    raise StreamError("The element {}  has no sources".format(target.name))
    
    507
    +                detail = "Try opening a workspace on one of its dependencies instead:\n"
    
    508
    +                detail += "  \n".join(build_depends)
    
    509
    +                raise StreamError("The element {} has no sources".format(target.name), detail=detail)
    
    510
    +
    
    511
    +            # Check for workspace config
    
    512
    +            workspace = workspaces.get_workspace(target._get_full_name())
    
    513
    +            if workspace and not force:
    
    514
    +                raise StreamError("Element '{}' already has workspace defined at: {}"
    
    515
    +                                  .format(target.name, workspace.get_absolute_path()))
    
    516
    +
    
    517
    +            if not no_checkout and target._get_consistency() != Consistency.CACHED:
    
    518
    +                raise StreamError("Could not stage uncached source. For {} ".format(target.name) +
    
    519
    +                                  "Use `--track` to track and " +
    
    520
    +                                  "fetch the latest version of the " +
    
    521
    +                                  "source.")
    
    522
    +
    
    523
    +            if not custom_dir:
    
    524
    +                directory = os.path.abspath(os.path.join(self._context.workspacedir, target.name))
    
    525
    +                if directory[-4:] == '.bst':
    
    526
    +                    directory = directory[:-4]
    
    527
    +                expanded_directories.append(directory)
    
    528
    +
    
    529
    +        if custom_dir:
    
    530
    +            if len(elements) != 1:
    
    531
    +                raise StreamError("Exactly one element can be given if --directory is used",
    
    532
    +                                  reason='directory-with-multiple-elements')
    
    533
    +            expanded_directories = [custom_dir, ]
    
    534
    +        else:
    
    535
    +            # If this fails it is a bug in what ever calls this, usually cli.py and so can not be tested for via the
    
    536
    +            # run bst test mechanism.
    
    537
    +            assert len(elements) == len(expanded_directories)
    
    538
    +
    
    539
    +        for element, directory in zip(elements, expanded_directories):
    
    540
    +            if os.path.exists(directory):
    
    541
    +                if not os.path.isdir(directory):
    
    542
    +                    raise StreamError("For element '{}', Directory path is not a directory: {}"
    
    543
    +                                      .format(target.name, directory), reason='bad-directory')
    
    544
    +
    
    545
    +                if not (no_checkout or force) and os.listdir(directory):
    
    546
    +                    raise StreamError("For element '{}', Directory path is not empty: {}"
    
    547
    +                                      .format(target.name, directory), reason='bad-directory')
    
    548
    +
    
    549
    +        # So far this function has tried to catch as many issues as possible with out making any changes
    
    550
    +        # Now it dose the bits that can not be made atomic.
    
    551
    +        targetGenerator = zip(elements, expanded_directories)
    
    552
    +        for target, directory in targetGenerator:
    
    553
    +            self._message(MessageType.INFO, "Creating workspace for element {}"
    
    554
    +                          .format(target.name))
    
    555
    +
    
    556
    +            workspace = workspaces.get_workspace(target._get_full_name())
    
    557
    +            if workspace:
    
    558
    +                workspaces.delete_workspace(target._get_full_name())
    
    559
    +                workspaces.save_config()
    
    560
    +                shutil.rmtree(directory)
    
    561
    +            try:
    
    562
    +                os.makedirs(directory, exist_ok=True)
    
    563
    +            except OSError as e:
    
    564
    +                todo_elements = " ".join([str(target.name) for target, directory_dict in targetGenerator])
    
    565
    +                if todo_elements:
    
    566
    +                    # This output should make creating the remaining workspaces as easy as possible.
    
    567
    +                    todo_elements = "\nDid not try to create workspaces for " + todo_elements
    
    568
    +                raise StreamError("Failed to create workspace directory: {}".format(e) + todo_elements) from e
    
    528 569
     
    
    529
    -        workspaces.create_workspace(target._get_full_name(), directory)
    
    570
    +            workspaces.create_workspace(target._get_full_name(), directory)
    
    530 571
     
    
    531
    -        if not no_checkout:
    
    532
    -            with target.timed_activity("Staging sources to {}".format(directory)):
    
    533
    -                target._open_workspace()
    
    572
    +            if not no_checkout:
    
    573
    +                with target.timed_activity("Staging sources to {}".format(directory)):
    
    574
    +                    target._open_workspace()
    
    534 575
     
    
    535
    -        workspaces.save_config()
    
    536
    -        self._message(MessageType.INFO, "Saved workspace configuration")
    
    576
    +            # Saving the workspace once it is set up means that if the next workspace fails to be created before
    
    577
    +            # the configuration gets saved. The successfully created workspace still gets saved.
    
    578
    +            workspaces.save_config()
    
    579
    +            self._message(MessageType.INFO, "Created a workspace for element: {}"
    
    580
    +                          .format(target._get_full_name()))
    
    537 581
     
    
    538 582
         # workspace_close
    
    539 583
         #
    

  • buildstream/_yaml.py
    ... ... @@ -351,6 +351,7 @@ _sentinel = object()
    351 351
     #    expected_type (type): The expected type for the value being searched
    
    352 352
     #    key (str): The key to get a value for in node
    
    353 353
     #    indices (list of ints): Optionally decend into lists of lists
    
    354
    +#    default_value: Optionally return this value if the key is not found
    
    354 355
     #
    
    355 356
     # Returns:
    
    356 357
     #    The value if found in node, otherwise default_value is returned
    

  • 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 workspaces, blank for no default set.
    
    26
    +workspacedir: .
    
    27
    +
    
    25 28
     #
    
    26 29
     #    Cache
    
    27 30
     #
    
    ... ... @@ -100,3 +103,35 @@ logging:
    100 103
     
    
    101 104
         [%{elapsed}][%{key}][%{element}] %{action} %{message}
    
    102 105
     
    
    106
    +#
    
    107
    +#    Prompt overrides
    
    108
    +#
    
    109
    +# Here you can suppress 'are you sure?' and other kinds of prompts by supplying
    
    110
    +# override values. Note that e.g. 'yes' and 'no' have the same meaning here as
    
    111
    +# they do in the actual cli prompt.
    
    112
    +#
    
    113
    +prompt:
    
    114
    +
    
    115
    +  # Whether to create a project with 'bst init' if we are invoked outside of a
    
    116
    +  # directory where we can resolve the project.
    
    117
    +  #
    
    118
    +  #  ask - Prompt the user to choose.
    
    119
    +  #  no  - Never create the project.
    
    120
    +  #
    
    121
    +  auto-init: ask
    
    122
    +
    
    123
    +  # Whether to really proceed with 'bst workspace close --remove-dir' removing
    
    124
    +  # a workspace directory, potentially losing changes.
    
    125
    +  #
    
    126
    +  #  ask - Ask the user if they are sure.
    
    127
    +  #  yes - Always remove, without asking.
    
    128
    +  #
    
    129
    +  really-workspace-close-remove-dir: ask
    
    130
    +
    
    131
    +  # Whether to really proceed with 'bst workspace reset' doing a hard reset of
    
    132
    +  # a workspace, potentially losing changes.
    
    133
    +  #
    
    134
    +  #  ask - Ask the user if they are sure.
    
    135
    +  #  yes - Always hard reset, without asking.
    
    136
    +  #
    
    137
    +  really-workspace-reset-hard: ask

  • doc/sessions/developing.run
    ... ... @@ -7,7 +7,7 @@ commands:
    7 7
     # Capture workspace open output 
    
    8 8
     - directory: ../examples/developing/
    
    9 9
       output: ../source/sessions/developing-workspace-open.html
    
    10
    -  command: workspace open hello.bst workspace_hello
    
    10
    +  command: workspace open hello.bst --directory workspace_hello
    
    11 11
     
    
    12 12
     # Catpure output from workspace list
    
    13 13
     - directory: ../examples/developing/
    

  • tests/examples/developing.py
    ... ... @@ -59,7 +59,7 @@ def test_open_workspace(cli, tmpdir, datafiles):
    59 59
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    60 60
         workspace_dir = os.path.join(str(tmpdir), "workspace_hello")
    
    61 61
     
    
    62
    -    result = cli.run(project=project, args=['workspace', 'open', '-f', 'hello.bst', workspace_dir])
    
    62
    +    result = cli.run(project=project, args=['workspace', 'open', '-f', '--directory', workspace_dir, 'hello.bst', ])
    
    63 63
         result.assert_success()
    
    64 64
     
    
    65 65
         result = cli.run(project=project, args=['workspace', 'list'])
    
    ... ... @@ -78,7 +78,7 @@ def test_make_change_in_workspace(cli, tmpdir, datafiles):
    78 78
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    79 79
         workspace_dir = os.path.join(str(tmpdir), "workspace_hello")
    
    80 80
     
    
    81
    -    result = cli.run(project=project, args=['workspace', 'open', '-f', 'hello.bst', workspace_dir])
    
    81
    +    result = cli.run(project=project, args=['workspace', 'open', '-f', '--directory', workspace_dir, 'hello.bst'])
    
    82 82
         result.assert_success()
    
    83 83
     
    
    84 84
         result = cli.run(project=project, args=['workspace', 'list'])
    

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

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

  • 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,9 +21,11 @@
    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
    
    28
    +import stat
    
    27 29
     import pytest
    
    28 30
     import shutil
    
    29 31
     import subprocess
    
    ... ... @@ -43,65 +45,120 @@ DATA_DIR = os.path.join(
    43 45
     )
    
    44 46
     
    
    45 47
     
    
    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)
    
    48
    +class WorkspaceCreater():
    
    49
    +    def __init__(self, cli, tmpdir, datafiles, project_path=None):
    
    50
    +        self.cli = cli
    
    51
    +        self.tmpdir = tmpdir
    
    52
    +        self.datafiles = datafiles
    
    53
    +
    
    54
    +        if not project_path:
    
    55
    +            project_path = os.path.join(datafiles.dirname, datafiles.basename)
    
    56
    +        else:
    
    57
    +            shutil.copytree(os.path.join(datafiles.dirname, datafiles.basename), project_path)
    
    58
    +
    
    59
    +        self.project_path = project_path
    
    60
    +        self.bin_files_path = os.path.join(project_path, 'files', 'bin-files')
    
    61
    +
    
    62
    +        self.workspace_cmd = os.path.join(self.project_path, 'workspace_cmd')
    
    63
    +
    
    64
    +    def create_workspace_element(self, kind, track, suffix='', workspace_dir=None,
    
    65
    +                                 element_attrs=None):
    
    66
    +        element_name = 'workspace-test-{}{}.bst'.format(kind, suffix)
    
    67
    +        element_path = os.path.join(self.project_path, 'elements')
    
    68
    +        if not workspace_dir:
    
    69
    +            workspace_dir = os.path.join(self.workspace_cmd, element_name)
    
    70
    +            if workspace_dir[-4:] == '.bst':
    
    71
    +                workspace_dir = workspace_dir[:-4]
    
    72
    +
    
    73
    +        # Create our repo object of the given source type with
    
    74
    +        # the bin files, and then collect the initial ref.
    
    75
    +        repo = create_repo(kind, str(self.tmpdir))
    
    76
    +        ref = repo.create(self.bin_files_path)
    
    77
    +        if track:
    
    78
    +            ref = None
    
    79
    +
    
    80
    +        # Write out our test target
    
    81
    +        element = {
    
    82
    +            'kind': 'import',
    
    83
    +            'sources': [
    
    84
    +                repo.source_config(ref=ref)
    
    85
    +            ]
    
    86
    +        }
    
    87
    +        if element_attrs:
    
    88
    +            element = {**element, **element_attrs}
    
    89
    +        _yaml.dump(element,
    
    90
    +                   os.path.join(element_path,
    
    91
    +                                element_name))
    
    92
    +        return element_name, element_path, workspace_dir
    
    57 93
     
    
    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
    
    94
    +    def create_workspace_elements(self, kinds, track, suffixs=None, workspace_dir_usr=None,
    
    95
    +                                  element_attrs=None):
    
    65 96
     
    
    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))
    
    97
    +        element_tuples = []
    
    78 98
     
    
    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'
    
    99
    +        if suffixs is None:
    
    100
    +            suffixs = ['', ] * len(kinds)
    
    101
    +        else:
    
    102
    +            if len(suffixs) != len(kinds):
    
    103
    +                raise "terable error"
    
    85 104
     
    
    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)
    
    105
    +        for suffix, kind in zip(suffixs, kinds):
    
    106
    +            element_name, element_path, workspace_dir = \
    
    107
    +                self.create_workspace_element(kind, track, suffix, workspace_dir_usr,
    
    108
    +                                              element_attrs)
    
    93 109
     
    
    94
    -    result.assert_success()
    
    110
    +            # Assert that there is no reference, a track & fetch is needed
    
    111
    +            state = self.cli.get_element_state(self.project_path, element_name)
    
    112
    +            if track:
    
    113
    +                assert state == 'no reference'
    
    114
    +            else:
    
    115
    +                assert state == 'fetch needed'
    
    116
    +            element_tuples.append((element_name, workspace_dir))
    
    95 117
     
    
    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'
    
    118
    +        return element_tuples
    
    99 119
     
    
    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)
    
    120
    +    def open_workspaces(self, kinds, track, suffixs=None, workspace_dir=None,
    
    121
    +                        element_attrs=None):
    
    122
    +
    
    123
    +        element_tuples = self.create_workspace_elements(kinds, track, suffixs, workspace_dir,
    
    124
    +                                                        element_attrs)
    
    125
    +        os.makedirs(self.workspace_cmd, exist_ok=True)
    
    126
    +
    
    127
    +        # Now open the workspace, this should have the effect of automatically
    
    128
    +        # tracking & fetching the source from the repo.
    
    129
    +        args = ['workspace', 'open']
    
    130
    +        if track:
    
    131
    +            args.append('--track')
    
    132
    +        if workspace_dir is not None:
    
    133
    +            assert len(element_tuples) == 1, "test logic error"
    
    134
    +            _, workspace_dir = element_tuples[0]
    
    135
    +            args.extend(['--directory', workspace_dir])
    
    136
    +
    
    137
    +        args.extend([element_name for element_name, workspace_dir_suffix in element_tuples])
    
    138
    +        result = self.cli.run(cwd=self.workspace_cmd, project=self.project_path, args=args)
    
    139
    +
    
    140
    +        result.assert_success()
    
    141
    +
    
    142
    +        for element_name, workspace_dir in element_tuples:
    
    143
    +            # Assert that we are now buildable because the source is
    
    144
    +            # now cached.
    
    145
    +            assert self.cli.get_element_state(self.project_path, element_name) == 'buildable'
    
    146
    +
    
    147
    +            # Check that the executable hello file is found in the workspace
    
    148
    +            filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
    
    149
    +            assert os.path.exists(filename)
    
    150
    +
    
    151
    +        return element_tuples
    
    103 152
     
    
    104
    -    return (element_name, project_path, workspace_dir)
    
    153
    +
    
    154
    +def open_workspace(cli, tmpdir, datafiles, kind, track, suffix='', workspace_dir=None,
    
    155
    +                   project_path=None, element_attrs=None):
    
    156
    +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles, project_path)
    
    157
    +    workspaces = workspace_object.open_workspaces((kind, ), track, (suffix, ), workspace_dir,
    
    158
    +                                                  element_attrs)
    
    159
    +    assert len(workspaces) == 1
    
    160
    +    element_name, workspace = workspaces[0]
    
    161
    +    return element_name, workspace_object.project_path, workspace
    
    105 162
     
    
    106 163
     
    
    107 164
     @pytest.mark.datafiles(DATA_DIR)
    
    ... ... @@ -128,6 +185,128 @@ def test_open_bzr_customize(cli, tmpdir, datafiles):
    128 185
         assert(expected_output_str in str(output))
    
    129 186
     
    
    130 187
     
    
    188
    +@pytest.mark.datafiles(DATA_DIR)
    
    189
    +def test_open_multi(cli, tmpdir, datafiles):
    
    190
    +
    
    191
    +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
    
    192
    +    workspaces = workspace_object.open_workspaces(repo_kinds, False)
    
    193
    +
    
    194
    +    for (elname, workspace), kind in zip(workspaces, repo_kinds):
    
    195
    +        assert kind in elname
    
    196
    +        workspace_lsdir = os.listdir(workspace)
    
    197
    +        if kind == 'git':
    
    198
    +            assert('.git' in workspace_lsdir)
    
    199
    +        elif kind == 'bzr':
    
    200
    +            assert('.bzr' in workspace_lsdir)
    
    201
    +        else:
    
    202
    +            assert not ('.git' in workspace_lsdir)
    
    203
    +            assert not ('.bzr' in workspace_lsdir)
    
    204
    +
    
    205
    +
    
    206
    +@pytest.mark.datafiles(DATA_DIR)
    
    207
    +def test_open_multi_unwritable(cli, tmpdir, datafiles):
    
    208
    +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
    
    209
    +
    
    210
    +    element_tuples = workspace_object.create_workspace_elements(repo_kinds, False, repo_kinds)
    
    211
    +    os.makedirs(workspace_object.workspace_cmd, exist_ok=True)
    
    212
    +
    
    213
    +    # Now open the workspace, this should have the effect of automatically
    
    214
    +    # tracking & fetching the source from the repo.
    
    215
    +    args = ['workspace', 'open']
    
    216
    +    args.extend([element_name for element_name, workspace_dir_suffix in element_tuples])
    
    217
    +    cli.configure({'workspacedir': workspace_object.workspace_cmd})
    
    218
    +
    
    219
    +    cwdstat = os.stat(workspace_object.workspace_cmd)
    
    220
    +    try:
    
    221
    +        os.chmod(workspace_object.workspace_cmd, cwdstat.st_mode - stat.S_IWRITE)
    
    222
    +        result = workspace_object.cli.run(project=workspace_object.project_path, args=args)
    
    223
    +    finally:
    
    224
    +        # Using this finally to make sure we always put thing back how they should be.
    
    225
    +        os.chmod(workspace_object.workspace_cmd, cwdstat.st_mode)
    
    226
    +
    
    227
    +    result.assert_main_error(ErrorDomain.STREAM, None)
    
    228
    +    # Normally we avoid checking stderr in favour of using the mechine readable result.assert_main_error
    
    229
    +    # But Tristan was very keen that the names of the elements left needing workspaces were present in the out put
    
    230
    +    assert (" ".join([element_name for element_name, workspace_dir_suffix in element_tuples[1:]]) in result.stderr)
    
    231
    +
    
    232
    +
    
    233
    +@pytest.mark.datafiles(DATA_DIR)
    
    234
    +def test_open_multi_with_directory(cli, tmpdir, datafiles):
    
    235
    +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
    
    236
    +
    
    237
    +    element_tuples = workspace_object.create_workspace_elements(repo_kinds, False, repo_kinds)
    
    238
    +    os.makedirs(workspace_object.workspace_cmd, exist_ok=True)
    
    239
    +
    
    240
    +    # Now open the workspace, this should have the effect of automatically
    
    241
    +    # tracking & fetching the source from the repo.
    
    242
    +    args = ['workspace', 'open']
    
    243
    +    args.extend(['--directory', 'any/dir/should/fail'])
    
    244
    +
    
    245
    +    args.extend([element_name for element_name, workspace_dir_suffix in element_tuples])
    
    246
    +    result = workspace_object.cli.run(cwd=workspace_object.workspace_cmd, project=workspace_object.project_path,
    
    247
    +                                      args=args)
    
    248
    +
    
    249
    +    result.assert_main_error(ErrorDomain.STREAM, 'directory-with-multiple-elements')
    
    250
    +
    
    251
    +
    
    252
    +@pytest.mark.datafiles(DATA_DIR)
    
    253
    +def test_open_defaultlocation(cli, tmpdir, datafiles):
    
    254
    +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
    
    255
    +
    
    256
    +    ((element_name, workspace_dir), ) = workspace_object.create_workspace_elements(['git'], False, ['git'])
    
    257
    +    os.makedirs(workspace_object.workspace_cmd, exist_ok=True)
    
    258
    +
    
    259
    +    # Now open the workspace, this should have the effect of automatically
    
    260
    +    # tracking & fetching the source from the repo.
    
    261
    +    args = ['workspace', 'open']
    
    262
    +    args.append(element_name)
    
    263
    +
    
    264
    +    # In the other tests we set the cmd to workspace_object.workspace_cmd with the optional
    
    265
    +    # argument, cwd for the workspace_object.cli.run function. But hear we set the default
    
    266
    +    # workspace location to workspace_object.workspace_cmd and run the cli.run function with
    
    267
    +    # no cwd option so that it runs in the project directory.
    
    268
    +    cli.configure({'workspacedir': workspace_object.workspace_cmd})
    
    269
    +    result = workspace_object.cli.run(project=workspace_object.project_path,
    
    270
    +                                      args=args)
    
    271
    +
    
    272
    +    result.assert_success()
    
    273
    +
    
    274
    +    assert cli.get_element_state(workspace_object.project_path, element_name) == 'buildable'
    
    275
    +
    
    276
    +    # Check that the executable hello file is found in the workspace
    
    277
    +    # even though the cli.run function was not run with cwd = workspace_object.workspace_cmd
    
    278
    +    # the workspace should be created in there as we used the 'workspacedir' configuration
    
    279
    +    # option.
    
    280
    +    filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello')
    
    281
    +    assert os.path.exists(filename)
    
    282
    +
    
    283
    +
    
    284
    +@pytest.mark.datafiles(DATA_DIR)
    
    285
    +def test_open_defaultlocation_exists(cli, tmpdir, datafiles):
    
    286
    +    workspace_object = WorkspaceCreater(cli, tmpdir, datafiles)
    
    287
    +
    
    288
    +    ((element_name, workspace_dir), ) = workspace_object.create_workspace_elements(['git'], False, ['git'])
    
    289
    +    os.makedirs(workspace_object.workspace_cmd, exist_ok=True)
    
    290
    +
    
    291
    +    with open(workspace_dir, 'w') as fl:
    
    292
    +        fl.write('foo')
    
    293
    +
    
    294
    +    # Now open the workspace, this should have the effect of automatically
    
    295
    +    # tracking & fetching the source from the repo.
    
    296
    +    args = ['workspace', 'open']
    
    297
    +    args.append(element_name)
    
    298
    +
    
    299
    +    # In the other tests we set the cmd to workspace_object.workspace_cmd with the optional
    
    300
    +    # argument, cwd for the workspace_object.cli.run function. But hear we set the default
    
    301
    +    # workspace location to workspace_object.workspace_cmd and run the cli.run function with
    
    302
    +    # no cwd option so that it runs in the project directory.
    
    303
    +    cli.configure({'workspacedir': workspace_object.workspace_cmd})
    
    304
    +    result = workspace_object.cli.run(project=workspace_object.project_path,
    
    305
    +                                      args=args)
    
    306
    +
    
    307
    +    result.assert_main_error(ErrorDomain.STREAM, 'bad-directory')
    
    308
    +
    
    309
    +
    
    131 310
     @pytest.mark.datafiles(DATA_DIR)
    
    132 311
     @pytest.mark.parametrize("kind", repo_kinds)
    
    133 312
     def test_open_track(cli, tmpdir, datafiles, kind):
    
    ... ... @@ -150,7 +329,7 @@ def test_open_force(cli, tmpdir, datafiles, kind):
    150 329
     
    
    151 330
         # Now open the workspace again with --force, this should happily succeed
    
    152 331
         result = cli.run(project=project, args=[
    
    153
    -        'workspace', 'open', '--force', element_name, workspace
    
    332
    +        'workspace', 'open', '--force', '--directory', workspace, element_name
    
    154 333
         ])
    
    155 334
         result.assert_success()
    
    156 335
     
    
    ... ... @@ -165,7 +344,7 @@ def test_open_force_open(cli, tmpdir, datafiles, kind):
    165 344
     
    
    166 345
         # Now open the workspace again with --force, this should happily succeed
    
    167 346
         result = cli.run(project=project, args=[
    
    168
    -        'workspace', 'open', '--force', element_name, workspace
    
    347
    +        'workspace', 'open', '--force', '--directory', workspace, element_name
    
    169 348
         ])
    
    170 349
         result.assert_success()
    
    171 350
     
    
    ... ... @@ -196,7 +375,7 @@ def test_open_force_different_workspace(cli, tmpdir, datafiles, kind):
    196 375
     
    
    197 376
         # Now open the workspace again with --force, this should happily succeed
    
    198 377
         result = cli.run(project=project, args=[
    
    199
    -        'workspace', 'open', '--force', element_name2, workspace
    
    378
    +        'workspace', 'open', '--force', '--directory', workspace, element_name2
    
    200 379
         ])
    
    201 380
     
    
    202 381
         # Assert that the file in workspace 1 has been replaced
    
    ... ... @@ -504,7 +683,7 @@ def test_buildable_no_ref(cli, tmpdir, datafiles):
    504 683
         # Now open the workspace. We don't need to checkout the source though.
    
    505 684
         workspace = os.path.join(str(tmpdir), 'workspace-no-ref')
    
    506 685
         os.makedirs(workspace)
    
    507
    -    args = ['workspace', 'open', '--no-checkout', element_name, workspace]
    
    686
    +    args = ['workspace', 'open', '--no-checkout', '--directory', workspace, element_name]
    
    508 687
         result = cli.run(project=project, args=args)
    
    509 688
         result.assert_success()
    
    510 689
     
    
    ... ... @@ -766,7 +945,7 @@ def test_list_supported_workspace(cli, tmpdir, datafiles, workspace_cfg, expecte
    766 945
                                 element_name))
    
    767 946
     
    
    768 947
         # Make a change to the workspaces file
    
    769
    -    result = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
    
    948
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace, element_name])
    
    770 949
         result.assert_success()
    
    771 950
         result = cli.run(project=project, args=['workspace', 'close', '--remove-dir', element_name])
    
    772 951
         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
    

  • 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,19 +108,28 @@ 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"))
    
    115 115
         assert os.path.exists(os.path.join(workspace_dir, "baz"))
    
    116 116
     
    
    117 117
     
    
    118
    +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
    
    119
    +def test_filter_workspace_open_multi(datafiles, cli, tmpdir):
    
    120
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    121
    +    result = cli.run(cwd=project, project=project, args=['workspace', 'open', 'deps-permitted.bst',
    
    122
    +                                                         'output-orphans.bst'])
    
    123
    +    result.assert_success()
    
    124
    +    assert os.path.exists(os.path.join(project, "input"))
    
    125
    +
    
    126
    +
    
    118 127
     @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
    
    119 128
     def test_filter_workspace_build(datafiles, cli, tmpdir):
    
    120 129
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    121 130
         tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
    
    122 131
         workspace_dir = os.path.join(tempdir, "workspace")
    
    123
    -    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
    
    132
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'output-orphans.bst'])
    
    124 133
         result.assert_success()
    
    125 134
         src = os.path.join(workspace_dir, "foo")
    
    126 135
         dst = os.path.join(workspace_dir, "quux")
    
    ... ... @@ -138,7 +147,7 @@ def test_filter_workspace_close(datafiles, cli, tmpdir):
    138 147
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    139 148
         tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
    
    140 149
         workspace_dir = os.path.join(tempdir, "workspace")
    
    141
    -    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
    
    150
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'output-orphans.bst'])
    
    142 151
         result.assert_success()
    
    143 152
         src = os.path.join(workspace_dir, "foo")
    
    144 153
         dst = os.path.join(workspace_dir, "quux")
    
    ... ... @@ -158,7 +167,7 @@ def test_filter_workspace_reset(datafiles, cli, tmpdir):
    158 167
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    159 168
         tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
    
    160 169
         workspace_dir = os.path.join(tempdir, "workspace")
    
    161
    -    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
    
    170
    +    result = cli.run(project=project, args=['workspace', 'open', '--directory', workspace_dir, 'output-orphans.bst'])
    
    162 171
         result.assert_success()
    
    163 172
         src = os.path.join(workspace_dir, "foo")
    
    164 173
         dst = os.path.join(workspace_dir, "quux")
    



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