OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
agrieve
2016/07/27 01:42:27
These actually shouldn't be updated. They are mean
estevenson
2016/07/28 21:56:45
Done.
| |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Runs the 'ar' command after removing its output file first. | 6 """Runs the 'ar' command after removing its output file first. |
7 | 7 |
8 This script is invoked like: | 8 This script is invoked like: |
9 python gcc_ar_wrapper.py --ar=$AR --output=$OUT $OP $INPUTS | 9 python gcc_ar_wrapper.py --ar=$AR --output=$OUT $OP $INPUTS |
10 to do the equivalent of: | 10 to do the equivalent of: |
11 rm -f $OUT && $AR $OP $OUT $INPUTS | 11 rm -f $OUT && $AR $OP $OUT $INPUTS |
12 """ | 12 """ |
13 | 13 |
14 import argparse | 14 import argparse |
15 import os | 15 import os |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 | 18 |
19 | 19 import wrapper_utils |
20 # When running on a Windows host and using a toolchain whose tools are | |
21 # actually wrapper scripts (i.e. .bat files on Windows) rather than binary | |
22 # executables, the "command" to run has to be prefixed with this magic. | |
23 # The GN toolchain definitions take care of that for when GN/Ninja is | |
24 # running the tool directly. When that command is passed in to this | |
25 # script, it appears as a unitary string but needs to be split up so that | |
26 # just 'cmd' is the actual command given to Python's subprocess module. | |
27 BAT_PREFIX = 'cmd /c call ' | |
28 | |
29 def CommandToRun(command): | |
30 if command[0].startswith(BAT_PREFIX): | |
31 command = command[0].split(None, 3) + command[1:] | |
32 return command | |
33 | 20 |
34 | 21 |
35 def main(): | 22 def main(): |
36 parser = argparse.ArgumentParser(description=__doc__) | 23 parser = argparse.ArgumentParser(description=__doc__) |
37 parser.add_argument('--ar', | 24 parser.add_argument('--ar', |
38 required=True, | 25 required=True, |
39 help='The ar binary to run', | 26 help='The ar binary to run', |
40 metavar='PATH') | 27 metavar='PATH') |
41 parser.add_argument('--output', | 28 parser.add_argument('--output', |
42 required=True, | 29 required=True, |
43 help='Output archive file', | 30 help='Output archive file', |
44 metavar='ARCHIVE') | 31 metavar='ARCHIVE') |
45 parser.add_argument('--plugin', | 32 parser.add_argument('--plugin', |
46 help='Load plugin') | 33 help='Load plugin') |
47 parser.add_argument('operation', | 34 parser.add_argument('operation', |
48 help='Operation on the archive') | 35 help='Operation on the archive') |
49 parser.add_argument('inputs', nargs='+', | 36 parser.add_argument('inputs', nargs='+', |
50 help='Input files') | 37 help='Input files') |
38 parser.add_argument('--rspfile', | |
39 help='Response file', | |
agrieve
2016/07/27 01:42:27
nit: response file is already passed as a position
estevenson
2016/07/28 21:56:45
Done.
| |
40 metavar='FILE') | |
41 parser.add_argument('--whitelist', action='store_true', | |
42 help='Indicates that whitelisting should be performed.') | |
agrieve
2016/07/27 01:42:27
It's probably not obvious to most what "whitelisti
estevenson
2016/07/28 21:56:45
Done.
| |
51 args = parser.parse_args() | 43 args = parser.parse_args() |
52 | 44 |
45 if args.whitelist: | |
46 whitelist_file = '%s.whitelist' % args.output | |
agrieve
2016/07/27 01:42:27
nit: For compiler wrapper you pass in the path to
estevenson
2016/07/28 21:56:45
Done.
| |
47 wrapper_utils.CombineWhitelists(args.rspfile, whitelist_file) | |
48 | |
53 command = [args.ar, args.operation] | 49 command = [args.ar, args.operation] |
54 if args.plugin is not None: | 50 if args.plugin is not None: |
51 | |
agrieve
2016/07/27 01:42:27
nit: revert
estevenson
2016/07/28 21:56:45
Done.
| |
55 command += ['--plugin', args.plugin] | 52 command += ['--plugin', args.plugin] |
56 command.append(args.output) | 53 command.append(args.output) |
57 command += args.inputs | 54 command += args.inputs |
58 | 55 |
59 # Remove the output file first. | 56 # Remove the output file first. |
60 try: | 57 try: |
61 os.remove(args.output) | 58 os.remove(args.output) |
62 except OSError as e: | 59 except OSError as e: |
63 if e.errno != os.errno.ENOENT: | 60 if e.errno != os.errno.ENOENT: |
64 raise | 61 raise |
65 | 62 |
66 # Now just run the ar command. | 63 # Now just run the ar command. |
67 return subprocess.call(CommandToRun(command)) | 64 return subprocess.call(wrapper_utils.CommandToRun(command)) |
68 | 65 |
69 | 66 |
70 if __name__ == "__main__": | 67 if __name__ == "__main__": |
71 sys.exit(main()) | 68 sys.exit(main()) |
OLD | NEW |