5"""Helper script for GN to run an arbitrary binary. See compiled_action.gni.
8 python3 gn_run_binary.py <invoker> <binary_name> [args ...]
10Where <invoker> is either
"compiled_action" or "exec_script". If it
is
11"compiled_action" the script has a non-zero exit code on a failure. If it
is
12"exec_script" the script has no output on success
and produces output otherwise,
13but always has an exit code of 0.
21# Run a command, swallowing the output unless there is an error.
22def run_command(command):
24 subprocess.check_output(command, stderr=subprocess.STDOUT)
26 except subprocess.CalledProcessError
as e:
27 return (
"Command failed: " +
' '.
join(command) +
"\n" +
"output: " +
30 return (
"Command failed: " +
' '.
join(command) +
"\n" +
"output: " +
35 return bytes.decode(
"utf-8")
40 if argv[1] ==
"compiled_action":
42 elif argv[1] !=
"exec_script":
43 print(
"The first argument should be either "
44 "'compiled_action' or 'exec_script")
50 path = os.path.abspath(argv[2])
52 if not os.path.isfile(path):
53 print(
"Binary not found: " + path)
57 args = [path] + argv[3:]
66if __name__ ==
'__main__':
67 sys.exit(
main(sys.argv))
def print(*args, **kwargs)
static SkString join(const CommandLineFlags::StringArray &)