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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | build/toolchain/gcc_solink_wrapper.py » ('j') | build/toolchain/gcc_solink_wrapper.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/toolchain/gcc_ar_wrapper.py
diff --git a/build/toolchain/gcc_ar_wrapper.py b/build/toolchain/gcc_ar_wrapper.py
new file mode 100755
index 0000000000000000000000000000000000000000..ed5d29f03413ecb9e1ce56ed77df4f36ef1114c3
--- /dev/null
+++ b/build/toolchain/gcc_ar_wrapper.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Runs the 'ar' command after removing its output file first.
+
+This script is invoked like:
+ python gcc_ar_wrapper.py --ar=$AR --output=$OUT $OP $INPUTS
+to do the equivalent of:
+ rm -f $OUT && $AR $OP $OUT $INPUTS
+"""
+
+import argparse
+import os
+import subprocess
+import sys
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--ar',
+ required=True,
+ help='The ar binary to run',
+ metavar='PATH')
+ parser.add_argument('--output',
+ required=True,
+ help='Output archive file',
+ metavar='ARCHIVE')
+ parser.add_argument('operation',
+ help='Operation on the archive')
+ parser.add_argument('--plugin',
+ 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
+ parser.add_argument('inputs', nargs='+',
+ help='Input files')
+ args = parser.parse_args()
+
+ command = [args.ar, args.operation]
+ if args.plugin is not None:
+ command += ['--plugin', args.plugin]
+ command.append(args.output)
+ command += args.inputs
+
+ # Remove the output file first.
+ try:
+ os.remove(args.output)
+ except OSError:
+ 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
+
+ # Now just run the ar command.
+ return subprocess.call(command)
+
+
+if __name__ == "__main__":
+ sys.exit(main())
« 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