1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
# Copyright (C) 2018 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:
# Phillip Smyth <phillip.smyth@codethink.co.uk>
"""A source implementation for using quilt to add patches.
**Usage:**
.. code:: yaml
# Specify the quilt source kind
kind: quilt
# Specify the directory containing the series file
path: patches
# The directory containing the series file should also contain all patches.
# This would ideally be located within the `files` directory.
"""
import os
from buildstream import Source, SourceError, Consistency
from buildstream import utils
class QuiltSource(Source):
def configure(self, node):
self.path = self.node_get_member(node, str, "path", "")
def preflight(self):
# Check if patch is installed, get the binary at the same time
self.host_quilt = utils.get_host_tool("quilt")
def get_unique_key(self):
return [self.path]
def get_consistency(self):
return Consistency.CACHED
def get_ref(self):
return None # pragma: nocover
def set_ref(self, ref, node):
pass # pragma: nocover
def fetch(self):
pass # pragma: nocover
def stage(self, directory):
patch_dir = os.path.join(directory, self.path)
with self.timed_activity("quilt: Applying patches: {}".format(patch_dir)):
if not os.path.isdir(patch_dir):
raise SourceError("Directory does not exist '{}'".format(patch_dir),
reason="no-dir-found")
# Call quilt command
self.command = [self.host_quilt, "push", "-a"]
self.call(self.command, cwd=directory, fail="Error occurred while calling {}".format(self.command), env={"QUILT_PATCHES": self.path})
# Plugin entry point
def setup():
return QuiltSource
|