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

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: pedantically correct os.remove error handling 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
« no previous file with comments | « no previous file | build/toolchain/gcc_solink_wrapper.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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('--plugin',
31 help='Load plugin')
32 parser.add_argument('operation',
33 help='Operation on the archive')
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 as e:
48 if e.errno != os.errno.ENOENT:
49 raise
50
51 # Now just run the ar command.
52 return subprocess.call(command)
53
54
55 if __name__ == "__main__":
56 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/toolchain/gcc_solink_wrapper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698