diff options
-rw-r--r-- | doc/source/core_plugins.rst | 1 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/bzr.py | 214 | ||||
-rw-r--r-- | src/buildstream/testing/_utils/site.py | 9 | ||||
-rw-r--r-- | tests/cachekey/cachekey.py | 3 | ||||
-rw-r--r-- | tests/cachekey/project/sources/bzr1.bst | 6 | ||||
-rw-r--r-- | tests/cachekey/project/sources/bzr1.expected | 1 | ||||
-rw-r--r-- | tests/cachekey/project/target.bst | 1 | ||||
-rw-r--r-- | tests/cachekey/project/target.expected | 2 | ||||
-rwxr-xr-x | tests/conftest.py | 2 | ||||
-rw-r--r-- | tests/frontend/workspace.py | 20 | ||||
-rw-r--r-- | tests/sources/bzr.py | 40 | ||||
-rw-r--r-- | tests/sources/bzr/basic/test | 1 | ||||
-rw-r--r-- | tests/sources/bzr/project.conf | 3 | ||||
-rw-r--r-- | tests/testutils/repo/bzr.py | 47 |
14 files changed, 2 insertions, 348 deletions
diff --git a/doc/source/core_plugins.rst b/doc/source/core_plugins.rst index e7889362b..8efe8a7c8 100644 --- a/doc/source/core_plugins.rst +++ b/doc/source/core_plugins.rst @@ -53,7 +53,6 @@ information. sources/tar sources/zip sources/git - sources/bzr sources/patch sources/pip diff --git a/src/buildstream/plugins/sources/bzr.py b/src/buildstream/plugins/sources/bzr.py deleted file mode 100644 index 8a02eff95..000000000 --- a/src/buildstream/plugins/sources/bzr.py +++ /dev/null @@ -1,214 +0,0 @@ -# Copyright (C) 2017 Codethink Limited -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library. If not, see <http://www.gnu.org/licenses/>. -# -# Authors: -# Jonathan Maw <jonathan.maw@codethink.co.uk> - -""" -bzr - stage files from a bazaar repository -========================================== - -**Host dependencies:** - - * bzr - -**Usage:** - -.. code:: yaml - - # Specify the bzr source kind - kind: bzr - - # Specify the bzr url. Bazaar URLs come in many forms, see - # `bzr help urlspec` for more information. Using an alias defined - # in your project configuration is encouraged. - url: https://launchpad.net/bzr - - # Specify the tracking branch. This is mandatory, as bzr cannot identify - # an individual revision outside its branch. bzr URLs that omit the branch - # name implicitly specify the trunk branch, but bst requires this to be - # explicit. - track: trunk - - # Specify the ref. This is a revision number. This is usually a decimal, - # but revisions on a branch are of the form - # <revision-branched-from>.<branch-number>.<revision-since-branching> - # e.g. 6622.1.6. - # The ref must be specified to build, and 'bst source track' will update the - # revision number to the one on the tip of the branch specified in 'track'. - ref: 6622 - -See :ref:`built-in functionality doumentation <core_source_builtins>` for -details on common configuration options for sources. -""" - -import os -import shutil -import fcntl -from contextlib import contextmanager - -from buildstream import Source, SourceError -from buildstream import utils - - -class BzrSource(Source): - # pylint: disable=attribute-defined-outside-init - - def configure(self, node): - node.validate_keys(["url", "track", "ref", *Source.COMMON_CONFIG_KEYS]) - - self.original_url = node.get_str("url") - self.tracking = node.get_str("track") - self.ref = node.get_str("ref", None) - self.url = self.translate_url(self.original_url) - - def preflight(self): - # Check if bzr is installed, get the binary at the same time. - self.host_bzr = utils.get_host_tool("bzr") - - def get_unique_key(self): - return [self.original_url, self.tracking, self.ref] - - def is_cached(self): - with self._locked(): - return self._check_ref() - - def load_ref(self, node): - self.ref = node.get_str("ref", None) - - def get_ref(self): - return self.ref - - def set_ref(self, ref, node): - node["ref"] = self.ref = ref - - def track(self): # pylint: disable=arguments-differ - with self.timed_activity("Tracking {}".format(self.url), silent_nested=True), self._locked(): - self._ensure_mirror(skip_ref_check=True) - ret, out = self.check_output( - [self.host_bzr, "version-info", "--custom", "--template={revno}", self._get_branch_dir()], - fail="Failed to read the revision number at '{}'".format(self._get_branch_dir()), - ) - if ret != 0: - raise SourceError("{}: Failed to get ref for tracking {}".format(self, self.tracking)) - - return out - - def fetch(self): # pylint: disable=arguments-differ - with self.timed_activity("Fetching {}".format(self.url), silent_nested=True), self._locked(): - self._ensure_mirror() - - def stage(self, directory): - self.call( - [ - self.host_bzr, - "checkout", - "--lightweight", - "--revision=revno:{}".format(self.ref), - self._get_branch_dir(), - directory, - ], - fail="Failed to checkout revision {} from branch {} to {}".format( - self.ref, self._get_branch_dir(), directory - ), - ) - # Remove .bzr dir - shutil.rmtree(os.path.join(directory, ".bzr")) - - def init_workspace(self, directory): - url = os.path.join(self.url, self.tracking) - with self.timed_activity('Setting up workspace "{}"'.format(directory), silent_nested=True): - # Checkout from the cache - self.call( - [ - self.host_bzr, - "branch", - "--use-existing-dir", - "--revision=revno:{}".format(self.ref), - self._get_branch_dir(), - directory, - ], - fail="Failed to branch revision {} from branch {} to {}".format( - self.ref, self._get_branch_dir(), directory - ), - ) - # Switch the parent branch to the source's origin - self.call( - [self.host_bzr, "switch", "--directory={}".format(directory), url], - fail="Failed to switch workspace's parent branch to {}".format(url), - ) - - # _locked() - # - # This context manager ensures exclusive access to the - # bzr repository. - # - @contextmanager - def _locked(self): - lockdir = os.path.join(self.get_mirror_directory(), "locks") - lockfile = os.path.join(lockdir, utils.url_directory_name(self.original_url) + ".lock") - os.makedirs(lockdir, exist_ok=True) - with open(lockfile, "w") as lock: - fcntl.flock(lock, fcntl.LOCK_EX) - try: - yield - finally: - fcntl.flock(lock, fcntl.LOCK_UN) - - def _check_ref(self): - # If the mirror doesnt exist yet, then we dont have the ref - if not os.path.exists(self._get_branch_dir()): - return False - - return self.call([self.host_bzr, "revno", "--revision=revno:{}".format(self.ref), self._get_branch_dir()]) == 0 - - def _get_branch_dir(self): - return os.path.join(self._get_mirror_dir(), self.tracking) - - def _get_mirror_dir(self): - return os.path.join(self.get_mirror_directory(), utils.url_directory_name(self.original_url)) - - def _ensure_mirror(self, skip_ref_check=False): - mirror_dir = self._get_mirror_dir() - bzr_metadata_dir = os.path.join(mirror_dir, ".bzr") - if not os.path.exists(bzr_metadata_dir): - self.call( - [self.host_bzr, "init-repo", "--no-trees", mirror_dir], fail="Failed to initialize bzr repository" - ) - - branch_dir = os.path.join(mirror_dir, self.tracking) - branch_url = self.url + "/" + self.tracking - if not os.path.exists(branch_dir): - # `bzr branch` the branch if it doesn't exist - # to get the upstream code - self.call( - [self.host_bzr, "branch", branch_url, branch_dir], - fail="Failed to branch from {} to {}".format(branch_url, branch_dir), - ) - - else: - # `bzr pull` the branch if it does exist - # to get any changes to the upstream code - self.call( - [self.host_bzr, "pull", "--directory={}".format(branch_dir), branch_url], - fail="Failed to pull new changes for {}".format(branch_dir), - ) - - if not skip_ref_check and not self._check_ref(): - raise SourceError("Failed to ensure ref '{}' was mirrored".format(self.ref), reason="ref-not-mirrored") - - -def setup(): - return BzrSource diff --git a/src/buildstream/testing/_utils/site.py b/src/buildstream/testing/_utils/site.py index 0dfbce222..61b993667 100644 --- a/src/buildstream/testing/_utils/site.py +++ b/src/buildstream/testing/_utils/site.py @@ -37,15 +37,6 @@ except ProgramNotFoundError: GIT_ENV = dict() try: - BZR = utils.get_host_tool("bzr") # type: Optional[str] - HAVE_BZR = True - BZR_ENV = {"BZR_EMAIL": "Testy McTesterson <testy.mctesterson@example.com>"} -except ProgramNotFoundError: - BZR = None - HAVE_BZR = False - BZR_ENV = {} - -try: utils.get_host_tool("bwrap") HAVE_BWRAP = True HAVE_BWRAP_JSON_STATUS = _site.get_bwrap_version() >= (0, 3, 2) diff --git a/tests/cachekey/cachekey.py b/tests/cachekey/cachekey.py index 08870f2a0..4e1ca205f 100644 --- a/tests/cachekey/cachekey.py +++ b/tests/cachekey/cachekey.py @@ -45,7 +45,7 @@ import os import pytest from buildstream.testing.runcli import cli # pylint: disable=unused-import -from buildstream.testing._utils.site import HAVE_BZR, HAVE_GIT, IS_LINUX, MACHINE_ARCH +from buildstream.testing._utils.site import HAVE_GIT, IS_LINUX, MACHINE_ARCH from buildstream.plugin import CoreWarnings from buildstream import _yaml @@ -155,7 +155,6 @@ DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project",) # @pytest.mark.skipif(MACHINE_ARCH != "x86-64", reason="Cache keys depend on architecture") @pytest.mark.skipif(not IS_LINUX, reason="Only available on linux") -@pytest.mark.skipif(HAVE_BZR is False, reason="bzr is not available") @pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") @pytest.mark.datafiles(DATA_DIR) def test_cache_key(datafiles, cli): diff --git a/tests/cachekey/project/sources/bzr1.bst b/tests/cachekey/project/sources/bzr1.bst deleted file mode 100644 index 4798d8add..000000000 --- a/tests/cachekey/project/sources/bzr1.bst +++ /dev/null @@ -1,6 +0,0 @@ -kind: import -sources: -- kind: bzr - url: https://launchpad.net/bzr - track: trunk - ref: 6622 diff --git a/tests/cachekey/project/sources/bzr1.expected b/tests/cachekey/project/sources/bzr1.expected deleted file mode 100644 index 50eff30c6..000000000 --- a/tests/cachekey/project/sources/bzr1.expected +++ /dev/null @@ -1 +0,0 @@ -2825e2d55baa6617ec7e559ae554bb66761105a1ce50028bffdb983b6bb11707
\ No newline at end of file diff --git a/tests/cachekey/project/target.bst b/tests/cachekey/project/target.bst index cabf3f7bf..c95a0a8ff 100644 --- a/tests/cachekey/project/target.bst +++ b/tests/cachekey/project/target.bst @@ -4,7 +4,6 @@ description: | This is the main entry point including cases in the cache key test. depends: -- sources/bzr1.bst - sources/git1.bst - sources/git2.bst - sources/git3.bst diff --git a/tests/cachekey/project/target.expected b/tests/cachekey/project/target.expected index cf38ddcfe..920ebd7d7 100644 --- a/tests/cachekey/project/target.expected +++ b/tests/cachekey/project/target.expected @@ -1 +1 @@ -a57f84353d1528b3ecbd9993ac02a20d0355f2451e19700172c95575af9a5b48
\ No newline at end of file +42eba0ea5bada0a2f49514ac652b0f4807bb6b8d179f12d660838bd2cdc1bfe9 diff --git a/tests/conftest.py b/tests/conftest.py index 8d33fa024..f62bec51e 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -31,7 +31,6 @@ from buildstream.testing.integration import integration_cache # pylint: disable from tests.testutils.repo.git import Git -from tests.testutils.repo.bzr import Bzr from tests.testutils.repo.tar import Tar from tests.testutils.repo.zip import Zip @@ -111,7 +110,6 @@ def remote_services(request): # Setup for templated source tests # ################################################# register_repo_kind("git", Git, None) -register_repo_kind("bzr", Bzr, None) register_repo_kind("tar", Tar, None) register_repo_kind("zip", Zip, None) diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py index b450d18f4..dd054fcad 100644 --- a/tests/frontend/workspace.py +++ b/tests/frontend/workspace.py @@ -159,23 +159,6 @@ def open_workspace( @pytest.mark.datafiles(DATA_DIR) -def test_open_bzr_customize(cli, tmpdir, datafiles): - element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "bzr") - - # Check that the .bzr dir exists - bzrdir = os.path.join(workspace, ".bzr") - assert os.path.isdir(bzrdir) - - # Check that the correct origin branch is set - element_config = _yaml.load(os.path.join(project, "elements", element_name)) - source_config = element_config.get_sequence("sources").mapping_at(0) - output = subprocess.check_output(["bzr", "info"], cwd=workspace) - stripped_url = source_config.get_str("url").lstrip("file:///") - expected_output_str = "checkout of branch: /{}/{}".format(stripped_url, source_config.get_str("track")) - assert expected_output_str in str(output) - - -@pytest.mark.datafiles(DATA_DIR) def test_open_multi(cli, tmpdir, datafiles): workspace_object = WorkspaceCreator(cli, tmpdir, datafiles) @@ -186,11 +169,8 @@ def test_open_multi(cli, tmpdir, datafiles): workspace_lsdir = os.listdir(workspace) if kind == "git": assert ".git" in workspace_lsdir - elif kind == "bzr": - assert ".bzr" in workspace_lsdir else: assert ".git" not in workspace_lsdir - assert ".bzr" not in workspace_lsdir @pytest.mark.skipif(os.geteuid() == 0, reason="root may have CAP_DAC_OVERRIDE and ignore permissions") diff --git a/tests/sources/bzr.py b/tests/sources/bzr.py deleted file mode 100644 index 2dcacfef5..000000000 --- a/tests/sources/bzr.py +++ /dev/null @@ -1,40 +0,0 @@ -# Pylint doesn't play well with fixtures and dependency injection from pytest -# pylint: disable=redefined-outer-name - -import os -import pytest - -from buildstream.testing import cli # pylint: disable=unused-import -from buildstream.testing import create_repo -from buildstream.testing import generate_element -from buildstream.testing._utils.site import HAVE_BZR - -DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "bzr") - - -@pytest.mark.skipif(HAVE_BZR is False, reason="bzr is not available") -@pytest.mark.datafiles(os.path.join(DATA_DIR)) -def test_fetch_checkout(cli, tmpdir, datafiles): - project = str(datafiles) - checkoutdir = os.path.join(str(tmpdir), "checkout") - - repo = create_repo("bzr", str(tmpdir)) - ref = repo.create(os.path.join(project, "basic")) - - # Write out our test target - element = {"kind": "import", "sources": [repo.source_config(ref=ref)]} - generate_element(project, "target.bst", element) - - # Fetch, build, checkout - result = cli.run(project=project, args=["source", "fetch", "target.bst"]) - assert result.exit_code == 0 - result = cli.run(project=project, args=["build", "target.bst"]) - assert result.exit_code == 0 - result = cli.run(project=project, args=["artifact", "checkout", "target.bst", "--directory", checkoutdir]) - assert result.exit_code == 0 - - # Assert we checked out the file as it was commited - with open(os.path.join(checkoutdir, "test")) as f: - text = f.read() - - assert text == "test\n" diff --git a/tests/sources/bzr/basic/test b/tests/sources/bzr/basic/test deleted file mode 100644 index 9daeafb98..000000000 --- a/tests/sources/bzr/basic/test +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/tests/sources/bzr/project.conf b/tests/sources/bzr/project.conf deleted file mode 100644 index 08a9d60db..000000000 --- a/tests/sources/bzr/project.conf +++ /dev/null @@ -1,3 +0,0 @@ -# Basic Project -name: foo -min-version: 2.0 diff --git a/tests/testutils/repo/bzr.py b/tests/testutils/repo/bzr.py deleted file mode 100644 index b6983416e..000000000 --- a/tests/testutils/repo/bzr.py +++ /dev/null @@ -1,47 +0,0 @@ -import os -import subprocess -import pytest - -from buildstream.testing import Repo -from buildstream.testing._utils.site import BZR, BZR_ENV, HAVE_BZR - - -class Bzr(Repo): - def __init__(self, directory, subdir): - if not HAVE_BZR: - pytest.skip("bzr is not available") - super().__init__(directory, subdir) - self.bzr = BZR - - self.env = os.environ.copy() - self.env.update(BZR_ENV) - - def create(self, directory): - # Work around race condition in bzr's creation of ~/.bazaar in - # ensure_config_dir_exists() when running tests in parallel. - bazaar_config_dir = os.path.expanduser("~/.bazaar") - os.makedirs(bazaar_config_dir, exist_ok=True) - - branch_dir = os.path.join(self.repo, "trunk") - - subprocess.call([self.bzr, "init-repo", self.repo], env=self.env) - subprocess.call([self.bzr, "init", branch_dir], env=self.env) - self.copy_directory(directory, branch_dir) - subprocess.call([self.bzr, "add", "."], env=self.env, cwd=branch_dir) - subprocess.call([self.bzr, "commit", '--message="Initial commit"'], env=self.env, cwd=branch_dir) - - return self.latest_commit() - - def source_config(self, ref=None): - config = {"kind": "bzr", "url": "file://" + self.repo, "track": "trunk"} - if ref is not None: - config["ref"] = ref - - return config - - def latest_commit(self): - return subprocess.check_output( - [self.bzr, "version-info", "--custom", "--template={revno}", os.path.join(self.repo, "trunk")], - env=self.env, - universal_newlines=True, - ).strip() |