Esempio n. 1
0
def test_dummy_sandbox_fallback(cli, datafiles, tmp_path):
    # Create symlink to buildbox-casd to work with custom PATH
    buildbox_casd = tmp_path.joinpath("bin/buildbox-casd")
    buildbox_casd.parent.mkdir()
    os.symlink(utils.get_host_tool("buildbox-casd"), str(buildbox_casd))

    project = str(datafiles)
    element_path = os.path.join(project, "elements", "element.bst")

    # Write out our test target
    element = {
        "kind": "script",
        "depends": [{"filename": "base.bst", "type": "build",},],
        "config": {"commands": ["true",],},
    }
    _yaml.roundtrip_dump(element, element_path)

    # Build without access to host tools, this will fail
    result = cli.run(project=project, args=["build", "element.bst"], env={"PATH": str(tmp_path.joinpath("bin"))},)
    # But if we dont spesify a sandbox then we fall back to dummy, we still
    # fail early but only once we know we need a facny sandbox and that
    # dumy is not enough, there for element gets fetched and so is buildable

    result.assert_task_error(ErrorDomain.SANDBOX, "unavailable-local-sandbox")
    assert cli.get_element_state(project, "element.bst") == "buildable"
Esempio n. 2
0
def test_host_tools_errors_are_not_cached(cli, datafiles, tmp_path):
    # Create symlink to buildbox-casd to work with custom PATH
    buildbox_casd = tmp_path.joinpath("bin/buildbox-casd")
    buildbox_casd.parent.mkdir()
    os.symlink(utils.get_host_tool("buildbox-casd"), str(buildbox_casd))

    project = str(datafiles)
    element_path = os.path.join(project, "elements", "element.bst")

    # Write out our test target
    element = {
        "kind": "script",
        "depends": [{"filename": "base.bst", "type": "build",},],
        "config": {"commands": ["true",],},
    }
    _yaml.roundtrip_dump(element, element_path)

    # Build without access to host tools, this will fail
    result1 = cli.run(project=project, args=["build", "element.bst"], env={"PATH": str(tmp_path.joinpath("bin"))},)
    result1.assert_task_error(ErrorDomain.SANDBOX, "unavailable-local-sandbox")
    assert cli.get_element_state(project, "element.bst") == "buildable"

    # When rebuilding, this should work
    result2 = cli.run(project=project, args=["build", "element.bst"])
    result2.assert_success()
    assert cli.get_element_state(project, "element.bst") == "cached"
Esempio n. 3
0
 def preflight(self):
     if self.allow_host_bazel:
         try:
             self.host_bazel = utils.get_host_tool("bazel")
         except utils.ProgramNotFoundError:
             self.warn(
                 "{}: Host bazel allowed, but no suitable command found".
                 format(self),
                 detail=
                 "This may cause an error if there is no repository file in the bazel repo",
             )
Esempio n. 4
0
    def preflight(self):
        # Check if git is installed, get the binary at the same time
        self.host_git = utils.get_host_tool("git")

        rc, version_str = self.check_output([self.host_git, "--version"])
        # e.g. on Git for Windows we get "git version 2.21.0.windows.1".
        # e.g. on Mac via Homebrew we get "git version 2.19.0".
        if rc == 0:
            self.host_git_version = tuple(
                int(x) for x in version_str.split(" ")[2].split(".")[:3])
        else:
            self.host_git_version = None
Esempio n. 5
0
    def preflight(self):
        # Try to find a pip version that spports download command
        self.host_pip = None
        for python in reversed(_PYTHON_VERSIONS):
            try:
                host_python = utils.get_host_tool(python)
                rc = self.call([host_python, "-m", "pip", "download", "--help"])
                if rc == 0:
                    self.host_pip = [host_python, "-m", "pip"]
                    break
            except utils.ProgramNotFoundError:
                pass

        if self.host_pip is None:
            raise SourceError("{}: Unable to find a suitable pip command".format(self))
