diff options
author | mcgrathr <mcgrathr@chromium.org> | 2015-10-28 17:24:33 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-29 00:25:08 +0000 |
commit | 0b367cc8cf4b27037e5c709adf37271c0d90d392 (patch) | |
tree | 4454f1df96d7f97916b372ecd5a0d8f0c0ab5c13 /build/toolchain/gcc_ar_wrapper.py | |
parent | 98cf8ac9d72ad4505f326983a71a4c803047d8fe (diff) | |
download | chromium_src-0b367cc8cf4b27037e5c709adf37271c0d90d392.zip chromium_src-0b367cc8cf4b27037e5c709adf37271c0d90d392.tar.gz chromium_src-0b367cc8cf4b27037e5c709adf37271c0d90d392.tar.bz2 |
GN: Avoid nontrivial shell commands in gcc_toolchain tools
The gcc_toolchain template is used for NaCl toolchains on every
host OS, as well as for the native toolchains on a POSIXy OS.
When the host is not POSIXy, the toolchain commands cannot use
nontrivial sh syntax or other POSIX utilities (such as 'cut').
The "ar" and "solink" tools do more than a simple command and
used POSIX sh syntax to do their work. To make these tools
portable, make them use Python scripts instead of those complex
shell command lines.
BUG= 512869
R=dpranke@chromium.org
Review URL: https://codereview.chromium.org/1413073005
Cr-Commit-Position: refs/heads/master@{#356699}
Diffstat (limited to 'build/toolchain/gcc_ar_wrapper.py')
-rwxr-xr-x | build/toolchain/gcc_ar_wrapper.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/build/toolchain/gcc_ar_wrapper.py b/build/toolchain/gcc_ar_wrapper.py new file mode 100755 index 0000000..d514910 --- /dev/null +++ b/build/toolchain/gcc_ar_wrapper.py @@ -0,0 +1,56 @@ +#!/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('--plugin', + help='Load plugin') + parser.add_argument('operation', + help='Operation on the archive') + 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 as e: + if e.errno != os.errno.ENOENT: + raise + + # Now just run the ar command. + return subprocess.call(command) + + +if __name__ == "__main__": + sys.exit(main()) |