[Notes] [Git][BuildStream/buildstream][jennis/warn_for_nonexistent_domains] filter.py: Fail if declared domains do not exist in the parent element



Title: GitLab

James Ennis pushed to branch jennis/warn_for_nonexistent_domains at BuildStream / buildstream

Commits:

5 changed files:

Changes:

  • buildstream/plugins/elements/filter.py
    ... ... @@ -66,6 +66,8 @@ class FilterElement(Element):
    66 66
             self.include = self.node_get_member(node, list, 'include')
    
    67 67
             self.exclude = self.node_get_member(node, list, 'exclude')
    
    68 68
             self.include_orphans = self.node_get_member(node, bool, 'include-orphans')
    
    69
    +        self.include_provenance = self.node_provenance(node, member_name='include')
    
    70
    +        self.exclude_provenance = self.node_provenance(node, member_name='exclude')
    
    69 71
     
    
    70 72
         def preflight(self):
    
    71 73
             # Exactly one build-depend is permitted
    
    ... ... @@ -105,6 +107,31 @@ class FilterElement(Element):
    105 107
         def assemble(self, sandbox):
    
    106 108
             with self.timed_activity("Staging artifact", silent_nested=True):
    
    107 109
                 for dep in self.dependencies(Scope.BUILD, recurse=False):
    
    110
    +                # Check that all the included/excluded domains exist
    
    111
    +                pub_data = dep.get_public_data('bst')
    
    112
    +                split_rules = pub_data.get('split-rules', {})
    
    113
    +                unfound_includes = []
    
    114
    +                for domain in self.include:
    
    115
    +                    if domain not in split_rules:
    
    116
    +                        unfound_includes.append(domain)
    
    117
    +                unfound_excludes = []
    
    118
    +                for domain in self.exclude:
    
    119
    +                    if domain not in split_rules:
    
    120
    +                        unfound_excludes.append(domain)
    
    121
    +
    
    122
    +                detail = []
    
    123
    +                if unfound_includes:
    
    124
    +                    detail.append("Unknown domains were used in {}".format(self.include_provenance))
    
    125
    +                    detail.extend([' - {}'.format(domain) for domain in unfound_includes])
    
    126
    +
    
    127
    +                if unfound_excludes:
    
    128
    +                    detail.append("Unknown domains were used in {}".format(self.exclude_provenance))
    
    129
    +                    detail.extend([' - {}'.format(domain) for domain in unfound_excludes])
    
    130
    +
    
    131
    +                if detail:
    
    132
    +                    detail = '\n'.join(detail)
    
    133
    +                    raise ElementError("Unknown domains declared.", detail=detail)
    
    134
    +
    
    108 135
                     dep.stage_artifact(sandbox, include=self.include,
    
    109 136
                                        exclude=self.exclude, orphans=self.include_orphans)
    
    110 137
             return ""
    

  • buildstream/plugins/elements/filter.yaml
    ... ... @@ -5,9 +5,8 @@ config:
    5 5
       # A list of domains to include from each artifact, as
    
    6 6
       # they were defined in the element's 'split-rules'.
    
    7 7
       #
    
    8
    -  # Since domains can be added, it is not an error to
    
    9
    -  # specify domains which may not exist for all of the
    
    10
    -  # elements in this composition.
    
    8
    +  # If a domain is specified that does not exist, the
    
    9
    +  # filter element will fail to build.
    
    11 10
       #
    
    12 11
       # The default empty list indicates that all domains
    
    13 12
       # from each dependency should be included.
    

  • tests/elements/filter.py
    ... ... @@ -484,3 +484,14 @@ def test_filter_include_with_indirect_deps(datafiles, cli, tmpdir):
    484 484
         # indirect dependencies shouldn't be staged and filtered
    
    485 485
         assert not os.path.exists(os.path.join(checkout, "foo"))
    
    486 486
         assert not os.path.exists(os.path.join(checkout, "bar"))
    
    487
    +
    
    488
    +
    
    489
    +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
    
    490
    +def test_filter_fails_for_nonexisting_domain(datafiles, cli, tmpdir):
    
    491
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    492
    +    result = cli.run(project=project, args=['build', 'output-include-nonexistent-domain.bst'])
    
    493
    +    result.assert_main_error(ErrorDomain.STREAM, None)
    
    494
    +
    
    495
    +    error = "Unknown domains were used in output-include-nonexistent-domain.bst [line 7 column 2]"
    
    496
    +    assert error in result.stderr
    
    497
    +    assert '- unknown_file' in result.stderr

  • tests/elements/filter/basic/elements/deps-permitted.bst
    1 1
     kind: filter
    
    2 2
     depends:
    
    3
    -- filename: output-include.bst
    
    3
    +- filename: input.bst
    
    4 4
       type: build
    
    5 5
     - filename: output-exclude.bst
    
    6 6
       type: runtime
    

  • tests/elements/filter/basic/elements/output-include-nonexistent-domain.bst
    1
    +kind: filter
    
    2
    +depends:
    
    3
    +- filename: input.bst
    
    4
    +  type: build
    
    5
    +config:
    
    6
    +  include:
    
    7
    +  - unknown_file
    
    8
    +



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