OLD | NEW |
(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()) |
OLD | NEW |