summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Playle <dplayle@bloomberg.net>2017-10-31 17:28:03 +0000
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-11-11 17:43:55 +0900
commit90850f2bdadfb582556f5783c9f47fda46e57bfb (patch)
treec1855275db5ea4791c8f1f7f00923e5bfe90a46e
parent5530bab052c25fe2c16f8f2116ca468b6a895174 (diff)
downloadbuildstream-90850f2bdadfb582556f5783c9f47fda46e57bfb.tar.gz
Change origin to point at source repo
This changes workspaces created with the git source element so that the origin remote points to the source repository of the build element as opposed to the internal repository in the bst cache. This introduces an addition of the init_workspace method in the source API. This method, which defaults to calling stage, is for the setup of the workspace after the creation of the workspace directory. This is a part of issue #53
-rw-r--r--buildstream/_pipeline.py2
-rw-r--r--buildstream/plugins/sources/git.py27
-rw-r--r--buildstream/source.py37
3 files changed, 60 insertions, 6 deletions
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py
index 9820880f6..9860d290c 100644
--- a/buildstream/_pipeline.py
+++ b/buildstream/_pipeline.py
@@ -553,7 +553,7 @@ class Pipeline():
"Use `--track` to track and " +
"fetch the latest version of the " +
"source.")
- source._stage(directory)
+ source._init_workspace(directory)
self.project._set_workspace(target, source_index, workdir)
diff --git a/buildstream/plugins/sources/git.py b/buildstream/plugins/sources/git.py
index baf159d82..d7a87c86c 100644
--- a/buildstream/plugins/sources/git.py
+++ b/buildstream/plugins/sources/git.py
@@ -142,8 +142,22 @@ class GitMirror():
# We need to pass '--no-hardlinks' because there's nothing to
# stop the build from overwriting the files in the .git directory
# inside the sandbox.
- self.source.call([self.source.host_git, 'clone', '--no-hardlinks', self.mirror, fullpath],
- fail="Failed to checkout git mirror {} in directory: {}".format(self.mirror, fullpath))
+ self.source.call([self.source.host_git, 'clone', '--no-checkout', '--no-hardlinks', self.mirror, fullpath],
+ fail="Failed to create git mirror {} in directory: {}".format(self.mirror, fullpath))
+
+ self.source.call([self.source.host_git, 'checkout', '--force', self.ref],
+ fail="Failed to checkout git ref {}".format(self.ref),
+ cwd=fullpath)
+
+ def init_workspace(self, directory):
+ fullpath = os.path.join(directory, self.path)
+
+ self.source.call([self.source.host_git, 'clone', '--no-checkout', self.mirror, fullpath],
+ fail="Failed to clone git mirror {} in directory: {}".format(self.mirror, fullpath))
+
+ self.source.call([self.source.host_git, 'remote', 'set-url', 'origin', self.url],
+ fail='Failed to add remote origin "{}"'.format(self.url),
+ cwd=fullpath)
self.source.call([self.source.host_git, 'checkout', '--force', self.ref],
fail="Failed to checkout git ref {}".format(self.ref),
@@ -295,6 +309,15 @@ class GitSource(Source):
self.refresh_submodules()
self.fetch_submodules()
+ def init_workspace(self, directory):
+ # XXX: may wish to refactor this as some code dupe with stage()
+ self.refresh_submodules()
+
+ with self.timed_activity('Setting up workspace "{}"'.format(directory), silent_nested=True):
+ self.mirror.init_workspace(directory)
+ for mirror in self.submodules:
+ mirror.init_workspace(directory)
+
def stage(self, directory):
# Need to refresh submodule list here again, because
diff --git a/buildstream/source.py b/buildstream/source.py
index ed3fe92b3..5c97a5743 100644
--- a/buildstream/source.py
+++ b/buildstream/source.py
@@ -229,6 +229,26 @@ class Source(Plugin):
"""
raise ImplError("Source plugin '%s' does not implement stage()" % self.get_kind())
+ def init_workspace(self, directory):
+ """Initialises a new workspace
+
+ Args:
+ directory (str): Path of the workspace to init
+
+ Raises:
+ :class:`.SourceError`
+
+ Default implementation is to call
+ :func:`~buildstream.source.Source.stage`.
+
+ Implementors overriding this method should assume that *directory*
+ already exists.
+
+ Implementors should raise :class:`.SourceError` when encountering
+ some system error.
+ """
+ self.stage(directory)
+
#############################################################
# Private Methods used in BuildStream #
#############################################################
@@ -276,20 +296,31 @@ class Source(Plugin):
def _fetch(self):
self.fetch()
+ # Ensures a fully constructed path and returns it
+ def _ensure_directory(self, directory):
+ if self.__directory is not None:
+ directory = os.path.join(directory, self.__directory.lstrip(os.sep))
+ os.makedirs(directory, exist_ok=True)
+ return directory
+
# Wrapper for stage() api which gives the source
# plugin a fully constructed path considering the
# 'directory' option
#
def _stage(self, directory):
- if self.__directory is not None:
- directory = os.path.join(directory, self.__directory.lstrip(os.sep))
- os.makedirs(directory, exist_ok=True)
+ directory = self._ensure_directory(directory)
if self._has_workspace():
self._stage_workspace(directory)
else:
self.stage(directory)
+ # Wrapper for init_workspace()
+ def _init_workspace(self, directory):
+ directory = self._ensure_directory(directory)
+
+ self.init_workspace(directory)
+
# Wrapper for get_unique_key() api
#
# This adds any core attributes to the key and