Skip to content
Snippets Groups Projects
Commit 79c6080e authored by richardmaw-codethink's avatar richardmaw-codethink
Browse files

scriptelement: Split stage into granular methods

This makes the __layout check per-method
and makes ScriptElement.stage call the methods in turn.

stage_dependency_artifacts falls-back to the default implementation
for everything except Scope.BUILD since Element.stage was only called
for Scope.BUILD, so layout handling shouldn't be consulted for other scopes
for compatibility with existing behaviour.
parent f98e00f0
No related branches found
No related tags found
Loading
......@@ -215,17 +215,31 @@ class ScriptElement(Element):
def stage(self, sandbox):
# Stage the elements, and run integration commands where appropriate.
if not self.__layout:
# if no layout set, stage all dependencies into /
for build_dep in self.dependencies(Scope.BUILD, recurse=False):
with self.timed_activity("Staging {} at /"
.format(build_dep.name), silent_nested=True):
build_dep.stage_dependency_artifacts(sandbox, Scope.RUN, path="/")
self.stage_dependency_artifacts(sandbox, Scope.BUILD)
self.integrate_dependencies(sandbox, Scope.BUILD)
self.post_integration_staging(sandbox)
def stage_dependency_artifacts(self, sandbox, scope, *, path=None,
include=None, exclude=None, orphans=True, visited=None):
if scope is not Scope.BUILD:
return super().stage_dependency_artifacts(sandbox, scope, path=path,
include=include,
exclude=exclude,
orphans=orphans,
visited=visited)
if path is None:
path = "/"
if visited is None:
visited = {}
if not self.__layout:
# if no layout set, stage all dependencies into path
for build_dep in self.dependencies(Scope.BUILD, recurse=False):
with self.timed_activity("Integrating {}".format(build_dep.name), silent_nested=True):
for dep in build_dep.dependencies(Scope.RUN):
dep.integrate(sandbox)
with self.timed_activity("Staging {} at {}"
.format(build_dep.name, path), silent_nested=True):
build_dep.stage_dependency_artifacts(sandbox, Scope.RUN, path=path, visited=visited)
else:
# If layout, follow its rules.
for item in self.__layout:
......@@ -236,17 +250,32 @@ class ScriptElement(Element):
element = self.search(Scope.BUILD, item['element'])
if item['destination'] == '/':
with self.timed_activity("Staging {} at /".format(element.name),
with self.timed_activity("Staging {} at {}".format(element.name, path),
silent_nested=True):
element.stage_dependency_artifacts(sandbox, Scope.RUN)
element.stage_dependency_artifacts(sandbox, Scope.RUN, path=path, visited=visited)
else:
subpath = os.path.join(path, item['destination'])
with self.timed_activity("Staging {} at {}"
.format(element.name, item['destination']),
.format(element.name, subpath),
silent_nested=True):
virtual_dstdir = sandbox.get_virtual_directory()
virtual_dstdir.descend(item['destination'].lstrip(os.sep).split(os.sep), create=True)
element.stage_dependency_artifacts(sandbox, Scope.RUN, path=item['destination'])
virtual_dstdir.descend(subpath.lstrip(os.sep).split(os.sep), create=True)
element.stage_dependency_artifacts(sandbox, Scope.RUN, path=subpath, visited=visited)
def integrate_dependencies(self, sandbox, scope, *, visited=None):
if scope is not Scope.BUILD:
return super().integrate_dependencies(sandbox, scope, visited=visited)
if visited is None:
visited = {}
if not self.__layout:
for build_dep in self.dependencies(Scope.BUILD, recurse=False):
with self.timed_activity("Integrating {}".format(build_dep.name), silent_nested=True):
for dep in build_dep.dependencies(Scope.RUN, visited=visited):
dep.integrate(sandbox)
else:
# If layout, follow its rules.
for item in self.__layout:
# Skip layout members which dont stage an element
......@@ -259,9 +288,10 @@ class ScriptElement(Element):
if item['destination'] == '/':
with self.timed_activity("Integrating {}".format(element.name),
silent_nested=True):
for dep in element.dependencies(Scope.RUN):
for dep in element.dependencies(Scope.RUN, visited=visited):
dep.integrate(sandbox)
def post_integration_staging(self, sandbox):
install_root_path_components = self.__install_root.lstrip(os.sep).split(os.sep)
sandbox.get_virtual_directory().descend(install_root_path_components, create=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment