Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
|
Dirk Pranke
2015/11/03 23:49:13
nit: probably should remove the shebang line.
Roland McGrath
2015/11/04 00:06:44
I'm following the example of all the .py files I'v
| |
| 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 a linking command and optionally a strip command. | |
| 7 | |
| 8 This script exists to avoid using complex shell commands in | |
| 9 gcc_toolchain.gni's tool("link"), in case the host running the compiler | |
| 10 does not have a POSIX-like shell (e.g. Windows). | |
| 11 """ | |
| 12 | |
| 13 import argparse | |
| 14 import subprocess | |
| 15 import sys | |
| 16 | |
| 17 | |
| 18 def main(): | |
| 19 parser = argparse.ArgumentParser(description=__doc__) | |
| 20 parser.add_argument('--strip', | |
| 21 help='The strip binary to run', | |
| 22 metavar='PATH') | |
| 23 parser.add_argument('--unstripped-file', | |
| 24 required=True, | |
| 25 help='Executable file produced by linking command', | |
| 26 metavar='FILE') | |
| 27 parser.add_argument('--output', | |
| 28 required=True, | |
| 29 help='Final output executable file', | |
| 30 metavar='FILE') | |
| 31 parser.add_argument('command', nargs='+', | |
| 32 help='Linking command') | |
| 33 args = parser.parse_args() | |
| 34 | |
| 35 # First, run the actual link. | |
| 36 result = subprocess.call(args.command) | |
| 37 if result != 0: | |
| 38 return result | |
| 39 | |
| 40 # Finally, strip the linked executable (if desired). | |
| 41 if args.strip: | |
| 42 command = [args.strip, '-o', args.output, args.unstripped_file] | |
| 43 # TODO(mcgrathr): Make the switch unconditional after pnacl-finalize | |
| 44 # is taught to accept it. | |
| 45 if not args.strip.endswith('pnacl-finalize'): | |
| 46 command.insert(1, '--strip-unneeded') | |
| 47 result = subprocess.call(command) | |
| 48 | |
| 49 return result | |
| 50 | |
| 51 | |
| 52 if __name__ == "__main__": | |
| 53 sys.exit(main()) | |
| OLD | NEW |