Commit 1b24148f authored by Chandan Singh's avatar Chandan Singh Committed by Benjamin Schubert
Browse files

Ensure `--deps=none` option works for `bst checkout`

Currently, `bst checkout --deps none` command always produces empty
output. Fix this issue and add regression test for the same.

- element_enums.py: Add Scope.NONE.

- element.py: Ensure Scope.NONE works correctly in addition to
  Scope.RUN/Scope.ALL in Element.dependencies() and Element.search().

- tests/frontend/buildcheckout.py: Fix tests for `--deps none`.

Fixes #670.
parent 87ba19d7
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -438,7 +438,7 @@ class Element(Plugin):
                                                visited=visited, recursed=True)

        # Yeild self only at the end, after anything needed has been traversed
        if should_yield and (recurse or recursed) and (scope in (Scope.ALL, Scope.RUN)):
        if should_yield and (recurse or recursed) and scope != Scope.BUILD:
            yield self

    def search(self, scope, name):
@@ -1353,16 +1353,20 @@ class Element(Plugin):
                if scope == Scope.BUILD:
                    self.stage(sandbox)
                elif scope == Scope.RUN:
                    # Stage deps in the sandbox root
                    if deps == 'run':
                        dependency_scope = Scope.RUN
                    else:
                        dependency_scope = Scope.NONE

                    # Stage deps in the sandbox root
                    with self.timed_activity("Staging dependencies", silent_nested=True):
                            self.stage_dependency_artifacts(sandbox, scope)
                        self.stage_dependency_artifacts(sandbox, dependency_scope)

                    # Run any integration commands provided by the dependencies
                    # once they are all staged and ready
                    if integrate:
                        with self.timed_activity("Integrating sandbox"):
                                for dep in self.dependencies(scope):
                            for dep in self.dependencies(dependency_scope):
                                dep.integrate(sandbox)

            yield sandbox
+6 −0
Original line number Diff line number Diff line
@@ -48,6 +48,12 @@ class Scope(Enum):
    itself.
    """

    NONE = 4
    """Just the element itself, no dependencies.

    *Since: 1.4*
    """


class Consistency():
    """Defines the various consistency states of a :class:`.Source`.
+8 −12
Original line number Diff line number Diff line
@@ -90,9 +90,10 @@ def test_build_invalid_suffix_dep(datafiles, cli, strict, hardlinks):
def test_build_checkout_deps(datafiles, cli, deps):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    checkout = os.path.join(cli.directory, 'checkout')
    element_name = "checkout-deps.bst"

    # First build it
    result = cli.run(project=project, args=['build', 'target.bst'])
    result = cli.run(project=project, args=['build', element_name])
    result.assert_success()

    # Assert that after a successful build, the builddir is empty
@@ -101,20 +102,15 @@ def test_build_checkout_deps(datafiles, cli, deps):
    assert not os.listdir(builddir)

    # Now check it out
    result = cli.run(project=project, args=['checkout', 'target.bst', '--deps', deps, checkout])
    result = cli.run(project=project, args=['checkout', element_name, '--deps', deps, checkout])
    result.assert_success()

    # Check that the executable hello file is found in the checkout
    filename = os.path.join(checkout, 'usr', 'bin', 'hello')

    if deps == "run":
    # Verify output of this element
    filename = os.path.join(checkout, 'etc', 'buildstream', 'config')
    assert os.path.exists(filename)
    else:
        assert not os.path.exists(filename)

    # Check that the executable hello file is found in the checkout
    filename = os.path.join(checkout, 'usr', 'include', 'pony.h')

    # Verify output of this element's runtime dependencies
    filename = os.path.join(checkout, 'usr', 'bin', 'hello')
    if deps == "run":
        assert os.path.exists(filename)
    else: