[Notes] [Git][BuildStream/buildstream][463-make-dependency-type-default-to-build] 2 commits: Add 'build-depends' and 'runtime-depends' fields to elements



Title: GitLab

Jonathan Maw pushed to branch 463-make-dependency-type-default-to-build at BuildStream / buildstream

Commits:

6 changed files:

Changes:

  • buildstream/_loader/loadelement.py
    ... ... @@ -71,6 +71,7 @@ class LoadElement():
    71 71
                 'kind', 'depends', 'sources', 'sandbox',
    
    72 72
                 'variables', 'environment', 'environment-nocache',
    
    73 73
                 'config', 'public', 'description',
    
    74
    +            'build-depends', 'runtime-depends',
    
    74 75
             ])
    
    75 76
     
    
    76 77
             # Extract the Dependencies
    
    ... ... @@ -127,28 +128,44 @@ class LoadElement():
    127 128
     # Returns:
    
    128 129
     #    (list): a list of Dependency objects
    
    129 130
     #
    
    130
    -def _extract_depends_from_node(node):
    
    131
    -    depends = _yaml.node_get(node, list, Symbol.DEPENDS, default_value=[])
    
    131
    +def _extract_depends_from_node(node, *, key=None):
    
    132
    +    if key is None:
    
    133
    +        build_depends = _extract_depends_from_node(node, key=Symbol.BUILD_DEPENDS)
    
    134
    +        runtime_depends = _extract_depends_from_node(node, key=Symbol.RUNTIME_DEPENDS)
    
    135
    +        depends = _extract_depends_from_node(node, key=Symbol.DEPENDS)
    
    136
    +        return build_depends + runtime_depends + depends
    
    137
    +    elif key == Symbol.BUILD_DEPENDS:
    
    138
    +        default_dep_type = Symbol.BUILD
    
    139
    +    elif key == Symbol.RUNTIME_DEPENDS:
    
    140
    +        default_dep_type = Symbol.RUNTIME
    
    141
    +    elif key == Symbol.DEPENDS:
    
    142
    +        default_dep_type = None
    
    143
    +
    
    144
    +    depends = _yaml.node_get(node, list, key, default_value=[])
    
    132 145
         output_deps = []
    
    133 146
     
    
    134 147
         for dep in depends:
    
    135
    -        dep_provenance = _yaml.node_get_provenance(node, key=Symbol.DEPENDS, indices=[depends.index(dep)])
    
    148
    +        dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[depends.index(dep)])
    
    136 149
     
    
    137 150
             if isinstance(dep, str):
    
    138
    -            dependency = Dependency(dep, provenance=dep_provenance)
    
    151
    +            dependency = Dependency(dep, provenance=dep_provenance, dep_type=default_dep_type)
    
    139 152
     
    
    140 153
             elif isinstance(dep, Mapping):
    
    141
    -            _yaml.node_validate(dep, ['filename', 'type', 'junction'])
    
    142
    -
    
    143
    -            # Make type optional, for this we set it to None
    
    144
    -            dep_type = _yaml.node_get(dep, str, Symbol.TYPE, default_value=None)
    
    145
    -            if dep_type is None or dep_type == Symbol.ALL:
    
    146
    -                dep_type = None
    
    147
    -            elif dep_type not in [Symbol.BUILD, Symbol.RUNTIME]:
    
    148
    -                provenance = _yaml.node_get_provenance(dep, key=Symbol.TYPE)
    
    149
    -                raise LoadError(LoadErrorReason.INVALID_DATA,
    
    150
    -                                "{}: Dependency type '{}' is not 'build', 'runtime' or 'all'"
    
    151
    -                                .format(provenance, dep_type))
    
    154
    +            if default_dep_type:
    
    155
    +                _yaml.node_validate(dep, ['filename', 'junction'])
    
    156
    +                dep_type = default_dep_type
    
    157
    +            else:
    
    158
    +                _yaml.node_validate(dep, ['filename', 'type', 'junction'])
    
    159
    +
    
    160
    +                # Make type optional, for this we set it to None
    
    161
    +                dep_type = _yaml.node_get(dep, str, Symbol.TYPE, default_value=None)
    
    162
    +                if dep_type is None or dep_type == Symbol.ALL:
    
    163
    +                    dep_type = None
    
    164
    +                elif dep_type not in [Symbol.BUILD, Symbol.RUNTIME]:
    
    165
    +                    provenance = _yaml.node_get_provenance(dep, key=Symbol.TYPE)
    
    166
    +                    raise LoadError(LoadErrorReason.INVALID_DATA,
    
    167
    +                                    "{}: Dependency type '{}' is not 'build', 'runtime' or 'all'"
    
    168
    +                                    .format(provenance, dep_type))
    
    152 169
     
    
    153 170
                 filename = _yaml.node_get(dep, str, Symbol.FILENAME)
    
    154 171
                 junction = _yaml.node_get(dep, str, Symbol.JUNCTION, default_value=None)
    
    ... ... @@ -159,13 +176,13 @@ def _extract_depends_from_node(node):
    159 176
     
    
    160 177
             else:
    
    161 178
                 index = depends.index(dep)
    
    162
    -            p = _yaml.node_get_provenance(node, key=Symbol.DEPENDS, indices=[index])
    
    179
    +            p = _yaml.node_get_provenance(node, key=key, indices=[index])
    
    163 180
                 raise LoadError(LoadErrorReason.INVALID_DATA,
    
    164 181
                                 "{}: Dependency is not specified as a string or a dictionary".format(p))
    
    165 182
     
    
    166 183
             output_deps.append(dependency)
    
    167 184
     
    
    168
    -    # Now delete "depends", we dont want it anymore
    
    169
    -    del node[Symbol.DEPENDS]
    
    185
    +    # Now delete the field, we dont want it anymore
    
    186
    +    del node[key]
    
    170 187
     
    
    171 188
         return output_deps

  • buildstream/_loader/types.py
    ... ... @@ -26,6 +26,8 @@ class Symbol():
    26 26
         FILENAME = "filename"
    
    27 27
         KIND = "kind"
    
    28 28
         DEPENDS = "depends"
    
    29
    +    BUILD_DEPENDS = "build-depends"
    
    30
    +    RUNTIME_DEPENDS = "runtime-depends"
    
    29 31
         SOURCES = "sources"
    
    30 32
         CONFIG = "config"
    
    31 33
         VARIABLES = "variables"
    

  • tests/loader/dependencies.py
    ... ... @@ -3,6 +3,7 @@ import pytest
    3 3
     
    
    4 4
     from buildstream._exceptions import LoadError, LoadErrorReason
    
    5 5
     from buildstream._loader import Loader, MetaElement
    
    6
    +from tests.testutils import cli
    
    6 7
     from . import make_loader
    
    7 8
     
    
    8 9
     DATA_DIR = os.path.join(
    
    ... ... @@ -27,7 +28,7 @@ def test_two_files(datafiles):
    27 28
         assert(len(element.dependencies) == 1)
    
    28 29
         firstdep = element.dependencies[0]
    
    29 30
         assert(isinstance(firstdep, MetaElement))
    
    30
    -    assert(firstdep.kind == 'thefirstdep')
    
    31
    +    assert(firstdep.kind == 'manual')
    
    31 32
     
    
    32 33
     
    
    33 34
     @pytest.mark.datafiles(DATA_DIR)
    
    ... ... @@ -47,7 +48,7 @@ def test_shared_dependency(datafiles):
    47 48
         #
    
    48 49
         firstdep = element.dependencies[0]
    
    49 50
         assert(isinstance(firstdep, MetaElement))
    
    50
    -    assert(firstdep.kind == 'thefirstdep')
    
    51
    +    assert(firstdep.kind == 'manual')
    
    51 52
         assert(len(firstdep.dependencies) == 0)
    
    52 53
     
    
    53 54
         # The second specified dependency is 'shareddep'
    
    ... ... @@ -86,7 +87,7 @@ def test_dependency_dict(datafiles):
    86 87
         assert(len(element.dependencies) == 1)
    
    87 88
         firstdep = element.dependencies[0]
    
    88 89
         assert(isinstance(firstdep, MetaElement))
    
    89
    -    assert(firstdep.kind == 'thefirstdep')
    
    90
    +    assert(firstdep.kind == 'manual')
    
    90 91
     
    
    91 92
     
    
    92 93
     @pytest.mark.datafiles(DATA_DIR)
    
    ... ... @@ -186,3 +187,21 @@ def test_all_dependency(datafiles):
    186 187
         assert(isinstance(firstdep, MetaElement))
    
    187 188
         firstbuilddep = element.build_dependencies[0]
    
    188 189
         assert(firstdep == firstbuilddep)
    
    190
    +
    
    191
    +
    
    192
    +@pytest.mark.datafiles(DATA_DIR)
    
    193
    +def test_list_build_dependency(cli, datafiles):
    
    194
    +    project = str(datafiles)
    
    195
    +
    
    196
    +    # Check that the pipeline includes the build dependency
    
    197
    +    deps = cli.get_pipeline(project, ['elements/builddep-list.bst'], scope="build")
    
    198
    +    assert "elements/firstdep.bst" in deps
    
    199
    +
    
    200
    +
    
    201
    +@pytest.mark.datafiles(DATA_DIR)
    
    202
    +def test_list_runtime_dependency(cli, datafiles):
    
    203
    +    project = str(datafiles)
    
    204
    +
    
    205
    +    # Check that the pipeline includes the runtime dependency
    
    206
    +    deps = cli.get_pipeline(project, ['elements/runtimedep-list.bst'], scope="run")
    
    207
    +    assert "elements/firstdep.bst" in deps

  • tests/loader/dependencies/elements/builddep-list.bst
    1
    +kind: stack
    
    2
    +description: This element has a build-only dependency specified via build-depends
    
    3
    +build-depends:
    
    4
    +  - elements/firstdep.bst

  • tests/loader/dependencies/elements/firstdep.bst
    1
    -kind: thefirstdep
    
    1
    +kind: manual
    
    2 2
     description: This is the first dependency

  • tests/loader/dependencies/elements/runtimedep-list.bst
    1
    +kind: stack
    
    2
    +description: This element has a runtime-only dependency
    
    3
    +runtime-depends:
    
    4
    +  - elements/firstdep.bst



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