From ee52bdf4327578c561ca7b0a1729e12462dcbc16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Tue, 15 Aug 2017 14:55:57 +0200 Subject: import.py: Implement generate_script() for source bundles Fixes #59 --- buildstream/plugins/elements/import.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'buildstream/plugins') diff --git a/buildstream/plugins/elements/import.py b/buildstream/plugins/elements/import.py index a6178a179..3ab7f7833 100644 --- a/buildstream/plugins/elements/import.py +++ b/buildstream/plugins/elements/import.py @@ -91,6 +91,32 @@ class ImportElement(BuildElement): # And we're done return '/output' + def generate_script(self): + build_root = self.get_variable('build-root') + install_root = self.get_variable('install-root') + commands = [] + + # The directory to grab + inputdir = os.path.join(build_root, self.normal_name, self.source.lstrip(os.sep)) + inputdir = inputdir.rstrip(os.sep) + + # The output target directory + outputdir = os.path.join(install_root, self.target.lstrip(os.sep)) + outputdir = outputdir.rstrip(os.sep) + + # Ensure target directory parent exists but target directory doesn't + commands.append("mkdir -p {}".format(os.path.dirname(outputdir))) + commands.append("[ ! -e {} ] || rmdir {}".format(outputdir, outputdir)) + + # Move it over + commands.append("mv {} {}".format(inputdir, outputdir)) + + script = "" + for cmd in commands: + script += "(set -ex; {}\n) || exit 1\n".format(cmd) + + return script + # Plugin entry point def setup(): -- cgit v1.2.1