[Notes] [Git][BuildStream/buildstream][issue_640-Build-All] 2 commits: _frontend/cli.py: Added build all functionality



Title: GitLab

Phillip Smyth pushed to branch issue_640-Build-All at BuildStream / buildstream

Commits:

22 changed files:

Changes:

  • buildstream/_frontend/cli.py
    ... ... @@ -170,6 +170,32 @@ original_main = click.BaseCommand.main
    170 170
     click.BaseCommand.main = override_main
    
    171 171
     
    
    172 172
     
    
    173
    +def get_elements(app):
    
    174
    +    directory = app._main_options.get("directory")
    
    175
    +    project = app.project
    
    176
    +    project_conf = project._project_conf
    
    177
    +    output = []
    
    178
    +
    
    179
    +    # The project is not required to have an element-path
    
    180
    +    element_directory = project_conf.get('element-path')
    
    181
    +
    
    182
    +    # The project may have a default element defined
    
    183
    +    default_element = project_conf.get("defaults", {}).get("target-element", None)
    
    184
    +
    
    185
    +    if default_element:
    
    186
    +        return (default_element,)
    
    187
    +
    
    188
    +    directory = os.path.abspath(directory)
    
    189
    +    for root, _, files in os.walk(directory):
    
    190
    +        for file in files:
    
    191
    +            if file.endswith(".bst"):
    
    192
    +                rel_dir = os.path.relpath(root, directory)
    
    193
    +                rel_file = os.path.join(rel_dir, file).lstrip("./")
    
    194
    +                rel_file = rel_file.lstrip(element_directory).lstrip('/')
    
    195
    +                output.append(rel_file)
    
    196
    +    return tuple(output)
    
    197
    +
    
    198
    +
    
    173 199
     ##################################################################
    
    174 200
     #                          Main Options                          #
    
    175 201
     ##################################################################
    
    ... ... @@ -313,9 +339,12 @@ def init(app, project_name, format_version, element_path, force):
    313 339
                   help="Deprecated: This is ignored")
    
    314 340
     @click.argument('elements', nargs=-1,
    
    315 341
                     type=click.Path(readable=False))
    
    342
    +
    
    316 343
     @click.pass_obj
    
    317 344
     def build(app, elements, all_, track_, track_save, track_all, track_except, track_cross_junctions):
    
    318
    -    """Build elements in a pipeline"""
    
    345
    +    """Build elements in a pipeline\n
    
    346
    +       Declaring no elements with result in building a default element if one is declared.\n
    
    347
    +       If no default is declared, all elements in the project will be built"""
    
    319 348
     
    
    320 349
         if (track_except or track_cross_junctions) and not (track_ or track_all):
    
    321 350
             click.echo("ERROR: The --track-except and --track-cross-junctions options "
    
    ... ... @@ -329,6 +358,8 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac
    329 358
             track_ = elements
    
    330 359
     
    
    331 360
         with app.initialized(session_name="Build"):
    
    361
    +        if not elements:
    
    362
    +            elements = get_elements(app)
    
    332 363
             app.stream.build(elements,
    
    333 364
                              track_targets=track_,
    
    334 365
                              track_except=track_except,
    

  • buildstream/_project.py
    ... ... @@ -226,7 +226,7 @@ class Project():
    226 226
                 'element-path', 'variables',
    
    227 227
                 'environment', 'environment-nocache',
    
    228 228
                 'split-rules', 'elements', 'plugins',
    
    229
    -            'aliases', 'name',
    
    229
    +            'aliases', 'name', 'defaults',
    
    230 230
                 'artifacts', 'options',
    
    231 231
                 'fail-on-overlap', 'shell', 'fatal-warnings',
    
    232 232
                 'ref-storage', 'sandbox', 'mirrors', 'remote-execution',
    

  • buildstream/data/projectconfig.yaml
    ... ... @@ -196,4 +196,11 @@ shell:
    196 196
     
    
    197 197
       # Command to run when `bst shell` does not provide a command
    
    198 198
       #
    
    199
    -  command: [ 'sh', '-i' ]
    \ No newline at end of file
    199
    +  command: [ 'sh', '-i' ]
    
    200
    +
    
    201
    +# Default Targets
    
    202
    +#
    
    203
    +defaults:
    
    204
    +
    
    205
    +  # Set a Default element to build when none are defined 
    
    206
    +  target-element: None

  • tests/frontend/buildcheckout.py
    ... ... @@ -60,6 +60,64 @@ def test_build_checkout(datafiles, cli, strict, hardlinks):
    60 60
         assert os.path.exists(filename)
    
    61 61
     
    
    62 62
     
    
    63
    +@pytest.mark.datafiles(os.path.join(os.path.dirname(
    
    64
    +    os.path.realpath(__file__)),
    
    65
    +    "project_world",
    
    66
    +))
    
    67
    +@pytest.mark.parametrize("strict,hardlinks", [
    
    68
    +    ("strict", "copies"),
    
    69
    +    ("strict", "hardlinks"),
    
    70
    +    ("non-strict", "copies"),
    
    71
    +    ("non-strict", "hardlinks"),
    
    72
    +])
    
    73
    +def test_build_default_all_checkout(datafiles, cli, strict, hardlinks):
    
    74
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    75
    +    checkout = os.path.join(cli.directory, 'checkout')
    
    76
    +
    
    77
    +    # First build it
    
    78
    +    result = cli.run(project=project, args=strict_args(['build'], strict))
    
    79
    +    result.assert_success()
    
    80
    +
    
    81
    +    # Assert that after a successful build, the builddir is empty
    
    82
    +    builddir = os.path.join(cli.directory, 'build')
    
    83
    +    assert os.path.isdir(builddir)
    
    84
    +    assert not os.listdir(builddir)
    
    85
    +
    
    86
    +    # Prepare checkout args
    
    87
    +    checkout_args = strict_args(['checkout'], strict)
    
    88
    +    if hardlinks == "hardlinks":
    
    89
    +        checkout_args += ['--hardlinks']
    
    90
    +    checkout_args += ['target.bst', checkout]
    
    91
    +
    
    92
    +    # Now check it out
    
    93
    +    result = cli.run(project=project, args=checkout_args)
    
    94
    +    result.assert_success()
    
    95
    +
    
    96
    +    # Check that the executable hello file is found in the checkout
    
    97
    +    filename = os.path.join(checkout, 'usr', 'bin', 'hello')
    
    98
    +    assert os.path.exists(filename)
    
    99
    +
    
    100
    +    filename = os.path.join(checkout, 'usr', 'include', 'pony.h')
    
    101
    +    assert os.path.exists(filename)
    
    102
    +
    
    103
    +
    
    104
    +@pytest.mark.datafiles(DATA_DIR + "_default")
    
    105
    +def test_show_default(cli, datafiles):
    
    106
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    107
    +    prev_dir = os.getcwd()
    
    108
    +    os.chdir(project)
    
    109
    +    result = cli.run(project=project, silent=True, args=[
    
    110
    +        'build'])
    
    111
    +    os.chdir(prev_dir)
    
    112
    +
    
    113
    +    result.assert_success()
    
    114
    +    results = cli.get_element_state(project, "target2.bst")
    
    115
    +    expected = "cached"
    
    116
    +    if results != expected:
    
    117
    +        raise AssertionError("Expected output:\n{}\nInstead received output:\n{}"
    
    118
    +                             .format(expected, result))
    
    119
    +
    
    120
    +
    
    63 121
     @pytest.mark.datafiles(DATA_DIR)
    
    64 122
     @pytest.mark.parametrize("strict,hardlinks", [
    
    65 123
         ("non-strict", "hardlinks"),
    

  • tests/frontend/project_default/elements/target.bst
    1
    +kind: stack
    
    2
    +description: |
    
    3
    +
    
    4
    +  Main stack target for the bst build test

  • tests/frontend/project_default/elements/target2.bst
    1
    +kind: stack
    
    2
    +description: |
    
    3
    +
    
    4
    +  Main stack target for the bst build test

  • tests/frontend/project_default/project.conf
    1
    +# Project config for frontend build test
    
    2
    +name: test
    
    3
    +
    
    4
    +element-path: elements
    
    5
    +
    
    6
    +fatal-warnings:
    
    7
    +- bad-element-suffix
    
    8
    +
    
    9
    +defaults:
    
    10
    +  target-element: target2.bst

  • tests/frontend/project_world/elements/compose-all.bst
    1
    +kind: compose
    
    2
    +
    
    3
    +depends:
    
    4
    +- filename: import-bin.bst
    
    5
    +  type: build
    
    6
    +- filename: import-dev.bst
    
    7
    +  type: build
    
    8
    +
    
    9
    +config:
    
    10
    +  # Dont try running the sandbox, we dont have a
    
    11
    +  # runtime to run anything in this context.
    
    12
    +  integrate: False

  • tests/frontend/project_world/elements/compose-exclude-dev.bst
    1
    +kind: compose
    
    2
    +
    
    3
    +depends:
    
    4
    +- filename: import-bin.bst
    
    5
    +  type: build
    
    6
    +- filename: import-dev.bst
    
    7
    +  type: build
    
    8
    +
    
    9
    +config:
    
    10
    +  # Dont try running the sandbox, we dont have a
    
    11
    +  # runtime to run anything in this context.
    
    12
    +  integrate: False
    
    13
    +
    
    14
    +  # Exclude the dev domain
    
    15
    +  exclude:
    
    16
    +  - devel

  • tests/frontend/project_world/elements/compose-include-bin.bst
    1
    +kind: compose
    
    2
    +
    
    3
    +depends:
    
    4
    +- filename: import-bin.bst
    
    5
    +  type: build
    
    6
    +- filename: import-dev.bst
    
    7
    +  type: build
    
    8
    +
    
    9
    +config:
    
    10
    +  # Dont try running the sandbox, we dont have a
    
    11
    +  # runtime to run anything in this context.
    
    12
    +  integrate: False
    
    13
    +
    
    14
    +  # Only include the runtim
    
    15
    +  include:
    
    16
    +  - runtime

  • tests/frontend/project_world/elements/import-bin.bst
    1
    +kind: import
    
    2
    +sources:
    
    3
    +- kind: local
    
    4
    +  path: files/bin-files

  • tests/frontend/project_world/elements/import-dev.bst
    1
    +kind: import
    
    2
    +sources:
    
    3
    +- kind: local
    
    4
    +  path: files/dev-files

  • tests/frontend/project_world/elements/rebuild-target.bst
    1
    +kind: compose
    
    2
    +
    
    3
    +build-depends:
    
    4
    +- target.bst

  • tests/frontend/project_world/elements/source-bundle/source-bundle-hello.bst
    1
    +kind: import
    
    2
    +description: the kind of this element must implement generate_script() method
    
    3
    +
    
    4
    +sources:
    
    5
    +- kind: local
    
    6
    +  path: files/source-bundle

  • tests/frontend/project_world/elements/target.bst
    1
    +kind: stack
    
    2
    +description: |
    
    3
    +
    
    4
    +  Main stack target for the bst build test
    
    5
    +
    
    6
    +depends:
    
    7
    +- import-bin.bst
    
    8
    +- compose-all.bst

  • tests/frontend/project_world/files/bar

  • tests/frontend/project_world/files/bin-files/usr/bin/hello
    1
    +#!/bin/bash
    
    2
    +
    
    3
    +echo "Hello !"

  • tests/frontend/project_world/files/build-files/buildstream/build/test
    1
    +test

  • tests/frontend/project_world/files/dev-files/usr/include/pony.h
    1
    +#ifndef __PONY_H__
    
    2
    +#define __PONY_H__
    
    3
    +
    
    4
    +#define PONY_BEGIN "Once upon a time, there was a pony."
    
    5
    +#define PONY_END "And they lived happily ever after, the end."
    
    6
    +
    
    7
    +#define MAKE_PONY(story)  \
    
    8
    +  PONY_BEGIN \
    
    9
    +  story \
    
    10
    +  PONY_END
    
    11
    +
    
    12
    +#endif /* __PONY_H__ */

  • tests/frontend/project_world/files/foo

  • tests/frontend/project_world/files/source-bundle/llamas.txt
    1
    +llamas

  • tests/frontend/project_world/project.conf
    1
    +# Project config for frontend build test
    
    2
    +name: test
    
    3
    +
    
    4
    +element-path: elements



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