Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
gn_run_binary.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright 2014 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Helper script for GN to run an arbitrary binary. See compiled_action.gni.
6
7Run with:
8 python3 gn_run_binary.py <invoker> <binary_name> [args ...]
9
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.
14"""
15
16import os
17import sys
18import subprocess
19
20
21# Run a command, swallowing the output unless there is an error.
22def run_command(command):
23 try:
24 subprocess.check_output(command, stderr=subprocess.STDOUT)
25 return 0
26 except subprocess.CalledProcessError as e:
27 return ("Command failed: " + ' '.join(command) + "\n" + "output: " +
28 _decode(e.output))
29 except OSError as e:
30 return ("Command failed: " + ' '.join(command) + "\n" + "output: " +
31 _decode(e.strerror))
32
33
34def _decode(bytes):
35 return bytes.decode("utf-8")
36
37
38def main(argv):
39 error_exit = 0
40 if argv[1] == "compiled_action":
41 error_exit = 1
42 elif argv[1] != "exec_script":
43 print("The first argument should be either "
44 "'compiled_action' or 'exec_script")
45 return 1
46
47 # Unless the path is absolute, this script is designed to run binaries
48 # produced by the current build, which is the current working directory when
49 # this script is run.
50 path = os.path.abspath(argv[2])
51
52 if not os.path.isfile(path):
53 print("Binary not found: " + path)
54 return error_exit
55
56 # The rest of the arguments are passed directly to the executable.
57 args = [path] + argv[3:]
58
59 result = run_command(args)
60 if result != 0:
61 print(result)
62 return error_exit
63 return 0
64
65
66if __name__ == '__main__':
67 sys.exit(main(sys.argv))
void print(void *str)
Definition bridge.cpp:126
run_command(command)
Definition main.py:1