[Notes] [Git][BuildStream/buildstream][issue_640-Build-All] 5 commits: projectconfig.yaml: Add default-element var



Title: GitLab

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

Commits:

23 changed files:

Changes:

  • NEWS
    ... ... @@ -12,6 +12,10 @@ buildstream 1.3.1
    12 12
         specific. Recommendation if you are building in Linux is to use the
    
    13 13
         ones being used in freedesktop-sdk project, for example
    
    14 14
     
    
    15
    +  o Running `bst build` without elements specified will now attempt to build
    
    16
    +    the default element defined in the projcet configuration.
    
    17
    +    If no default element is defined, all elements in the project will be built
    
    18
    +
    
    15 19
       o All elements must now be suffixed with `.bst`
    
    16 20
         Attempting to use an element that does not have the `.bst` extension,
    
    17 21
         will result in a warning.
    

  • buildstream/_frontend/cli.py
    ... ... @@ -306,7 +306,11 @@ def init(app, project_name, format_version, element_path, force):
    306 306
                     type=click.Path(readable=False))
    
    307 307
     @click.pass_obj
    
    308 308
     def build(app, elements, all_, track_, track_save, track_all, track_except, track_cross_junctions):
    
    309
    -    """Build elements in a pipeline"""
    
    309
    +    """Build elements in a pipeline
    
    310
    +
    
    311
    +       Declaring no elements with result in building a default element if one is declared in the project configuration.
    
    312
    +
    
    313
    +       If no default is declared, all elements in the project will be built"""
    
    310 314
     
    
    311 315
         if (track_except or track_cross_junctions) and not (track_ or track_all):
    
    312 316
             click.echo("ERROR: The --track-except and --track-cross-junctions options "
    
    ... ... @@ -321,6 +325,8 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac
    321 325
                 guessed_target = app.context.guess_element()
    
    322 326
                 if guessed_target:
    
    323 327
                     elements = (guessed_target,)
    
    328
    +            else:
    
    329
    +                app.project.get_default_elements()
    
    324 330
     
    
    325 331
             if track_all:
    
    326 332
                 track_ = elements
    

  • buildstream/_project.py
    ... ... @@ -228,7 +228,7 @@ class Project():
    228 228
                 'element-path', 'variables',
    
    229 229
                 'environment', 'environment-nocache',
    
    230 230
                 'split-rules', 'elements', 'plugins',
    
    231
    -            'aliases', 'name',
    
    231
    +            'aliases', 'name', 'defaults',
    
    232 232
                 'artifacts', 'options',
    
    233 233
                 'fail-on-overlap', 'shell', 'fatal-warnings',
    
    234 234
                 'ref-storage', 'sandbox', 'mirrors', 'remote-execution',
    
    ... ... @@ -391,6 +391,36 @@ class Project():
    391 391
             # Reset the element loader state
    
    392 392
             Element._reset_load_state()
    
    393 393
     
    
    394
    +
    
    395
    +    # get_default_elements()
    
    396
    +    #
    
    397
    +    # This function is used to gather either:
    
    398
    +    # The project default element (if defined in project.conf)
    
    399
    +    # or
    
    400
    +    # All elements in the project
    
    401
    +    #
    
    402
    +    def get_default_elements(self):
    
    403
    +        output = []
    
    404
    +
    
    405
    +        # The project is not required to have an element-path
    
    406
    +        element_directory = self._project_conf.get('element-path')
    
    407
    +
    
    408
    +        # The project may have a default element defined
    
    409
    +        default_element = self._project_conf.get("defaults", {}).get("target-element", None)
    
    410
    +
    
    411
    +        if default_element:
    
    412
    +            return (default_element,)
    
    413
    +
    
    414
    +        directory = os.path.join(self.directory, element_directory)
    
    415
    +        for root, _, files in os.walk(directory):
    
    416
    +            for file in files:
    
    417
    +                if file.endswith(".bst"):
    
    418
    +                    rel_dir = os.path.relpath(root, directory)
    
    419
    +                    rel_file = os.path.join(rel_dir, file).lstrip("./")
    
    420
    +                    output.append(rel_file)
    
    421
    +        return tuple(output)
    
    422
    +
    
    423
    +
    
    394 424
         # _load():
    
    395 425
         #
    
    396 426
         # Loads the project configuration file in the project
    

  • buildstream/data/projectconfig.yaml
    ... ... @@ -167,3 +167,10 @@ shell:
    167 167
       # Command to run when `bst shell` does not provide a command
    
    168 168
       #
    
    169 169
       command: [ 'sh', '-i' ]
    
    170
    +
    
    171
    +# Default Targets
    
    172
    +#
    
    173
    +defaults:
    
    174
    +
    
    175
    +  # Set a Default element to build when none are defined 
    
    176
    +  target-element: None

  • tests/frontend/buildcheckout.py
    ... ... @@ -2,6 +2,7 @@ import os
    2 2
     import tarfile
    
    3 3
     import hashlib
    
    4 4
     import pytest
    
    5
    +import subprocess
    
    5 6
     from tests.testutils import cli, create_repo, ALL_REPO_KINDS, generate_junction
    
    6 7
     
    
    7 8
     from buildstream import _yaml
    
    ... ... @@ -60,6 +61,35 @@ def test_build_checkout(datafiles, cli, strict, hardlinks):
    60 61
         assert os.path.exists(filename)
    
    61 62
     
    
    62 63
     
    
    64
    +@pytest.mark.datafiles(DATA_DIR + "_world")
    
    65
    +def test_build_default_all(datafiles, cli):
    
    66
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    67
    +    result = cli.run(project=project, cwd=project, silent=True, args=['build'])
    
    68
    +
    
    69
    +    result.assert_success()
    
    70
    +    target_dir = os.path.join(cli.directory, DATA_DIR + "_world", "elements")
    
    71
    +    output_dir = os.path.join(cli.directory, "logs", "test")
    
    72
    +
    
    73
    +    expected = subprocess.Popen(('ls', target_dir), stdout=subprocess.PIPE)
    
    74
    +    expected = subprocess.check_output(("wc", "-w"), stdin=expected.stdout)
    
    75
    +
    
    76
    +    results = subprocess.Popen(('ls', output_dir), stdout=subprocess.PIPE)
    
    77
    +    results = subprocess.check_output(("wc", "-w"), stdin=results.stdout)
    
    78
    +
    
    79
    +    assert results == expected
    
    80
    +
    
    81
    +
    
    82
    +@pytest.mark.datafiles(DATA_DIR + "_default")
    
    83
    +def test_build_default(cli, datafiles):
    
    84
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    85
    +    result = cli.run(project=project, cwd=project , silent=True, args=['build'])
    
    86
    +
    
    87
    +    result.assert_success()
    
    88
    +    results = cli.get_element_state(project, "target2.bst")
    
    89
    +    expected = "cached"
    
    90
    +    assert results == expected:
    
    91
    +
    
    92
    +
    
    63 93
     @pytest.mark.datafiles(DATA_DIR)
    
    64 94
     @pytest.mark.parametrize("strict,hardlinks", [
    
    65 95
         ("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]