Commit 41e91ab5 authored by Dor Askayo's avatar Dor Askayo
Browse files

filter.py: don't recurse when staging dependencies

Also bump the element's version so cached artifacts would be
invalidated.

Fixes #883
parent a2140d74
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ from buildstream import Element, ElementError, Scope
class FilterElement(Element):
    # pylint: disable=attribute-defined-outside-init

    BST_ARTIFACT_VERSION = 1

    # The filter element's output is its dependencies, so
    # we must rebuild if the dependencies change even when
    # not in strict build plans.
@@ -102,7 +104,7 @@ class FilterElement(Element):

    def assemble(self, sandbox):
        with self.timed_activity("Staging artifact", silent_nested=True):
            for dep in self.dependencies(Scope.BUILD):
            for dep in self.dependencies(Scope.BUILD, recurse=False):
                dep.stage_artifact(sandbox, include=self.include,
                                   exclude=self.exclude, orphans=self.include_orphans)
        return ""
+20 −0
Original line number Diff line number Diff line
@@ -464,3 +464,23 @@ def test_filter_track_multi_exclude(datafiles, cli, tmpdir):
    assert "ref" not in new_input["sources"][0]
    new_input2 = _yaml.load(input2_file)
    assert new_input2["sources"][0]["ref"] == ref


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
def test_filter_include_with_indirect_deps(datafiles, cli, tmpdir):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    result = cli.run(project=project, args=[
        'build', 'output-include-with-indirect-deps.bst'])
    result.assert_success()

    checkout = os.path.join(tmpdir.dirname, tmpdir.basename, 'checkout')
    result = cli.run(project=project, args=[
        'artifact', 'checkout', 'output-include-with-indirect-deps.bst', '--directory', checkout])
    result.assert_success()

    # direct dependencies should be staged and filtered
    assert os.path.exists(os.path.join(checkout, "baz"))

    # indirect dependencies shouldn't be staged and filtered
    assert not os.path.exists(os.path.join(checkout, "foo"))
    assert not os.path.exists(os.path.join(checkout, "bar"))
+14 −0
Original line number Diff line number Diff line
kind: import

depends:
- filename: input.bst

sources:
- kind: local
  path: files

public:
  bst:
    split-rules:
      baz:
      - /baz
+5 −0
Original line number Diff line number Diff line
kind: filter

depends:
- filename: input-with-deps.bst
  type: build