Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: build/toolchain/gcc_ar_wrapper.py

Issue 1413073005: GN: Avoid nontrivial shell commands in gcc_toolchain tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2015 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
6 """Runs the 'ar' command after removing its output file first.
7
8 This script is invoked like:
9 python gcc_ar_wrapper.py --ar=$AR --output=$OUT $OP $INPUTS
10 to do the equivalent of:
11 rm -f $OUT && $AR $OP $OUT $INPUTS
12 """
13
14 import argparse
15 import os
16 import subprocess
17 import sys
18
19
20 def main():
21 parser = argparse.ArgumentParser(description=__doc__)
22 parser.add_argument('--ar',
23 required=True,
24 help='The ar binary to run',
25 metavar='PATH')
26 parser.add_argument('--output',
27 required=True,
28 help='Output archive file',
29 metavar='ARCHIVE')
30 parser.add_argument('operation',
31 help='Operation on the archive')
32 parser.add_argument('--plugin',
33 help='Load plugin')
Dirk Pranke 2015/10/28 22:13:03 nit: I'd reorder --plugin before operation.
Roland McGrath 2015/10/28 22:25:16 Done. I originally wrote them in the order they a
34 parser.add_argument('inputs', nargs='+',
35 help='Input files')
36 args = parser.parse_args()
37
38 command = [args.ar, args.operation]
39 if args.plugin is not None:
40 command += ['--plugin', args.plugin]
41 command.append(args.output)
42 command += args.inputs
43
44 # Remove the output file first.
45 try:
46 os.remove(args.output)
47 except OSError:
48 pass
Dirk Pranke 2015/10/28 22:13:03 I suspect you shouldn't be ignoring the error here
Roland McGrath 2015/10/28 22:25:15 Ignoring the error is the equivalent of 'rm -f', w
49
50 # Now just run the ar command.
51 return subprocess.call(command)
52
53
54 if __name__ == "__main__":
55 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/toolchain/gcc_solink_wrapper.py » ('j') | build/toolchain/gcc_solink_wrapper.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698