Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
build
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
7
Run with:
8
python3 gn_run_binary.py <invoker> <binary_name> [args ...]
9
10
Where <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,
13
but always has an exit code of 0.
14
"""
15
16
import
os
17
import
sys
18
import
subprocess
19
20
21
# Run a command, swallowing the output unless there is an error.
22
def
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
34
def
_decode
(bytes):
35
return
bytes.decode(
"utf-8"
)
36
37
38
def
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
66
if
__name__ ==
'__main__'
:
67
sys.exit(
main
(sys.argv))
print
void print(void *str)
Definition
bridge.cpp:126
gn_run_binary._decode
_decode(bytes)
Definition
gn_run_binary.py:34
gn_run_binary.run_command
run_command(command)
Definition
gn_run_binary.py:22
main
Definition
main.py:1
Generated on Fri Apr 26 2024 06:14:39 for Flutter Engine by
1.9.8