[Notes] [Git][BuildStream/buildstream][jonathan/workspace-fragment-guess-element] 5 commits: Make specifying elements optional in bst commands



Title: GitLab

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

Commits:

10 changed files:

Changes:

  • NEWS
    ... ... @@ -82,6 +82,11 @@ buildstream 1.3.1
    82 82
       o Opening a workspace now creates a .bstproject.yaml file that allows buildstream
    
    83 83
         commands to be run from a workspace that is not inside a project.
    
    84 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', 'track', 'workspace close' and 'workspace reset' commands are
    
    88
    +    affected.
    
    89
    +
    
    85 90
     
    
    86 91
     =================
    
    87 92
     buildstream 1.1.5
    

  • buildstream/_context.py
    ... ... @@ -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
    
    ... ... @@ -148,6 +151,7 @@ class Context():
    148 151
             self._log_handle = None
    
    149 152
             self._log_filename = None
    
    150 153
             self._cascache = None
    
    154
    +        self._directory = directory
    
    151 155
     
    
    152 156
         # load()
    
    153 157
         #
    
    ... ... @@ -645,6 +649,19 @@ class Context():
    645 649
                 self._cascache = CASCache(self.artifactdir)
    
    646 650
             return self._cascache
    
    647 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
    +
    
    648 665
     
    
    649 666
     # _node_get_option_str()
    
    650 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
    ... ... @@ -316,10 +316,15 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac
    316 316
         if track_save:
    
    317 317
             click.echo("WARNING: --track-save is deprecated, saving is now unconditional", err=True)
    
    318 318
     
    
    319
    -    if track_all:
    
    320
    -        track_ = elements
    
    321
    -
    
    322 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
    +
    
    323 328
             app.stream.build(elements,
    
    324 329
                              track_targets=track_,
    
    325 330
                              track_except=track_except,
    
    ... ... @@ -371,6 +376,11 @@ def fetch(app, elements, deps, track_, except_, track_cross_junctions):
    371 376
             deps = PipelineSelection.ALL
    
    372 377
     
    
    373 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
    +
    
    374 384
             app.stream.fetch(elements,
    
    375 385
                              selection=deps,
    
    376 386
                              except_targets=except_,
    
    ... ... @@ -407,6 +417,11 @@ def track(app, elements, deps, except_, cross_junctions):
    407 417
             all:   All dependencies of all specified elements
    
    408 418
         """
    
    409 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
    +
    
    410 425
             # Substitute 'none' for 'redirect' so that element redirections
    
    411 426
             # will be done
    
    412 427
             if deps == 'none':
    
    ... ... @@ -442,7 +457,13 @@ def pull(app, elements, deps, remote):
    442 457
             none:  No dependencies, just the element itself
    
    443 458
             all:   All dependencies
    
    444 459
         """
    
    460
    +
    
    445 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
    +
    
    446 467
             app.stream.pull(elements, selection=deps, remote=remote)
    
    447 468
     
    
    448 469
     
    
    ... ... @@ -475,6 +496,11 @@ def push(app, elements, deps, remote):
    475 496
             all:   All dependencies
    
    476 497
         """
    
    477 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
    +
    
    478 504
             app.stream.push(elements, selection=deps, remote=remote)
    
    479 505
     
    
    480 506
     
    
    ... ... @@ -545,6 +571,11 @@ def show(app, elements, deps, except_, order, format_):
    545 571
                 $'---------- %{name} ----------\\n%{vars}'
    
    546 572
         """
    
    547 573
         with app.initialized():
    
    574
    +        if not elements:
    
    575
    +            guessed_target = app.context.guess_element()
    
    576
    +            if guessed_target:
    
    577
    +                elements = (guessed_target,)
    
    578
    +
    
    548 579
             dependencies = app.stream.load_selection(elements,
    
    549 580
                                                      selection=deps,
    
    550 581
                                                      except_targets=except_)
    
    ... ... @@ -573,7 +604,7 @@ def show(app, elements, deps, except_, order, format_):
    573 604
                   help="Mount a file or directory into the sandbox")
    
    574 605
     @click.option('--isolate', is_flag=True, default=False,
    
    575 606
                   help='Create an isolated build sandbox')
    
    576
    -@click.argument('element',
    
    607
    +@click.argument('element', required=False,
    
    577 608
                     type=click.Path(readable=False))
    
    578 609
     @click.argument('command', type=click.STRING, nargs=-1)
    
    579 610
     @click.pass_obj
    
    ... ... @@ -604,6 +635,11 @@ def shell(app, element, sysroot, mount, isolate, build_, command):
    604 635
             scope = Scope.RUN
    
    605 636
     
    
    606 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
    +
    
    607 643
             dependencies = app.stream.load_selection((element,), selection=PipelineSelection.NONE)
    
    608 644
             element = dependencies[0]
    
    609 645
             prompt = app.shell_prompt(element)
    
    ... ... @@ -641,15 +677,24 @@ def shell(app, element, sysroot, mount, isolate, build_, command):
    641 677
                   help="Create a tarball from the artifact contents instead "
    
    642 678
                        "of a file tree. If LOCATION is '-', the tarball "
    
    643 679
                        "will be dumped to the standard output.")
    
    644
    -@click.argument('element',
    
    680
    +@click.argument('element', required=False,
    
    645 681
                     type=click.Path(readable=False))
    
    646
    -@click.argument('location', type=click.Path())
    
    682
    +@click.argument('location', type=click.Path(), required=False)
    
    647 683
     @click.pass_obj
    
    648 684
     def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
    
    649 685
         """Checkout a built artifact to the specified location
    
    650 686
         """
    
    651 687
         from ..element import Scope
    
    652 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
    +
    
    653 698
         if hardlinks and tar:
    
    654 699
             click.echo("ERROR: options --hardlinks and --tar conflict", err=True)
    
    655 700
             sys.exit(-1)
    
    ... ... @@ -662,6 +707,11 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
    662 707
             scope = Scope.NONE
    
    663 708
     
    
    664 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
    +
    
    665 715
             app.stream.checkout(element,
    
    666 716
                                 location=location,
    
    667 717
                                 force=force,
    
    ... ... @@ -683,14 +733,28 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
    683 733
                   help='The dependencies whose sources to checkout (default: none)')
    
    684 734
     @click.option('--fetch', 'fetch_', default=False, is_flag=True,
    
    685 735
                   help='Fetch elements if they are not fetched')
    
    686
    -@click.argument('element',
    
    736
    +@click.argument('element', required=False,
    
    687 737
                     type=click.Path(readable=False))
    
    688
    -@click.argument('location', type=click.Path())
    
    738
    +@click.argument('location', type=click.Path(), required=False)
    
    689 739
     @click.pass_obj
    
    690 740
     def source_checkout(app, element, location, deps, fetch_, except_):
    
    691 741
         """Checkout sources of an element to the specified location
    
    692 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
    +
    
    693 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
    +
    
    694 758
             app.stream.source_checkout(element,
    
    695 759
                                        location=location,
    
    696 760
                                        deps=deps,
    
    ... ... @@ -747,11 +811,15 @@ def workspace_open(app, no_checkout, force, track_, directory, elements):
    747 811
     def workspace_close(app, remove_dir, all_, elements):
    
    748 812
         """Close a workspace"""
    
    749 813
     
    
    750
    -    if not (all_ or elements):
    
    751
    -        click.echo('ERROR: no elements specified', err=True)
    
    752
    -        sys.exit(-1)
    
    753
    -
    
    754 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')
    
    755 823
     
    
    756 824
             # Early exit if we specified `all` and there are no workspaces
    
    757 825
             if all_ and not app.stream.workspace_exists():
    
    ... ... @@ -807,7 +875,11 @@ def workspace_reset(app, soft, track_, all_, elements):
    807 875
         with app.initialized():
    
    808 876
     
    
    809 877
             if not (all_ or elements):
    
    810
    -            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')
    
    811 883
     
    
    812 884
             if all_ and not app.stream.workspace_exists():
    
    813 885
                 raise AppError("No open workspaces to reset")
    

  • 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
    +    "from_workspace,guess_element",
    
    33
    +    [("workspace", "guess"), ("workspace", "no-guess"), ("no-workspace", "no-guess")]
    
    34
    +)
    
    35
    +def test_source_checkout(datafiles, cli, tmpdir_factory, from_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 from_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
    ... ... @@ -616,12 +616,15 @@ def test_list(cli, tmpdir, datafiles):
    616 616
     @pytest.mark.datafiles(DATA_DIR)
    
    617 617
     @pytest.mark.parametrize("kind", repo_kinds)
    
    618 618
     @pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
    
    619
    -@pytest.mark.parametrize("call_from", [("project"), ("workspace")])
    
    620
    -def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
    
    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):
    
    621 623
         tmpdir = tmpdir_factory.mktemp('')
    
    622 624
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
    
    623 625
         checkout = os.path.join(str(tmpdir), 'checkout')
    
    624
    -    args_pre = ['-C', workspace] if call_from == "workspace" else []
    
    626
    +    args_dir = ['-C', workspace] if call_from == "workspace" else []
    
    627
    +    args_elm = [element_name] if guess_element == "no-guess" else []
    
    625 628
     
    
    626 629
         # Modify workspace
    
    627 630
         shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
    
    ... ... @@ -644,14 +647,14 @@ def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
    644 647
         # Build modified workspace
    
    645 648
         assert cli.get_element_state(project, element_name) == 'buildable'
    
    646 649
         assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
    
    647
    -    result = cli.run(project=project, args=args_pre + ['build', element_name])
    
    650
    +    result = cli.run(project=project, args=args_dir + ['build'] + args_elm)
    
    648 651
         result.assert_success()
    
    649 652
         assert cli.get_element_state(project, element_name) == 'cached'
    
    650 653
         assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
    
    651 654
     
    
    652 655
         # Checkout the result
    
    653 656
         result = cli.run(project=project,
    
    654
    -                     args=args_pre + ['checkout', element_name, checkout])
    
    657
    +                     args=args_dir + ['checkout'] + args_elm + [checkout])
    
    655 658
         result.assert_success()
    
    656 659
     
    
    657 660
         # Check that the pony.conf from the modified workspace exists
    
    ... ... @@ -1061,24 +1064,31 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles):
    1061 1064
     
    
    1062 1065
     
    
    1063 1066
     @pytest.mark.datafiles(DATA_DIR)
    
    1064
    -def test_external_fetch(cli, datafiles, tmpdir_factory):
    
    1067
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1068
    +def test_external_fetch(cli, datafiles, tmpdir_factory, guess_element):
    
    1065 1069
         # Fetching from a workspace outside a project doesn't fail horribly
    
    1066 1070
         tmpdir = tmpdir_factory.mktemp('')
    
    1067 1071
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1072
    +    arg_elm = [element_name] if guess_element == "no-guess" else []
    
    1068 1073
     
    
    1069
    -    result = cli.run(project=project, args=['-C', workspace, 'fetch', element_name])
    
    1074
    +    result = cli.run(project=project, args=['-C', workspace, 'fetch'] + arg_elm)
    
    1070 1075
         result.assert_success()
    
    1071 1076
     
    
    1072 1077
         # We already fetched it by opening the workspace, but we're also checking
    
    1073 1078
         # `bst show` works here
    
    1074
    -    assert cli.get_element_state(project, element_name) == 'buildable'
    
    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'
    
    1075 1083
     
    
    1076 1084
     
    
    1077 1085
     @pytest.mark.datafiles(DATA_DIR)
    
    1078
    -def test_external_push_pull(cli, datafiles, tmpdir_factory):
    
    1086
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1087
    +def test_external_push_pull(cli, datafiles, tmpdir_factory, guess_element):
    
    1079 1088
         # Pushing and pulling to/from an artifact cache works from an external workspace
    
    1080 1089
         tmpdir = tmpdir_factory.mktemp('')
    
    1081 1090
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1091
    +    args_elm = [element_name] if guess_element == "no-guess" else []
    
    1082 1092
     
    
    1083 1093
         with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
    
    1084 1094
             result = cli.run(project=project, args=['-C', workspace, 'build', element_name])
    
    ... ... @@ -1088,22 +1098,24 @@ def test_external_push_pull(cli, datafiles, tmpdir_factory):
    1088 1098
                 'artifacts': {'url': share.repo, 'push': True}
    
    1089 1099
             })
    
    1090 1100
     
    
    1091
    -        result = cli.run(project=project, args=['-C', workspace, 'push', element_name])
    
    1101
    +        result = cli.run(project=project, args=['-C', workspace, 'push'] + args_elm)
    
    1092 1102
             result.assert_success()
    
    1093 1103
     
    
    1094
    -        result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all', element_name])
    
    1104
    +        result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all'] + args_elm)
    
    1095 1105
             result.assert_success()
    
    1096 1106
     
    
    1097 1107
     
    
    1098 1108
     @pytest.mark.datafiles(DATA_DIR)
    
    1099
    -def test_external_track(cli, datafiles, tmpdir_factory):
    
    1109
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1110
    +def test_external_track(cli, datafiles, tmpdir_factory, guess_element):
    
    1100 1111
         # Tracking does not get horribly confused
    
    1101 1112
         tmpdir = tmpdir_factory.mktemp('')
    
    1102 1113
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
    
    1114
    +    args_elm = [element_name] if guess_element == "no-guess" else []
    
    1103 1115
     
    
    1104 1116
         # The workspace is necessarily already tracked, so we only care that
    
    1105 1117
         # there's no weird errors.
    
    1106
    -    result = cli.run(project=project, args=['-C', workspace, 'track', element_name])
    
    1118
    +    result = cli.run(project=project, args=['-C', workspace, 'track'] + args_elm)
    
    1107 1119
         result.assert_success()
    
    1108 1120
     
    
    1109 1121
     
    
    ... ... @@ -1141,15 +1153,17 @@ def test_external_close_other(cli, datafiles, tmpdir_factory):
    1141 1153
     
    
    1142 1154
     
    
    1143 1155
     @pytest.mark.datafiles(DATA_DIR)
    
    1144
    -def test_external_close_self(cli, datafiles, tmpdir_factory):
    
    1156
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1157
    +def test_external_close_self(cli, datafiles, tmpdir_factory, guess_element):
    
    1145 1158
         # >From inside an external workspace, close it
    
    1146 1159
         tmpdir1 = tmpdir_factory.mktemp('')
    
    1147 1160
         tmpdir2 = tmpdir_factory.mktemp('')
    
    1148 1161
         # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    1149 1162
         alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
    
    1150 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 []
    
    1151 1165
     
    
    1152
    -    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', alpha_element])
    
    1166
    +    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close'] + arg_elm)
    
    1153 1167
         result.assert_success()
    
    1154 1168
     
    
    1155 1169
     
    
    ... ... @@ -1166,11 +1180,13 @@ def test_external_reset_other(cli, datafiles, tmpdir_factory):
    1166 1180
     
    
    1167 1181
     
    
    1168 1182
     @pytest.mark.datafiles(DATA_DIR)
    
    1169
    -def test_external_reset_self(cli, datafiles, tmpdir):
    
    1183
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1184
    +def test_external_reset_self(cli, datafiles, tmpdir, guess_element):
    
    1170 1185
         element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1186
    +    arg_elm = [element] if guess_element == "no-guess" else []
    
    1171 1187
     
    
    1172 1188
         # Command succeeds
    
    1173
    -    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset', element])
    
    1189
    +    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset'] + arg_elm)
    
    1174 1190
         result.assert_success()
    
    1175 1191
     
    
    1176 1192
         # Successive commands still work (i.e. .bstproject.yaml hasn't been deleted)
    

  • tests/integration/shell.py
    ... ... @@ -358,13 +358,22 @@ def test_integration_devices(cli, tmpdir, datafiles):
    358 358
     # Test that a shell can be opened from an external workspace
    
    359 359
     @pytest.mark.datafiles(DATA_DIR)
    
    360 360
     @pytest.mark.parametrize("build_shell", [("build"), ("nobuild")])
    
    361
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    361 362
     @pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
    
    362
    -def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell):
    
    363
    +def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell, guess_element):
    
    363 364
         tmpdir = tmpdir_factory.mktemp("")
    
    364 365
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    365 366
         element_name = 'autotools/amhello.bst'
    
    366 367
         workspace_dir = os.path.join(str(tmpdir), 'workspace')
    
    367 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
    +
    
    368 377
         result = cli.run(project=project, args=[
    
    369 378
             'workspace', 'open', '--directory', workspace_dir, element_name
    
    370 379
         ])
    
    ... ... @@ -373,9 +382,10 @@ def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_sh
    373 382
         result = cli.run(project=project, args=['-C', workspace_dir, 'build', element_name])
    
    374 383
         result.assert_success()
    
    375 384
     
    
    376
    -    command = ['shell']
    
    385
    +    command = ['-C', workspace_dir, 'shell']
    
    377 386
         if build_shell == 'build':
    
    378 387
             command.append('--build')
    
    379
    -    command.extend([element_name, '--', 'true'])
    
    388
    +    if guess_element == "no-guess":
    
    389
    +        command.extend([element_name, '--', 'true'])
    
    380 390
         result = cli.run(project=project, cwd=workspace_dir, args=command)
    
    381 391
         result.assert_success()



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