Esempio n. 6
0
# Pylint doesn't play well with fixtures and dependency injection from pytest
# pylint: disable=redefined-outer-name

import subprocess
import pytest

from buildstream.testing import Repo
from buildstream import utils, ProgramNotFoundError

try:
    OSTREE_CLI = utils.get_host_tool("ostree")
    HAVE_OSTREE_CLI = True
except ProgramNotFoundError:
    HAVE_OSTREE_CLI = False


class OSTree(Repo):
    def __init__(self, directory, subdir):
        if not HAVE_OSTREE_CLI:
            pytest.skip("ostree cli is not available")

        super().__init__(directory, subdir)
        self.ostree = OSTREE_CLI

    def create(self, directory, *, gpg_sign=None, gpg_homedir=None):
        subprocess.call(
            [self.ostree, "init", "--repo", self.repo, "--mode", "archive-z2"])

        commit_args = [
            self.ostree,
            "commit",
Esempio n. 7
0
# Some things resolved about the execution site,
# so we dont have to repeat this everywhere
#
import os
import stat
import subprocess
import sys
import tempfile
from typing import Optional  # pylint: disable=unused-import

from buildstream import utils, ProgramNotFoundError
from buildstream._platform import Platform


try:
    GIT = utils.get_host_tool("git")  # type: Optional[str]
    HAVE_GIT = True

    out = str(subprocess.check_output(["git", "--version"]), "utf-8")
    # e.g. on Git for Windows we get "git version 2.21.0.windows.1".
    # e.g. on Mac via Homebrew we get "git version 2.19.0".
    version = tuple(int(x) for x in out.split(" ")[2].split(".")[:3])
    HAVE_OLD_GIT = version < (1, 8, 5)

    GIT_ENV = {
        "GIT_AUTHOR_DATE": "1320966000 +0200",
        "GIT_AUTHOR_NAME": "tomjon",
        "GIT_AUTHOR_EMAIL": "*****@*****.**",
        "GIT_COMMITTER_DATE": "1320966000 +0200",
        "GIT_COMMITTER_NAME": "tomjon",
        "GIT_COMMITTER_EMAIL": "*****@*****.**",
 def preflight(self):
     # Check if patch is installed, get the binary at the same time
     self.host_quilt = utils.get_host_tool("quilt")
Esempio n. 9
0
def _symlink_host_tools_to_dir(host_tools, dir_):
    dir_.mkdir(exist_ok=True)
    for tool in host_tools:
        target_path = dir_ / tool
        os.symlink(utils.get_host_tool(tool), str(target_path))
 def preflight(self):
     # Check if ostree is installed, get the binary at the same time
     self.ostree = utils.get_host_tool("ostree")
Esempio n. 11
0
 def preflight(self):
     # Check if bzr is installed, get the binary at the same time.
     self.host_bzr = utils.get_host_tool("bzr")
Esempio n. 12
0
 def preflight(self):
     self.host_lzip = None
     if self.url.endswith(".lz"):
         self.host_lzip = utils.get_host_tool("lzip")
Esempio n. 13
0
 def preflight(self):
     # Check if git is installed, get the binary at the same time
     self.host_git = utils.get_host_tool('git')
     if self.use_lfs:
         self.call([self.host_git, 'lfs', '--version'],
                   fail="Git lfs not installed")
Esempio n. 14
0
# Some things resolved about the execution site,
# so we don't have to repeat this everywhere
#
import os
import sys

from buildstream import utils, ProgramNotFoundError

try:
    utils.get_host_tool('bzr')
    HAVE_BZR = True
except ProgramNotFoundError:
    HAVE_BZR = False

try:
    utils.get_host_tool('git')
    HAVE_GIT = True
except ProgramNotFoundError:
    HAVE_GIT = False

try:
    utils.get_host_tool('ostree')
    HAVE_OSTREE_CLI = True
except ProgramNotFoundError:
    HAVE_OSTREE_CLI = False

try:
    from buildstream import _ostree
    HAVE_OSTREE = True
except (ImportError, ValueError):
    HAVE_OSTREE = False