2019-02-27 11:58:00 +00:00
|
|
|
import os
|
2019-02-14 03:25:34 +00:00
|
|
|
import subprocess
|
|
|
|
|
2019-02-18 12:04:59 +00:00
|
|
|
|
2019-02-27 11:58:00 +00:00
|
|
|
def run_subprocess(command, working_dir='.', env=None, expected_returncode=0):
|
2019-02-18 12:04:59 +00:00
|
|
|
"""
|
|
|
|
Helper function to run a shell command and report success/failure
|
|
|
|
depending on the exit status of the shell command.
|
|
|
|
"""
|
2019-02-27 11:58:00 +00:00
|
|
|
if env is not None:
|
|
|
|
env_ = os.environ.copy()
|
|
|
|
env_.update(env)
|
|
|
|
env = env_
|
|
|
|
|
2019-02-18 12:04:59 +00:00
|
|
|
# Note we need to capture stdout/stderr from the subprocess,
|
|
|
|
# then print it, which nose/unittest will then capture and
|
|
|
|
# buffer appropriately
|
2019-02-14 03:25:34 +00:00
|
|
|
result = subprocess.run(
|
|
|
|
command,
|
2019-02-18 12:04:59 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
2019-02-27 11:58:00 +00:00
|
|
|
cwd=working_dir,
|
|
|
|
env=env,
|
2019-02-14 03:25:34 +00:00
|
|
|
)
|
2019-02-26 04:28:37 +00:00
|
|
|
print(working_dir + " > " + " ".join(command))
|
2019-02-14 03:25:34 +00:00
|
|
|
print(result.stdout.decode('utf-8'))
|
|
|
|
assert(result.returncode == expected_returncode)
|
2019-02-14 16:29:49 +00:00
|
|
|
return result.stdout.decode('utf-8')
|
2019-02-27 11:44:21 +00:00
|
|
|
|
|
|
|
|
2019-02-27 11:58:00 +00:00
|
|
|
def make(*args, working_dir='.', env=None, **kwargs):
|
2019-02-27 11:44:21 +00:00
|
|
|
"""
|
|
|
|
Runs a make target in the specified working directory
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
make('clean', 'targetb', SCHEME='bla')
|
|
|
|
"""
|
|
|
|
make_command = 'make'
|
|
|
|
return run_subprocess(
|
|
|
|
[
|
|
|
|
make_command,
|
|
|
|
*args,
|
|
|
|
*['{}={}'.format(k, v) for k, v in kwargs.items()],
|
|
|
|
],
|
|
|
|
working_dir=working_dir,
|
2019-02-27 11:58:00 +00:00
|
|
|
env=env,
|
2019-02-27 11:44:21 +00:00
|
|
|
)
|