[Notes] [Git][BuildStream/buildstream][jonathan/workspace-fragment-guess-element] 19 commits: Fix bst source-checkout not working with open workspaces



Title: GitLab

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

Commits:

15 changed files:

Changes:

  • NEWS
    ... ... @@ -79,6 +79,15 @@ buildstream 1.3.1
    79 79
         plugin has now a tag tracking feature instead. This can be enabled
    
    80 80
         by setting 'track-tags'.
    
    81 81
     
    
    82
    +  o Opening a workspace now creates a .bstproject.yaml file that allows buildstream
    
    83
    +    commands to be run from a workspace that is not inside a project.
    
    84
    +
    
    85
    +  o Specifying an element is now optional for some commands when buildstream is run
    
    86
    +    from inside a workspace - the 'build', 'checkout', 'fetch', 'pull', 'push',
    
    87
    +    'shell', 'show', 'source-checkout', 'track', 'workspace close' and 'workspace reset'
    
    88
    +    commands are affected.
    
    89
    +
    
    90
    +
    
    82 91
     =================
    
    83 92
     buildstream 1.1.5
    
    84 93
     =================
    

  • buildstream/_context.py
    ... ... @@ -32,7 +32,7 @@ from ._message import Message, MessageType
    32 32
     from ._profile import Topics, profile_start, profile_end
    
    33 33
     from ._artifactcache import ArtifactCache
    
    34 34
     from ._artifactcache.cascache import CASCache
    
    35
    -from ._workspaces import Workspaces
    
    35
    +from ._workspaces import Workspaces, WorkspaceProjectCache
    
    36 36
     from .plugin import _plugin_lookup
    
    37 37
     
    
    38 38
     
    
    ... ... @@ -47,9 +47,12 @@ from .plugin import _plugin_lookup
    47 47
     # verbosity levels and basically anything pertaining to the context
    
    48 48
     # in which BuildStream was invoked.
    
    49 49
     #
    
    50
    +# Args:
    
    51
    +#    directory (str): The directory that buildstream was invoked in
    
    52
    +#
    
    50 53
     class Context():
    
    51 54
     
    
    52
    -    def __init__(self):
    
    55
    +    def __init__(self, directory=None):
    
    53 56
     
    
    54 57
             # Filename indicating which configuration file was used, or None for the defaults
    
    55 58
             self.config_origin = None
    
    ... ... @@ -122,6 +125,10 @@ class Context():
    122 125
             # remove a workspace directory.
    
    123 126
             self.prompt_workspace_close_remove_dir = None
    
    124 127
     
    
    128
    +        # Boolean, whether we double-check with the user that they meant to
    
    129
    +        # close the workspace when they're using it to access the project.
    
    130
    +        self.prompt_workspace_close_project_inaccessible = None
    
    131
    +
    
    125 132
             # Boolean, whether we double-check with the user that they meant to do
    
    126 133
             # a hard reset of a workspace, potentially losing changes.
    
    127 134
             self.prompt_workspace_reset_hard = None
    
    ... ... @@ -140,9 +147,11 @@ class Context():
    140 147
             self._projects = []
    
    141 148
             self._project_overrides = {}
    
    142 149
             self._workspaces = None
    
    150
    +        self._workspace_project_cache = WorkspaceProjectCache()
    
    143 151
             self._log_handle = None
    
    144 152
             self._log_filename = None
    
    145 153
             self._cascache = None
    
    154
    +        self._directory = directory
    
    146 155
     
    
    147 156
         # load()
    
    148 157
         #
    
    ... ... @@ -250,12 +259,15 @@ class Context():
    250 259
                 defaults, Mapping, 'prompt')
    
    251 260
             _yaml.node_validate(prompt, [
    
    252 261
                 'auto-init', 'really-workspace-close-remove-dir',
    
    262
    +            'really-workspace-close-project-inaccessible',
    
    253 263
                 'really-workspace-reset-hard',
    
    254 264
             ])
    
    255 265
             self.prompt_auto_init = _node_get_option_str(
    
    256 266
                 prompt, 'auto-init', ['ask', 'no']) == 'ask'
    
    257 267
             self.prompt_workspace_close_remove_dir = _node_get_option_str(
    
    258 268
                 prompt, 'really-workspace-close-remove-dir', ['ask', 'yes']) == 'ask'
    
    269
    +        self.prompt_workspace_close_project_inaccessible = _node_get_option_str(
    
    270
    +            prompt, 'really-workspace-close-project-inaccessible', ['ask', 'yes']) == 'ask'
    
    259 271
             self.prompt_workspace_reset_hard = _node_get_option_str(
    
    260 272
                 prompt, 'really-workspace-reset-hard', ['ask', 'yes']) == 'ask'
    
    261 273
     
    
    ... ... @@ -285,7 +297,7 @@ class Context():
    285 297
         #
    
    286 298
         def add_project(self, project):
    
    287 299
             if not self._projects:
    
    288
    -            self._workspaces = Workspaces(project)
    
    300
    +            self._workspaces = Workspaces(project, self._workspace_project_cache)
    
    289 301
             self._projects.append(project)
    
    290 302
     
    
    291 303
         # get_projects():
    
    ... ... @@ -312,6 +324,16 @@ class Context():
    312 324
         def get_workspaces(self):
    
    313 325
             return self._workspaces
    
    314 326
     
    
    327
    +    # get_workspace_project_cache():
    
    328
    +    #
    
    329
    +    # Return the WorkspaceProjectCache object used for this BuildStream invocation
    
    330
    +    #
    
    331
    +    # Returns:
    
    332
    +    #    (WorkspaceProjectCache): The WorkspaceProjectCache object
    
    333
    +    #
    
    334
    +    def get_workspace_project_cache(self):
    
    335
    +        return self._workspace_project_cache
    
    336
    +
    
    315 337
         # get_overrides():
    
    316 338
         #
    
    317 339
         # Fetch the override dictionary for the active project. This returns
    
    ... ... @@ -627,6 +649,19 @@ class Context():
    627 649
                 self._cascache = CASCache(self.artifactdir)
    
    628 650
             return self._cascache
    
    629 651
     
    
    652
    +    # guess_element()
    
    653
    +    #
    
    654
    +    # Attempts to interpret which element the user intended to run commands on
    
    655
    +    #
    
    656
    +    # Returns:
    
    657
    +    #    (str) The name of the element, or None if no element can be guessed
    
    658
    +    def guess_element(self):
    
    659
    +        workspace_project = self._workspace_project_cache.get(self._directory)
    
    660
    +        if workspace_project:
    
    661
    +            return workspace_project.get_default_element()
    
    662
    +        else:
    
    663
    +            return None
    
    664
    +
    
    630 665
     
    
    631 666
     # _node_get_option_str()
    
    632 667
     #
    

  • buildstream/_frontend/app.py
    ... ... @@ -164,7 +164,7 @@ class App():
    164 164
             # Load the Context
    
    165 165
             #
    
    166 166
             try:
    
    167
    -            self.context = Context()
    
    167
    +            self.context = Context(directory)
    
    168 168
                 self.context.load(config)
    
    169 169
             except BstError as e:
    
    170 170
                 self._error_exit(e, "Error loading user configuration")
    

  • buildstream/_frontend/cli.py
    ... ... @@ -59,18 +59,9 @@ def complete_target(args, incomplete):
    59 59
         :return: all the possible user-specified completions for the param
    
    60 60
         """
    
    61 61
     
    
    62
    +    from .. import utils
    
    62 63
         project_conf = 'project.conf'
    
    63 64
     
    
    64
    -    def ensure_project_dir(directory):
    
    65
    -        directory = os.path.abspath(directory)
    
    66
    -        while not os.path.isfile(os.path.join(directory, project_conf)):
    
    67
    -            parent_dir = os.path.dirname(directory)
    
    68
    -            if directory == parent_dir:
    
    69
    -                break
    
    70
    -            directory = parent_dir
    
    71
    -
    
    72
    -        return directory
    
    73
    -
    
    74 65
         # First resolve the directory, in case there is an
    
    75 66
         # active --directory/-C option
    
    76 67
         #
    
    ... ... @@ -89,7 +80,7 @@ def complete_target(args, incomplete):
    89 80
         else:
    
    90 81
             # Check if this directory or any of its parent directories
    
    91 82
             # contain a project config file
    
    92
    -        base_directory = ensure_project_dir(base_directory)
    
    83
    +        base_directory = utils._search_upward_for_file(base_directory, project_conf)
    
    93 84
     
    
    94 85
         # Now parse the project.conf just to find the element path,
    
    95 86
         # this is unfortunately a bit heavy.
    
    ... ... @@ -325,10 +316,15 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac
    325 316
         if track_save:
    
    326 317
             click.echo("WARNING: --track-save is deprecated, saving is now unconditional", err=True)
    
    327 318
     
    
    328
    -    if track_all:
    
    329
    -        track_ = elements
    
    330
    -
    
    331 319
         with app.initialized(session_name="Build"):
    
    320
    +        if not all_ and not elements:
    
    321
    +            guessed_target = app.context.guess_element()
    
    322
    +            if guessed_target:
    
    323
    +                elements = (guessed_target,)
    
    324
    +
    
    325
    +        if track_all:
    
    326
    +            track_ = elements
    
    327
    +
    
    332 328
             app.stream.build(elements,
    
    333 329
                              track_targets=track_,
    
    334 330
                              track_except=track_except,
    
    ... ... @@ -380,6 +376,11 @@ def fetch(app, elements, deps, track_, except_, track_cross_junctions):
    380 376
             deps = PipelineSelection.ALL
    
    381 377
     
    
    382 378
         with app.initialized(session_name="Fetch"):
    
    379
    +        if not elements:
    
    380
    +            guessed_target = app.context.guess_element()
    
    381
    +            if guessed_target:
    
    382
    +                elements = (guessed_target,)
    
    383
    +
    
    383 384
             app.stream.fetch(elements,
    
    384 385
                              selection=deps,
    
    385 386
                              except_targets=except_,
    
    ... ... @@ -416,6 +417,11 @@ def track(app, elements, deps, except_, cross_junctions):
    416 417
             all:   All dependencies of all specified elements
    
    417 418
         """
    
    418 419
         with app.initialized(session_name="Track"):
    
    420
    +        if not elements:
    
    421
    +            guessed_target = app.context.guess_element()
    
    422
    +            if guessed_target:
    
    423
    +                elements = (guessed_target,)
    
    424
    +
    
    419 425
             # Substitute 'none' for 'redirect' so that element redirections
    
    420 426
             # will be done
    
    421 427
             if deps == 'none':
    
    ... ... @@ -451,7 +457,13 @@ def pull(app, elements, deps, remote):
    451 457
             none:  No dependencies, just the element itself
    
    452 458
             all:   All dependencies
    
    453 459
         """
    
    460
    +
    
    454 461
         with app.initialized(session_name="Pull"):
    
    462
    +        if not elements:
    
    463
    +            guessed_target = app.context.guess_element()
    
    464
    +            if guessed_target:
    
    465
    +                elements = (guessed_target,)
    
    466
    +
    
    455 467
             app.stream.pull(elements, selection=deps, remote=remote)
    
    456 468
     
    
    457 469
     
    
    ... ... @@ -484,6 +496,11 @@ def push(app, elements, deps, remote):
    484 496
             all:   All dependencies
    
    485 497
         """
    
    486 498
         with app.initialized(session_name="Push"):
    
    499
    +        if not elements:
    
    500
    +            guessed_target = app.context.guess_element()
    
    501
    +            if guessed_target:
    
    502
    +                elements = (guessed_target,)
    
    503
    +
    
    487 504
             app.stream.push(elements, selection=deps, remote=remote)
    
    488 505
     
    
    489 506
     
    
    ... ... @@ -554,6 +571,11 @@ def show(app, elements, deps, except_, order, format_):
    554 571
                 $'---------- %{name} ----------\\n%{vars}'
    
    555 572
         """
    
    556 573
         with app.initialized():
    
    574
    +        if not elements:
    
    575
    +            guessed_target = app.context.guess_element()
    
    576
    +            if guessed_target:
    
    577
    +                elements = (guessed_target,)
    
    578
    +
    
    557 579
             dependencies = app.stream.load_selection(elements,
    
    558 580
                                                      selection=deps,
    
    559 581
                                                      except_targets=except_)
    
    ... ... @@ -582,7 +604,7 @@ def show(app, elements, deps, except_, order, format_):
    582 604
                   help="Mount a file or directory into the sandbox")
    
    583 605
     @click.option('--isolate', is_flag=True, default=False,
    
    584 606
                   help='Create an isolated build sandbox')
    
    585
    -@click.argument('element',
    
    607
    +@click.argument('element', required=False,
    
    586 608
                     type=click.Path(readable=False))
    
    587 609
     @click.argument('command', type=click.STRING, nargs=-1)
    
    588 610
     @click.pass_obj
    
    ... ... @@ -613,6 +635,11 @@ def shell(app, element, sysroot, mount, isolate, build_, command):
    613 635
             scope = Scope.RUN
    
    614 636
     
    
    615 637
         with app.initialized():
    
    638
    +        if not element:
    
    639
    +            element = app.context.guess_element()
    
    640
    +            if not element:
    
    641
    +                raise AppError('Missing argument "ELEMENT".')
    
    642
    +
    
    616 643
             dependencies = app.stream.load_selection((element,), selection=PipelineSelection.NONE)
    
    617 644
             element = dependencies[0]
    
    618 645
             prompt = app.shell_prompt(element)
    
    ... ... @@ -650,15 +677,24 @@ def shell(app, element, sysroot, mount, isolate, build_, command):
    650 677
                   help="Create a tarball from the artifact contents instead "
    
    651 678
                        "of a file tree. If LOCATION is '-', the tarball "
    
    652 679
                        "will be dumped to the standard output.")
    
    653
    -@click.argument('element',
    
    680
    +@click.argument('element', required=False,
    
    654 681
                     type=click.Path(readable=False))
    
    655
    -@click.argument('location', type=click.Path())
    
    682
    +@click.argument('location', type=click.Path(), required=False)
    
    656 683
     @click.pass_obj
    
    657 684
     def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
    
    658 685
         """Checkout a built artifact to the specified location
    
    659 686
         """
    
    660 687
         from ..element import Scope
    
    661 688
     
    
    689
    +    if not element and not location:
    
    690
    +        click.echo("ERROR: LOCATION is not specified", err=True)
    
    691
    +        sys.exit(-1)
    
    692
    +
    
    693
    +    if element and not location:
    
    694
    +        # Nasty hack to get around click's optional args
    
    695
    +        location = element
    
    696
    +        element = None
    
    697
    +
    
    662 698
         if hardlinks and tar:
    
    663 699
             click.echo("ERROR: options --hardlinks and --tar conflict", err=True)
    
    664 700
             sys.exit(-1)
    
    ... ... @@ -671,6 +707,11 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
    671 707
             scope = Scope.NONE
    
    672 708
     
    
    673 709
         with app.initialized():
    
    710
    +        if not element:
    
    711
    +            element = app.context.guess_element()
    
    712
    +            if not element:
    
    713
    +                raise AppError('Missing argument "ELEMENT".')
    
    714
    +
    
    674 715
             app.stream.checkout(element,
    
    675 716
                                 location=location,
    
    676 717
                                 force=force,
    
    ... ... @@ -692,14 +733,28 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
    692 733
                   help='The dependencies whose sources to checkout (default: none)')
    
    693 734
     @click.option('--fetch', 'fetch_', default=False, is_flag=True,
    
    694 735
                   help='Fetch elements if they are not fetched')
    
    695
    -@click.argument('element',
    
    736
    +@click.argument('element', required=False,
    
    696 737
                     type=click.Path(readable=False))
    
    697
    -@click.argument('location', type=click.Path())
    
    738
    +@click.argument('location', type=click.Path(), required=False)
    
    698 739
     @click.pass_obj
    
    699 740
     def source_checkout(app, element, location, deps, fetch_, except_):
    
    700 741
         """Checkout sources of an element to the specified location
    
    701 742
         """
    
    743
    +    if not element and not location:
    
    744
    +        click.echo("ERROR: LOCATION is not specified", err=True)
    
    745
    +        sys.exit(-1)
    
    746
    +
    
    747
    +    if element and not location:
    
    748
    +        # Nasty hack to get around click's optional args
    
    749
    +        location = element
    
    750
    +        element = None
    
    751
    +
    
    702 752
         with app.initialized():
    
    753
    +        if not element:
    
    754
    +            element = app.context.guess_element()
    
    755
    +            if not element:
    
    756
    +                raise AppError('Missing argument "ELEMENT".')
    
    757
    +
    
    703 758
             app.stream.source_checkout(element,
    
    704 759
                                        location=location,
    
    705 760
                                        deps=deps,
    
    ... ... @@ -756,11 +811,15 @@ def workspace_open(app, no_checkout, force, track_, directory, elements):
    756 811
     def workspace_close(app, remove_dir, all_, elements):
    
    757 812
         """Close a workspace"""
    
    758 813
     
    
    759
    -    if not (all_ or elements):
    
    760
    -        click.echo('ERROR: no elements specified', err=True)
    
    761
    -        sys.exit(-1)
    
    762
    -
    
    763 814
         with app.initialized():
    
    815
    +        if not (all_ or elements):
    
    816
    +            # NOTE: I may need to revisit this when implementing multiple projects
    
    817
    +            # opening one workspace.
    
    818
    +            element = app.context.guess_element()
    
    819
    +            if element:
    
    820
    +                elements = (element,)
    
    821
    +            else:
    
    822
    +                raise AppError('No elements specified')
    
    764 823
     
    
    765 824
             # Early exit if we specified `all` and there are no workspaces
    
    766 825
             if all_ and not app.stream.workspace_exists():
    
    ... ... @@ -772,11 +831,18 @@ def workspace_close(app, remove_dir, all_, elements):
    772 831
     
    
    773 832
             elements = app.stream.redirect_element_names(elements)
    
    774 833
     
    
    775
    -        # Check that the workspaces in question exist
    
    834
    +        # Check that the workspaces in question exist, and that it's safe to
    
    835
    +        # remove them.
    
    776 836
             nonexisting = []
    
    777 837
             for element_name in elements:
    
    778 838
                 if not app.stream.workspace_exists(element_name):
    
    779 839
                     nonexisting.append(element_name)
    
    840
    +            if (app.stream.workspace_is_required(element_name) and app.interactive and
    
    841
    +                    app.context.prompt_workspace_close_project_inaccessible):
    
    842
    +                click.echo("Removing '{}' will prevent you from running buildstream commands".format(element_name))
    
    843
    +                if not click.confirm('Are you sure you want to close this workspace?'):
    
    844
    +                    click.echo('Aborting', err=True)
    
    845
    +                    sys.exit(-1)
    
    780 846
             if nonexisting:
    
    781 847
                 raise AppError("Workspace does not exist", detail="\n".join(nonexisting))
    
    782 848
     
    
    ... ... @@ -809,7 +875,11 @@ def workspace_reset(app, soft, track_, all_, elements):
    809 875
         with app.initialized():
    
    810 876
     
    
    811 877
             if not (all_ or elements):
    
    812
    -            raise AppError('No elements specified to reset')
    
    878
    +            element = app.context.guess_element()
    
    879
    +            if element:
    
    880
    +                elements = (element,)
    
    881
    +            else:
    
    882
    +                raise AppError('No elements specified to reset')
    
    813 883
     
    
    814 884
             if all_ and not app.stream.workspace_exists():
    
    815 885
                 raise AppError("No open workspaces to reset")
    

  • buildstream/_project.py
    ... ... @@ -95,8 +95,10 @@ class Project():
    95 95
             # The project name
    
    96 96
             self.name = None
    
    97 97
     
    
    98
    -        # The project directory
    
    99
    -        self.directory = self._ensure_project_dir(directory)
    
    98
    +        self._context = context  # The invocation Context, a private member
    
    99
    +
    
    100
    +        # The project directory, and whether the project was found from an external workspace
    
    101
    +        self.directory, self._required_workspace_element = self._find_project_dir(directory)
    
    100 102
     
    
    101 103
             # Absolute path to where elements are loaded from within the project
    
    102 104
             self.element_path = None
    
    ... ... @@ -117,7 +119,6 @@ class Project():
    117 119
             #
    
    118 120
             # Private Members
    
    119 121
             #
    
    120
    -        self._context = context  # The invocation Context
    
    121 122
     
    
    122 123
             self._default_mirror = default_mirror    # The name of the preferred mirror.
    
    123 124
     
    
    ... ... @@ -371,6 +372,14 @@ class Project():
    371 372
     
    
    372 373
             self._load_second_pass()
    
    373 374
     
    
    375
    +    # required_workspace_element()
    
    376
    +    #
    
    377
    +    # Returns the element whose workspace is required to load this project,
    
    378
    +    # if any.
    
    379
    +    #
    
    380
    +    def required_workspace_element(self):
    
    381
    +        return self._required_workspace_element
    
    382
    +
    
    374 383
         # cleanup()
    
    375 384
         #
    
    376 385
         # Cleans up resources used loading elements
    
    ... ... @@ -650,7 +659,7 @@ class Project():
    650 659
             # Source url aliases
    
    651 660
             output._aliases = _yaml.node_get(config, Mapping, 'aliases', default_value={})
    
    652 661
     
    
    653
    -    # _ensure_project_dir()
    
    662
    +    # _find_project_dir()
    
    654 663
         #
    
    655 664
         # Returns path of the project directory, if a configuration file is found
    
    656 665
         # in given directory or any of its parent directories.
    
    ... ... @@ -661,18 +670,26 @@ class Project():
    661 670
         # Raises:
    
    662 671
         #    LoadError if project.conf is not found
    
    663 672
         #
    
    664
    -    def _ensure_project_dir(self, directory):
    
    665
    -        directory = os.path.abspath(directory)
    
    666
    -        while not os.path.isfile(os.path.join(directory, _PROJECT_CONF_FILE)):
    
    667
    -            parent_dir = os.path.dirname(directory)
    
    668
    -            if directory == parent_dir:
    
    673
    +    # Returns:
    
    674
    +    #    (str) - the directory that contains the project, and
    
    675
    +    #    (str) - the name of the element required to find the project, or an empty string
    
    676
    +    #
    
    677
    +    def _find_project_dir(self, directory):
    
    678
    +        workspace_element = ""
    
    679
    +        project_directory = utils._search_upward_for_file(directory, _PROJECT_CONF_FILE)
    
    680
    +        if not project_directory:
    
    681
    +            workspace_project_cache = self._context.get_workspace_project_cache()
    
    682
    +            workspace_project = workspace_project_cache.get(directory)
    
    683
    +            if workspace_project:
    
    684
    +                project_directory = workspace_project.get_default_project_path()
    
    685
    +                workspace_element = workspace_project.get_default_element()
    
    686
    +            else:
    
    669 687
                     raise LoadError(
    
    670 688
                         LoadErrorReason.MISSING_PROJECT_CONF,
    
    671 689
                         '{} not found in current directory or any of its parent directories'
    
    672 690
                         .format(_PROJECT_CONF_FILE))
    
    673
    -            directory = parent_dir
    
    674 691
     
    
    675
    -        return directory
    
    692
    +        return project_directory, workspace_element
    
    676 693
     
    
    677 694
         def _load_plugin_factories(self, config, output):
    
    678 695
             plugin_source_origins = []   # Origins of custom sources
    

  • buildstream/_stream.py
    ... ... @@ -544,7 +544,8 @@ class Stream():
    544 544
                 if len(elements) != 1:
    
    545 545
                     raise StreamError("Exactly one element can be given if --directory is used",
    
    546 546
                                       reason='directory-with-multiple-elements')
    
    547
    -            expanded_directories = [custom_dir, ]
    
    547
    +            directory = os.path.abspath(custom_dir)
    
    548
    +            expanded_directories = [directory, ]
    
    548 549
             else:
    
    549 550
                 # If this fails it is a bug in what ever calls this, usually cli.py and so can not be tested for via the
    
    550 551
                 # run bst test mechanism.
    
    ... ... @@ -581,15 +582,7 @@ class Stream():
    581 582
                         todo_elements = "\nDid not try to create workspaces for " + todo_elements
    
    582 583
                     raise StreamError("Failed to create workspace directory: {}".format(e) + todo_elements) from e
    
    583 584
     
    
    584
    -            workspaces.create_workspace(target._get_full_name(), directory)
    
    585
    -
    
    586
    -            if not no_checkout:
    
    587
    -                with target.timed_activity("Staging sources to {}".format(directory)):
    
    588
    -                    target._open_workspace()
    
    589
    -
    
    590
    -            # Saving the workspace once it is set up means that if the next workspace fails to be created before
    
    591
    -            # the configuration gets saved. The successfully created workspace still gets saved.
    
    592
    -            workspaces.save_config()
    
    585
    +            workspaces.create_workspace(target, directory, not no_checkout)
    
    593 586
                 self._message(MessageType.INFO, "Created a workspace for element: {}"
    
    594 587
                               .format(target._get_full_name()))
    
    595 588
     
    
    ... ... @@ -672,10 +665,7 @@ class Stream():
    672 665
                                           .format(workspace_path, e)) from e
    
    673 666
     
    
    674 667
                 workspaces.delete_workspace(element._get_full_name())
    
    675
    -            workspaces.create_workspace(element._get_full_name(), workspace_path)
    
    676
    -
    
    677
    -            with element.timed_activity("Staging sources to {}".format(workspace_path)):
    
    678
    -                element._open_workspace()
    
    668
    +            workspaces.create_workspace(element, workspace_path, True)
    
    679 669
     
    
    680 670
                 self._message(MessageType.INFO,
    
    681 671
                               "Reset workspace for {} at: {}".format(element.name,
    
    ... ... @@ -707,6 +697,20 @@ class Stream():
    707 697
     
    
    708 698
             return False
    
    709 699
     
    
    700
    +    # workspace_is_required()
    
    701
    +    #
    
    702
    +    # Checks whether the workspace belonging to element_name is required to
    
    703
    +    # load the project
    
    704
    +    #
    
    705
    +    # Args:
    
    706
    +    #    element_name (str): The element whose workspace may be required
    
    707
    +    #
    
    708
    +    # Returns:
    
    709
    +    #    (bool): True if the workspace is required
    
    710
    +    def workspace_is_required(self, element_name):
    
    711
    +        required_elm = self._project.required_workspace_element()
    
    712
    +        return required_elm == element_name
    
    713
    +
    
    710 714
         # workspace_list
    
    711 715
         #
    
    712 716
         # Serializes the workspaces and dumps them in YAML to stdout.
    
    ... ... @@ -1199,7 +1203,7 @@ class Stream():
    1199 1203
                 element_source_dir = self._get_element_dirname(directory, element)
    
    1200 1204
                 if list(element.sources()):
    
    1201 1205
                     os.makedirs(element_source_dir)
    
    1202
    -                element._stage_sources_at(element_source_dir)
    
    1206
    +                element._stage_sources_at(element_source_dir, mount_workspaces=False)
    
    1203 1207
     
    
    1204 1208
         # Write a master build script to the sandbox
    
    1205 1209
         def _write_build_script(self, directory, elements):
    

  • buildstream/_workspaces.py
    ... ... @@ -25,6 +25,219 @@ from ._exceptions import LoadError, LoadErrorReason
    25 25
     
    
    26 26
     
    
    27 27
     BST_WORKSPACE_FORMAT_VERSION = 3
    
    28
    +BST_WORKSPACE_PROJECT_FORMAT_VERSION = 1
    
    29
    +WORKSPACE_PROJECT_FILE = ".bstproject.yaml"
    
    30
    +
    
    31
    +
    
    32
    +# WorkspaceProject()
    
    33
    +#
    
    34
    +# An object to contain various helper functions and data required for
    
    35
    +# referring from a workspace back to buildstream.
    
    36
    +#
    
    37
    +# Args:
    
    38
    +#    directory (str): The directory that the workspace exists in.
    
    39
    +#
    
    40
    +class WorkspaceProject():
    
    41
    +    def __init__(self, directory):
    
    42
    +        self._projects = []
    
    43
    +        self._directory = directory
    
    44
    +
    
    45
    +    # get_default_project_path()
    
    46
    +    #
    
    47
    +    # Retrieves the default path to a project.
    
    48
    +    #
    
    49
    +    # Returns:
    
    50
    +    #    (str): The path to a project
    
    51
    +    #
    
    52
    +    def get_default_project_path(self):
    
    53
    +        return self._projects[0]['project-path']
    
    54
    +
    
    55
    +    # get_default_element()
    
    56
    +    #
    
    57
    +    # Retrieves the name of the element that owns this workspace.
    
    58
    +    #
    
    59
    +    # Returns:
    
    60
    +    #    (str): The name of an element
    
    61
    +    #
    
    62
    +    def get_default_element(self):
    
    63
    +        return self._projects[0]['element-name']
    
    64
    +
    
    65
    +    # to_dict()
    
    66
    +    #
    
    67
    +    # Turn the members data into a dict for serialization purposes
    
    68
    +    #
    
    69
    +    # Returns:
    
    70
    +    #    (dict): A dict representation of the WorkspaceProject
    
    71
    +    #
    
    72
    +    def to_dict(self):
    
    73
    +        ret = {
    
    74
    +            'projects': self._projects,
    
    75
    +            'format-version': BST_WORKSPACE_PROJECT_FORMAT_VERSION,
    
    76
    +        }
    
    77
    +        return ret
    
    78
    +
    
    79
    +    # from_dict()
    
    80
    +    #
    
    81
    +    # Loads a new WorkspaceProject from a simple dictionary
    
    82
    +    #
    
    83
    +    # Args:
    
    84
    +    #    directory (str): The directory that the workspace exists in
    
    85
    +    #    dictionary (dict): The dict to generate a WorkspaceProject from
    
    86
    +    #
    
    87
    +    # Returns:
    
    88
    +    #   (WorkspaceProject): A newly instantiated WorkspaceProject
    
    89
    +    #
    
    90
    +    @classmethod
    
    91
    +    def from_dict(cls, directory, dictionary):
    
    92
    +        # Only know how to handle one format-version at the moment.
    
    93
    +        format_version = int(dictionary['format-version'])
    
    94
    +        assert format_version == BST_WORKSPACE_PROJECT_FORMAT_VERSION, \
    
    95
    +            "Format version {} not found in {}".format(BST_WORKSPACE_PROJECT_FORMAT_VERSION, dictionary)
    
    96
    +
    
    97
    +        workspace_project = cls(directory)
    
    98
    +        for item in dictionary['projects']:
    
    99
    +            workspace_project.add_project(item['project-path'], item['element-name'])
    
    100
    +
    
    101
    +        return workspace_project
    
    102
    +
    
    103
    +    # load()
    
    104
    +    #
    
    105
    +    # Loads the WorkspaceProject for a given directory. This directory may be a
    
    106
    +    # subdirectory of the workspace's directory.
    
    107
    +    #
    
    108
    +    # Args:
    
    109
    +    #    directory (str): The directory
    
    110
    +    # Returns:
    
    111
    +    #    (WorkspaceProject): The created WorkspaceProject, if in a workspace, or
    
    112
    +    #    (NoneType): None, if the directory is not inside a workspace.
    
    113
    +    #
    
    114
    +    @classmethod
    
    115
    +    def load(cls, directory):
    
    116
    +        project_dir = cls.search_for_dir(directory)
    
    117
    +        if project_dir:
    
    118
    +            workspace_file = os.path.join(project_dir, WORKSPACE_PROJECT_FILE)
    
    119
    +            data_dict = _yaml.load(workspace_file)
    
    120
    +            return cls.from_dict(project_dir, data_dict)
    
    121
    +        else:
    
    122
    +            return None
    
    123
    +
    
    124
    +    # write()
    
    125
    +    #
    
    126
    +    # Writes the WorkspaceProject to disk
    
    127
    +    #
    
    128
    +    def write(self):
    
    129
    +        os.makedirs(self._directory, exist_ok=True)
    
    130
    +        _yaml.dump(self.to_dict(), self.get_filename())
    
    131
    +
    
    132
    +    # search_for_dir()
    
    133
    +    #
    
    134
    +    # Returns the directory that contains the workspace local project file,
    
    135
    +    # searching upwards from search_dir.
    
    136
    +    #
    
    137
    +    @staticmethod
    
    138
    +    def search_for_dir(search_dir):
    
    139
    +        return utils._search_upward_for_file(search_dir, WORKSPACE_PROJECT_FILE)
    
    140
    +
    
    141
    +    # get_filename()
    
    142
    +    #
    
    143
    +    # Returns the full path to the workspace local project file
    
    144
    +    #
    
    145
    +    def get_filename(self):
    
    146
    +        return os.path.join(self._directory, WORKSPACE_PROJECT_FILE)
    
    147
    +
    
    148
    +    # add_project()
    
    149
    +    #
    
    150
    +    # Adds an entry containing the project's path and element's name.
    
    151
    +    #
    
    152
    +    # Args:
    
    153
    +    #    project_path (str): The path to the project that opened the workspace.
    
    154
    +    #    element_name (str): The name of the element that the workspace belongs to.
    
    155
    +    #
    
    156
    +    def add_project(self, project_path, element_name):
    
    157
    +        assert (project_path and element_name)
    
    158
    +        self._projects.append({'project-path': project_path, 'element-name': element_name})
    
    159
    +
    
    160
    +
    
    161
    +# WorkspaceProjectCache()
    
    162
    +#
    
    163
    +# A class to manage workspace project data for multiple workspaces.
    
    164
    +#
    
    165
    +class WorkspaceProjectCache():
    
    166
    +    def __init__(self):
    
    167
    +        self._projects = {}  # Mapping of a workspace directory to its WorkspaceProject
    
    168
    +
    
    169
    +    # get()
    
    170
    +    #
    
    171
    +    # Returns a WorkspaceProject for a given directory, retrieving from the cache if
    
    172
    +    # present, and searching the filesystem for the file and loading it if not.
    
    173
    +    #
    
    174
    +    # Args:
    
    175
    +    #    directory (str): The directory to search for a WorkspaceProject.
    
    176
    +    #
    
    177
    +    # Returns:
    
    178
    +    #    (WorkspaceProject): The WorkspaceProject that was found for that directory.
    
    179
    +    #    or      (NoneType): None, if no WorkspaceProject can be found.
    
    180
    +    #
    
    181
    +    def get(self, directory):
    
    182
    +        try:
    
    183
    +            workspace_project = self._projects[directory]
    
    184
    +        except KeyError:
    
    185
    +            found_dir = WorkspaceProject.search_for_dir(directory)
    
    186
    +            if found_dir:
    
    187
    +                try:
    
    188
    +                    workspace_project = self._projects[found_dir]
    
    189
    +                except KeyError:
    
    190
    +                    workspace_project = WorkspaceProject.load(found_dir)
    
    191
    +                    self._projects[found_dir] = workspace_project
    
    192
    +            else:
    
    193
    +                workspace_project = None
    
    194
    +
    
    195
    +        return workspace_project
    
    196
    +
    
    197
    +    # add()
    
    198
    +    #
    
    199
    +    # Adds the project path and element name to the WorkspaceProject that exists
    
    200
    +    # for that directory
    
    201
    +    #
    
    202
    +    # Args:
    
    203
    +    #    directory (str): The directory to search for a WorkspaceProject.
    
    204
    +    #    project_path (str): The path to the project that refers to this workspace
    
    205
    +    #    element_name (str): The element in the project that was refers to this workspace
    
    206
    +    #
    
    207
    +    # Returns:
    
    208
    +    #    (WorkspaceProject): The WorkspaceProject that was found for that directory.
    
    209
    +    #
    
    210
    +    def add(self, directory, project_path, element_name):
    
    211
    +        workspace_project = self.get(directory)
    
    212
    +        if not workspace_project:
    
    213
    +            workspace_project = WorkspaceProject(directory)
    
    214
    +            self._projects[directory] = workspace_project
    
    215
    +
    
    216
    +        workspace_project.add_project(project_path, element_name)
    
    217
    +        return workspace_project
    
    218
    +
    
    219
    +    # remove()
    
    220
    +    #
    
    221
    +    # Removes the project path and element name from the WorkspaceProject that exists
    
    222
    +    # for that directory.
    
    223
    +    #
    
    224
    +    # NOTE: This currently just deletes the file, but with support for multiple
    
    225
    +    # projects opening the same workspace, this will involve decreasing the count
    
    226
    +    # and deleting the file if there are no more projects.
    
    227
    +    #
    
    228
    +    # Args:
    
    229
    +    #    directory (str): The directory to search for a WorkspaceProject.
    
    230
    +    #
    
    231
    +    def remove(self, directory):
    
    232
    +        workspace_project = self.get(directory)
    
    233
    +        if not workspace_project:
    
    234
    +            raise LoadError(LoadErrorReason.MISSING_FILE,
    
    235
    +                            "Failed to find a {} file to remove".format(WORKSPACE_PROJECT_FILE))
    
    236
    +        path = workspace_project.get_filename()
    
    237
    +        try:
    
    238
    +            os.unlink(path)
    
    239
    +        except FileNotFoundError:
    
    240
    +            pass
    
    28 241
     
    
    29 242
     
    
    30 243
     # Workspace()
    
    ... ... @@ -174,10 +387,15 @@ class Workspace():
    174 387
             if recalculate or self._key is None:
    
    175 388
                 fullpath = self.get_absolute_path()
    
    176 389
     
    
    390
    +            excluded_files = (WORKSPACE_PROJECT_FILE,)
    
    391
    +
    
    177 392
                 # Get a list of tuples of the the project relative paths and fullpaths
    
    178 393
                 if os.path.isdir(fullpath):
    
    179 394
                     filelist = utils.list_relative_paths(fullpath)
    
    180
    -                filelist = [(relpath, os.path.join(fullpath, relpath)) for relpath in filelist]
    
    395
    +                filelist = [
    
    396
    +                    (relpath, os.path.join(fullpath, relpath)) for relpath in filelist
    
    397
    +                    if relpath not in excluded_files
    
    398
    +                ]
    
    181 399
                 else:
    
    182 400
                     filelist = [(self.get_absolute_path(), fullpath)]
    
    183 401
     
    
    ... ... @@ -199,12 +417,14 @@ class Workspace():
    199 417
     #
    
    200 418
     # Args:
    
    201 419
     #    toplevel_project (Project): Top project used to resolve paths.
    
    420
    +#    workspace_project_cache (WorkspaceProjectCache): The cache of WorkspaceProjects
    
    202 421
     #
    
    203 422
     class Workspaces():
    
    204
    -    def __init__(self, toplevel_project):
    
    423
    +    def __init__(self, toplevel_project, workspace_project_cache):
    
    205 424
             self._toplevel_project = toplevel_project
    
    206 425
             self._bst_directory = os.path.join(toplevel_project.directory, ".bst")
    
    207 426
             self._workspaces = self._load_config()
    
    427
    +        self._workspace_project_cache = workspace_project_cache
    
    208 428
     
    
    209 429
         # list()
    
    210 430
         #
    
    ... ... @@ -219,19 +439,36 @@ class Workspaces():
    219 439
     
    
    220 440
         # create_workspace()
    
    221 441
         #
    
    222
    -    # Create a workspace in the given path for the given element.
    
    442
    +    # Create a workspace in the given path for the given element, and potentially
    
    443
    +    # checks-out the target into it.
    
    223 444
         #
    
    224 445
         # Args:
    
    225
    -    #    element_name (str) - The element name to create a workspace for
    
    446
    +    #    target (Element) - The element to create a workspace for
    
    226 447
         #    path (str) - The path in which the workspace should be kept
    
    448
    +    #    checkout (bool): Whether to check-out the element's sources into the directory
    
    227 449
         #
    
    228
    -    def create_workspace(self, element_name, path):
    
    229
    -        if path.startswith(self._toplevel_project.directory):
    
    230
    -            path = os.path.relpath(path, self._toplevel_project.directory)
    
    450
    +    def create_workspace(self, target, path, checkout):
    
    451
    +        element_name = target._get_full_name()
    
    452
    +        project_dir = self._toplevel_project.directory
    
    453
    +        if path.startswith(project_dir):
    
    454
    +            workspace_path = os.path.relpath(path, project_dir)
    
    455
    +        else:
    
    456
    +            workspace_path = path
    
    231 457
     
    
    232
    -        self._workspaces[element_name] = Workspace(self._toplevel_project, path=path)
    
    458
    +        self._workspaces[element_name] = Workspace(self._toplevel_project, path=workspace_path)
    
    233 459
     
    
    234
    -        return self._workspaces[element_name]
    
    460
    +        if checkout:
    
    461
    +            with target.timed_activity("Staging sources to {}".format(path)):
    
    462
    +                target._open_workspace()
    
    463
    +
    
    464
    +        workspace_project = self._workspace_project_cache.add(path, project_dir, element_name)
    
    465
    +        project_file_path = workspace_project.get_filename()
    
    466
    +
    
    467
    +        if os.path.exists(project_file_path):
    
    468
    +            target.warn("{} was staged from this element's sources".format(WORKSPACE_PROJECT_FILE))
    
    469
    +        workspace_project.write()
    
    470
    +
    
    471
    +        self.save_config()
    
    235 472
     
    
    236 473
         # get_workspace()
    
    237 474
         #
    
    ... ... @@ -280,8 +517,19 @@ class Workspaces():
    280 517
         #    element_name (str) - The element name whose workspace to delete
    
    281 518
         #
    
    282 519
         def delete_workspace(self, element_name):
    
    520
    +        workspace = self.get_workspace(element_name)
    
    283 521
             del self._workspaces[element_name]
    
    284 522
     
    
    523
    +        # Remove from the cache if it exists
    
    524
    +        try:
    
    525
    +            self._workspace_project_cache.remove(workspace.get_absolute_path())
    
    526
    +        except LoadError as e:
    
    527
    +            # We might be closing a workspace with a deleted directory
    
    528
    +            if e.reason == LoadErrorReason.MISSING_FILE:
    
    529
    +                pass
    
    530
    +            else:
    
    531
    +                raise
    
    532
    +
    
    285 533
         # save_config()
    
    286 534
         #
    
    287 535
         # Dump the current workspace element to the project configuration
    

  • buildstream/data/userconfig.yaml
    ... ... @@ -128,6 +128,14 @@ prompt:
    128 128
       #
    
    129 129
       really-workspace-close-remove-dir: ask
    
    130 130
     
    
    131
    +  # Whether to really proceed with 'bst workspace close' when doing so would
    
    132
    +  # stop them from running bst commands in this workspace.
    
    133
    +  #
    
    134
    +  #  ask - Ask the user if they are sure.
    
    135
    +  #  yes - Always close, without asking.
    
    136
    +  #
    
    137
    +  really-workspace-close-project-inaccessible: ask
    
    138
    +
    
    131 139
       # Whether to really proceed with 'bst workspace reset' doing a hard reset of
    
    132 140
       # a workspace, potentially losing changes.
    
    133 141
       #
    

  • buildstream/utils.py
    ... ... @@ -1259,3 +1259,17 @@ def _message_digest(message_buffer):
    1259 1259
         digest.hash = sha.hexdigest()
    
    1260 1260
         digest.size_bytes = len(message_buffer)
    
    1261 1261
         return digest
    
    1262
    +
    
    1263
    +
    
    1264
    +# Returns the first directory to contain filename, or an empty string if
    
    1265
    +# none found
    
    1266
    +#
    
    1267
    +def _search_upward_for_file(directory, filename):
    
    1268
    +    directory = os.path.abspath(directory)
    
    1269
    +    while not os.path.isfile(os.path.join(directory, filename)):
    
    1270
    +        parent_dir = os.path.dirname(directory)
    
    1271
    +        if directory == parent_dir:
    
    1272
    +            return ""
    
    1273
    +        directory = parent_dir
    
    1274
    +
    
    1275
    +    return directory

  • doc/sessions/developing.run
    ... ... @@ -24,6 +24,11 @@ commands:
    24 24
       output: ../source/sessions/developing-build-after-changes.html
    
    25 25
       command: build hello.bst
    
    26 26
     
    
    27
    +# Rebuild, from the workspace
    
    28
    +- directory: ../examples/developing/workspace_hello
    
    29
    +  output: ../source/sessions/developing-build-after-changes-workspace.html
    
    30
    +  command: build
    
    31
    +
    
    27 32
     # Capture shell output with changes
    
    28 33
     - directory: ../examples/developing/
    
    29 34
       output: ../source/sessions/developing-shell-after-changes.html
    

  • doc/source/developing/workspaces.rst
    ... ... @@ -50,11 +50,16 @@ We can open workspace_hello/hello.c and make the following change:
    50 50
     .. literalinclude:: ../../examples/developing/update.patch
    
    51 51
         :language: diff
    
    52 52
     
    
    53
    -Now, rebuild the hello.bst element
    
    53
    +Now, rebuild the hello.bst element.
    
    54 54
     
    
    55 55
     .. raw:: html
    
    56 56
        :file: ../sessions/developing-build-after-changes.html
    
    57 57
     
    
    58
    +Note that if you run the command from inside the workspace, the element name is optional.
    
    59
    +
    
    60
    +.. raw:: html
    
    61
    +   :file: ../sessions/developing-build-after-changes-workspace.html
    
    62
    +
    
    58 63
     Now running the hello command using bst shell:
    
    59 64
     
    
    60 65
     .. raw:: html
    

  • doc/source/sessions-stored/developing-build-after-changes-workspace.html
    1
    +<!--
    
    2
    +    WARNING: This file was generated with bst2html.py
    
    3
    +-->
    
    4
    +<div class="highlight" style="font-size:x-small"><pre>
    
    5
    +<span style="color:#C4A000;font-weight:bold">user@host</span>:<span style="color:#3456A4;font-weight:bold">~/workspace_hello</span>$ bst build
    
    6
    +
    
    7
    +<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START  </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Build
    
    8
    +<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START  </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Loading elements
    
    9
    +<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Loading elements
    
    10
    +<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START  </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Resolving elements
    
    11
    +<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Resolving elements
    
    12
    +<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START  </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Resolving cached state
    
    13
    +<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Resolving cached state
    
    14
    +<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">--</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#3465A4"><span style=""><span style="opacity:0.5">START  </span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Checking sources
    
    15
    +<span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Checking sources
    
    16
    +
    
    17
    +<span style="color:#C4A000"><span style="">BuildStream Version 1.3.0+1032.g41813d3a.dirty
    
    18
    +</span></span><span style="color:#06989A"><span style="opacity:0.5">  Session Start: </span></span><span style="color:#C4A000">Wednesday, 05-12-2018 at 16:47:38</span>
    
    19
    +<span style="color:#06989A"><span style="opacity:0.5">  Project:       </span></span><span style="color:#C4A000">developing (/home/user/workspace/buildstream/buildstream/doc/examples/developing)</span>
    
    20
    +<span style="color:#06989A"><span style="opacity:0.5">  Targets:       </span></span><span style="color:#C4A000">hello.bst</span>
    
    21
    +
    
    22
    +<span style="color:#C4A000"><span style="">User Configuration
    
    23
    +</span></span><span style="color:#06989A"><span style="opacity:0.5">  Configuration File:      </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/buildstream.conf</span>
    
    24
    +<span style="color:#06989A"><span style="opacity:0.5">  Log Files:               </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/logs</span>
    
    25
    +<span style="color:#06989A"><span style="opacity:0.5">  Source Mirrors:          </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/sources</span>
    
    26
    +<span style="color:#06989A"><span style="opacity:0.5">  Build Area:              </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/build</span>
    
    27
    +<span style="color:#06989A"><span style="opacity:0.5">  Artifact Cache:          </span></span><span style="color:#C4A000">/home/user/workspace/buildstream/buildstream/doc/run-bst-7ocq4_a7/artifacts</span>
    
    28
    +<span style="color:#06989A"><span style="opacity:0.5">  Strict Build Plan:       </span></span><span style="color:#C4A000">Yes</span>
    
    29
    +<span style="color:#06989A"><span style="opacity:0.5">  Maximum Fetch Tasks:     </span></span><span style="color:#C4A000">10</span>
    
    30
    +<span style="color:#06989A"><span style="opacity:0.5">  Maximum Build Tasks:     </span></span><span style="color:#C4A000">4</span>
    
    31
    +<span style="color:#06989A"><span style="opacity:0.5">  Maximum Push Tasks:      </span></span><span style="color:#C4A000">4</span>
    
    32
    +<span style="color:#06989A"><span style="opacity:0.5">  Maximum Network Retries: </span></span><span style="color:#C4A000">2</span>
    
    33
    +
    
    34
    +<span style="color:#C4A000"><span style="">Pipeline
    
    35
    +</span></span><span style="color:#75507B">      cached</span> <span style="color:#C4A000">9afe69d645f0bee106749bc2101aae16ef437bb51e1b343ef1f16f04f0572efb</span> <span style="color:#3465A4"><span style="">base/alpine.bst</span></span> 
    
    36
    +<span style="color:#75507B">      cached</span> <span style="color:#C4A000">19f7c50c7a1db9ae4babe9d1f34f4cdbbf2428827d48673861fd1452d6c7e16b</span> <span style="color:#3465A4"><span style="">base.bst</span></span> 
    
    37
    +<span style="color:#75507B">      cached</span> <span style="color:#C4A000">faa419610e7309d36d15926a81a8d75bbc113443c23c8162e63843dd86b5f56a</span> <span style="color:#3465A4"><span style="">hello.bst</span></span> Workspace: /home/user/workspace/buildstream/buildstream/doc/examples/developing/workspace_hello
    
    38
    +<span style="color:#06989A"><span style="opacity:0.5">===============================================================================
    
    39
    +</span></span><span style="color:#06989A"><span style="opacity:0.5">[</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">:</span></span><span style="color:#C4A000">00</span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">][</span></span><span style="color:#06989A"><span style="opacity:0.5">] </span></span><span style="color:#4E9A06"><span style=""><span style="opacity:0.5">SUCCESS</span></span></span><span style="color:#06989A"><span style="opacity:0.5"> </span></span>Build
    
    40
    +
    
    41
    +<span style="color:#C4A000"><span style="">Pipeline Summary
    
    42
    +</span></span><span style="color:#06989A"><span style="opacity:0.5">  Total:       </span></span><span style="color:#C4A000">3</span>
    
    43
    +<span style="color:#06989A"><span style="opacity:0.5">  Session:     </span></span><span style="color:#C4A000">0</span>
    
    44
    +<span style="color:#06989A"><span style="opacity:0.5">  Fetch Queue: </span></span><span style="color:#C4A000">processed </span><span style="color:#4E9A06">0</span><span style="color:#06989A"><span style="opacity:0.5">, </span></span><span style="color:#C4A000">skipped </span><span style="color:#C4A000">0</span><span style="color:#06989A"><span style="opacity:0.5">, </span></span><span style="color:#C4A000">failed </span><span style="color:#CC0000"><span style="opacity:0.5">0</span></span> 
    
    45
    +<span style="color:#06989A"><span style="opacity:0.5">  Build Queue: </span></span><span style="color:#C4A000">processed </span><span style="color:#4E9A06">0</span><span style="color:#06989A"><span style="opacity:0.5">, </span></span><span style="color:#C4A000">skipped </span><span style="color:#C4A000">0</span><span style="color:#06989A"><span style="opacity:0.5">, </span></span><span style="color:#C4A000">failed </span><span style="color:#CC0000"><span style="opacity:0.5">0</span></span>
    
    46
    +</pre></div>

  • tests/frontend/source_checkout.py
    ... ... @@ -28,12 +28,27 @@ def generate_remote_import_element(input_path, output_path):
    28 28
     
    
    29 29
     
    
    30 30
     @pytest.mark.datafiles(DATA_DIR)
    
    31
    -def test_source_checkout(datafiles, cli):
    
    31
    +@pytest.mark.parametrize(
    
    32
    +    "with_workspace,guess_element",
    
    33
    +    [("workspace", "guess"), ("workspace", "no-guess"), ("no-workspace", "no-guess")]
    
    34
    +)
    
    35
    +def test_source_checkout(datafiles, cli, tmpdir_factory, with_workspace, guess_element):
    
    36
    +    tmpdir = tmpdir_factory.mktemp("")
    
    32 37
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    33 38
         checkout = os.path.join(cli.directory, 'source-checkout')
    
    34 39
         target = 'checkout-deps.bst'
    
    40
    +    workspace = os.path.join(str(tmpdir), 'workspace')
    
    41
    +    elm_cmd = [target] if guess_element == "no-guess" else []
    
    35 42
     
    
    36
    -    result = cli.run(project=project, args=['source-checkout', target, '--deps', 'none', checkout])
    
    43
    +    if with_workspace == "workspace":
    
    44
    +        ws_cmd = ['-C', workspace]
    
    45
    +        result = cli.run(project=project, args=["workspace", "open", "--directory", workspace, target])
    
    46
    +        result.assert_success()
    
    47
    +    else:
    
    48
    +        ws_cmd = []
    
    49
    +
    
    50
    +    args = ws_cmd + ['source-checkout', '--deps', 'none'] + elm_cmd + [checkout]
    
    51
    +    result = cli.run(project=project, args=args)
    
    37 52
         result.assert_success()
    
    38 53
     
    
    39 54
         assert os.path.exists(os.path.join(checkout, 'checkout-deps', 'etc', 'buildstream', 'config'))
    

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

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



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