diff options
author | Daniel Playle <dplayle@bloomberg.net> | 2017-10-31 17:28:03 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-11 17:43:55 +0900 |
commit | 90850f2bdadfb582556f5783c9f47fda46e57bfb (patch) | |
tree | c1855275db5ea4791c8f1f7f00923e5bfe90a46e /buildstream/source.py | |
parent | 5530bab052c25fe2c16f8f2116ca468b6a895174 (diff) | |
download | buildstream-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
Diffstat (limited to 'buildstream/source.py')
-rw-r--r-- | buildstream/source.py | 37 |
1 files changed, 34 insertions, 3 deletions
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 |