Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
gn_run_binary Namespace Reference

Functions

 run_command (command)
 
 _decode (bytes)
 
 main (argv)
 

Detailed Description

Helper script for GN to run an arbitrary binary. See compiled_action.gni.

Run with:
  python3 gn_run_binary.py <invoker> <binary_name> [args ...]

Where <invoker> is either "compiled_action" or "exec_script". If it is
"compiled_action" the script has a non-zero exit code on a failure. If it is
"exec_script" the script has no output on success and produces output otherwise,
but always has an exit code of 0.

Function Documentation

◆ _decode()

gn_run_binary._decode (   bytes)
protected

Definition at line 34 of file gn_run_binary.py.

34def _decode(bytes):
35 return bytes.decode("utf-8")
36
37

◆ main()

gn_run_binary.main (   argv)

Definition at line 38 of file gn_run_binary.py.

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
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1

◆ run_command()

gn_run_binary.run_command (   command)

Definition at line 22 of file gn_run_binary.py.

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