diff options
author | Jürg Billeter <j@bitron.ch> | 2017-08-17 11:46:39 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2017-08-17 11:46:39 +0200 |
commit | 7de843dd17f79bf6d4c1fb7213a198fea77cc83f (patch) | |
tree | 5992ed0ed1fdcc73394ac6c22c50fb301c3ac966 | |
parent | 52807a865840d776171eaab795e4220bb99bd3e4 (diff) | |
download | buildstream-7de843dd17f79bf6d4c1fb7213a198fea77cc83f.tar.gz |
element.py: Add optional command argument to _shell()
If specified, the command will run in non-interactive mode.
-rw-r--r-- | buildstream/element.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index 09ead8264..ad4831fad 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -1347,8 +1347,10 @@ class Element(Plugin): # scope (Scope): Either BUILD or RUN scopes are valid, or None # directory (str): A directory to an existing sandbox, or None # + # Returns: Exit code + # # If directory is not specified, one will be staged using scope - def _shell(self, scope=None, directory=None): + def _shell(self, scope=None, directory=None, command=None): with self._prepare_sandbox(scope, directory) as sandbox: @@ -1363,11 +1365,16 @@ class Element(Plugin): if os.environ.get(override) is not None: environment[override] = os.environ.get(override) + argv = ['sh'] + flags = SandboxFlags.NETWORK_ENABLED + if command: + argv += ['-c', command] + else: + argv += ['-i'] + flags |= SandboxFlags.INTERACTIVE + # Run shells with network enabled and readonly root. - exitcode = sandbox.run(['sh', '-i'], - SandboxFlags.NETWORK_ENABLED | - SandboxFlags.INTERACTIVE, - env=environment) + return sandbox.run(argv, flags, env=environment) # _stage_sources_at(): # |