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