nathanwilliams-ct commented on code in PR #2147:
URL: https://github.com/apache/buildstream/pull/2147#discussion_r4015026503
##########
src/buildstream/_stream.py:
##########
@@ -235,6 +240,65 @@ def query_cache(self, elements, *,
sources_of_cached_elements=False, only_source
task.add_current_progress()
+ # shell_with()
+ #
+ # Run a shell with other targets.
+ #
+ # Automatically creates a temporary target based on 'target' with
'other_targets' as runtime or build dependencies.
+ #
+ # Note: Method will build the temporary target, before entering into it's
shell.
+ #
+ # Args:
+ # target (str): The name of the element to run the shell for
+ # other_targets: (Iterable[str]): The name of the other elements to run
the shell with.
+ # scope: _Scope: Either BUILD or RUN
+ # *args, **kwargs: Passed to shell() untouched.
+ #
+ # Returns:
+ # (int): The exit code of the launched shell
+ #
+ def shell_with(self, target: str, other_targets: Iterable[str], scope:
_Scope, *args, **kwargs):
+
+ assert self._project, "Must have a project"
+ assert self._project.loader, "Project must have loader"
+
+ _, target_name, target_loader =
self._project.loader._parse_name(target, MappingNode.from_dict({}))
+
+ target_path = os.path.join(target_loader._basedir, target_name)
+ target_node: CommentedMap = _yaml.roundtrip_load(target_path)
+
+ if scope == _Scope.RUN:
+ r_depends = target_node.get("runtime-depends", [])
+
+ for other_target in other_targets:
+ r_depends.append(other_target)
+
+ target_node["runtime-depends"] = r_depends
+ elif scope == _Scope.BUILD:
+ r_depends = target_node.get("build-depends", [])
+
+ for other_target in other_targets:
+ r_depends.append(other_target)
+
+ target_node["build-depends"] = r_depends
+ else:
+ raise StreamError(
+ "Only BUILD and RUN scopes are supported",
+ detail="Use the --build and --use-buildtree options to shell
into a build tree",
+ reason="only-build-run-supported",
+ )
+
+ with tempfile.NamedTemporaryFile(
+ delete_on_close=False,
prefix=f"{target_name.replace('/','_')}_temp", suffix=".bst"
+ ) as temp_target_file:
+ _yaml.roundtrip_dump(target_node, temp_target_file)
+ temp_target_file.close() # delete_on_close is false so this
doesn't remove the file, but delete is True(default) so we delete the file when
we leave the context manager.
+
+ target_loader._set_fullpath_overrides(target_name,
temp_target_file.name)
+
+ self.build([target])
Review Comment:
Changing the dependencies messes with the cache key so a build is necessary
still.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]