diff options
author | Ed Baunton <edbaunton@gmail.com> | 2018-07-26 14:06:52 +0000 |
---|---|---|
committer | Ed Baunton <edbaunton@gmail.com> | 2018-07-26 14:06:52 +0000 |
commit | 9a46c16f97df78232d4232b310ec707b62dab7b5 (patch) | |
tree | 3a47a90912cdf91477c7634f5680c47c72f86137 /buildstream | |
parent | f62b6cb7420c91c2f87b3ebba4dcfcf16b4d6f0a (diff) | |
parent | bd1196efe104991a2a091d1fe4a024dfd690eca0 (diff) | |
download | buildstream-466-optimize-bst-build-initialization-time.tar.gz |
Merge branch 'edbaunton/remote-source' into 'master'466-optimize-bst-build-initialization-time
Add remote source plugin
Closes #163
See merge request BuildStream/buildstream!541
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_versions.py | 2 | ||||
-rw-r--r-- | buildstream/plugins/sources/remote.py | 81 |
2 files changed, 82 insertions, 1 deletions
diff --git a/buildstream/_versions.py b/buildstream/_versions.py index 28f00f8ca..19699e125 100644 --- a/buildstream/_versions.py +++ b/buildstream/_versions.py @@ -23,7 +23,7 @@ # This version is bumped whenever enhancements are made # to the `project.conf` format or the core element format. # -BST_FORMAT_VERSION = 9 +BST_FORMAT_VERSION = 10 # The base BuildStream artifact version diff --git a/buildstream/plugins/sources/remote.py b/buildstream/plugins/sources/remote.py new file mode 100644 index 000000000..ad4cdab8b --- /dev/null +++ b/buildstream/plugins/sources/remote.py @@ -0,0 +1,81 @@ +# +# Copyright Bloomberg Finance LP +# +# 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: +# Ed Baunton <ebaunton1@bloomberg.net> + +""" +remote - stage files from remote urls +===================================== + +**Usage:** + +.. code:: yaml + + # Specify the remote source kind + kind: remote + + # Optionally specify a relative staging directory + # directory: path/to/stage + + # Optionally specify a relative staging filename. + # If not specified, the basename of the url will be used. + # filename: customfilename + + # Specify the url. Using an alias defined in your project + # configuration is encouraged. 'bst track' will update the + # sha256sum in 'ref' to the downloaded file's sha256sum. + url: upstream:foo + + # Specify the ref. It's a sha256sum of the file you download. + ref: 6c9f6f68a131ec6381da82f2bff978083ed7f4f7991d931bfa767b7965ebc94b + +.. note:: + + The ``remote`` plugin is available since :ref:`format version 10 <project_format_version>` + +""" +import os +from buildstream import SourceError, utils +from ._downloadablefilesource import DownloadableFileSource + + +class RemoteSource(DownloadableFileSource): + # pylint: disable=attribute-defined-outside-init + + def configure(self, node): + super().configure(node) + + self.filename = self.node_get_member(node, str, 'filename', os.path.basename(self.url)) + + if os.sep in self.filename: + raise SourceError('{}: filename parameter cannot contain directories'.format(self), + reason="filename-contains-directory") + self.node_validate(node, DownloadableFileSource.COMMON_CONFIG_KEYS + ['filename']) + + def get_unique_key(self): + return super().get_unique_key() + [self.filename] + + def stage(self, directory): + # Same as in local plugin, don't use hardlinks to stage sources, they + # are not write protected in the sandbox. + dest = os.path.join(directory, self.filename) + with self.timed_activity("Staging remote file to {}".format(dest)): + utils.safe_copy(self._get_mirror_file(), dest) + + +def setup(): + return RemoteSource |