from buildstream import Element, ElementError, Scope class ScriptShelllessElement(Element): __root_read_only:bool __commands:list BST_FORBID_RDEPENDS = True def configure(self, node): # Get data self.__root_read_only = self.node_get_member(node, bool, 'root_read_only', None) self.__commands = self.node_get_member(node, list, 'commands', None) def preflight(self): pass def get_unique_key(self): return {'version': 6, "root_read_only": self.__root_read_only, "commands": self.__commands} def configure_sandbox(self, sandbox): sandbox.set_environment(self.get_environment()) def stage(self, sandbox): 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="/") 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) def assemble(self, sandbox): for command in self.__commands: self.status("Running command", detail=" ".join(command)) #self.status(sandbox.get_virtual_directory()) exitcode = sandbox.run(command, SandboxFlags.ROOT_READ_ONLY if self.__root_read_only else 0, cwd="/") print("Command: %s Exit: %i" % (repr(" ".join(command)), exitcode)) if exitcode != 0: raise ElementError("Command '{}' failed with exitcode {}".format(" ".join(command), exitcode)) # Return where the result can be collected from return "/" # Plugin entry point def setup(): return ScriptShelllessElement