summaryrefslogtreecommitdiff
path: root/buildstream
diff options
context:
space:
mode:
authorJim MacArthur <jim.macarthur@codethink.co.uk>2018-05-08 16:20:55 +0100
committerJim MacArthur <jim.macarthur@codethink.co.uk>2018-08-01 13:07:33 +0100
commita8c71ba49b03a389f84a69402615b5e88feb77bd (patch)
tree366c8b3b4f571f3581e984941d4e1ce578102b24 /buildstream
parent270325b4f470f1b33258cfc67f109338c52678b8 (diff)
downloadbuildstream-a8c71ba49b03a389f84a69402615b5e88feb77bd.tar.gz
plugins/elements/import.py: Convert to virtual directories
Diffstat (limited to 'buildstream')
-rw-r--r--buildstream/plugins/elements/import.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/buildstream/plugins/elements/import.py b/buildstream/plugins/elements/import.py
index 93594b623..0eca2a902 100644
--- a/buildstream/plugins/elements/import.py
+++ b/buildstream/plugins/elements/import.py
@@ -31,7 +31,6 @@ The empty configuration is as such:
"""
import os
-import shutil
from buildstream import Element, BuildElement, ElementError
@@ -39,6 +38,9 @@ from buildstream import Element, BuildElement, ElementError
class ImportElement(BuildElement):
# pylint: disable=attribute-defined-outside-init
+ # This plugin has been modified to avoid the use of Sandbox.get_directory
+ BST_VIRTUAL_DIRECTORY = True
+
def configure(self, node):
self.source = self.node_subst_member(node, 'source')
self.target = self.node_subst_member(node, 'target')
@@ -68,27 +70,22 @@ class ImportElement(BuildElement):
# Do not mount workspaces as the files are copied from outside the sandbox
self._stage_sources_in_sandbox(sandbox, 'input', mount_workspaces=False)
- rootdir = sandbox.get_directory()
- inputdir = os.path.join(rootdir, 'input')
- outputdir = os.path.join(rootdir, 'output')
+ rootdir = sandbox.get_virtual_directory()
+ inputdir = rootdir.descend(['input'])
+ outputdir = rootdir.descend(['output'], create=True)
# The directory to grab
- inputdir = os.path.join(inputdir, self.source.lstrip(os.sep))
- inputdir = inputdir.rstrip(os.sep)
+ inputdir = inputdir.descend(self.source.strip(os.sep).split(os.sep))
# The output target directory
- outputdir = os.path.join(outputdir, self.target.lstrip(os.sep))
- outputdir = outputdir.rstrip(os.sep)
-
- # Ensure target directory parent
- os.makedirs(os.path.dirname(outputdir), exist_ok=True)
+ outputdir = outputdir.descend(self.target.strip(os.sep).split(os.sep), create=True)
- if not os.path.exists(inputdir):
+ if inputdir.is_empty():
raise ElementError("{}: No files were found inside directory '{}'"
.format(self, self.source))
# Move it over
- shutil.move(inputdir, outputdir)
+ outputdir.import_files(inputdir)
# And we're done
return '/output'