xref: /aosp_15_r20/external/angle/build/gn_run_binary.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2014 The Chromium Authors
2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be
3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file.
4*8975f5c5SAndroid Build Coastguard Worker
5*8975f5c5SAndroid Build Coastguard Worker"""Helper script for GN to run an arbitrary binary. See compiled_action.gni.
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard WorkerRun with:
8*8975f5c5SAndroid Build Coastguard Worker  python gn_run_binary.py <binary_name> [args ...]
9*8975f5c5SAndroid Build Coastguard Worker"""
10*8975f5c5SAndroid Build Coastguard Worker
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Workerimport os
13*8975f5c5SAndroid Build Coastguard Workerimport subprocess
14*8975f5c5SAndroid Build Coastguard Workerimport sys
15*8975f5c5SAndroid Build Coastguard Worker
16*8975f5c5SAndroid Build Coastguard Worker# This script is designed to run binaries produced by the current build. We
17*8975f5c5SAndroid Build Coastguard Worker# may prefix it with "./" to avoid picking up system versions that might
18*8975f5c5SAndroid Build Coastguard Worker# also be on the path.
19*8975f5c5SAndroid Build Coastguard Workerpath = sys.argv[1]
20*8975f5c5SAndroid Build Coastguard Workerif not os.path.isabs(path):
21*8975f5c5SAndroid Build Coastguard Worker  path = './' + path
22*8975f5c5SAndroid Build Coastguard Worker
23*8975f5c5SAndroid Build Coastguard Worker# The rest of the arguments are passed directly to the executable.
24*8975f5c5SAndroid Build Coastguard Workerargs = [path] + sys.argv[2:]
25*8975f5c5SAndroid Build Coastguard Worker
26*8975f5c5SAndroid Build Coastguard Workerret = subprocess.call(args)
27*8975f5c5SAndroid Build Coastguard Workerif ret != 0:
28*8975f5c5SAndroid Build Coastguard Worker  if ret <= -100:
29*8975f5c5SAndroid Build Coastguard Worker    # Windows error codes such as 0xC0000005 and 0xC0000409 are much easier to
30*8975f5c5SAndroid Build Coastguard Worker    # recognize and differentiate in hex. In order to print them as unsigned
31*8975f5c5SAndroid Build Coastguard Worker    # hex we need to add 4 Gig to them.
32*8975f5c5SAndroid Build Coastguard Worker    print('%s failed with exit code 0x%08X' % (sys.argv[1], ret + (1 << 32)))
33*8975f5c5SAndroid Build Coastguard Worker  else:
34*8975f5c5SAndroid Build Coastguard Worker    print('%s failed with exit code %d' % (sys.argv[1], ret))
35*8975f5c5SAndroid Build Coastguard Workersys.exit(ret)
36