Index: build/toolchain/gcc_link_wrapper.py |
diff --git a/build/toolchain/gcc_link_wrapper.py b/build/toolchain/gcc_link_wrapper.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..497d7952796e84d45c639052ad3a2438eaabfde6 |
--- /dev/null |
+++ b/build/toolchain/gcc_link_wrapper.py |
@@ -0,0 +1,53 @@ |
+#!/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
|
+# 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 a linking command and optionally a strip command. |
+ |
+This script exists to avoid using complex shell commands in |
+gcc_toolchain.gni's tool("link"), in case the host running the compiler |
+does not have a POSIX-like shell (e.g. Windows). |
+""" |
+ |
+import argparse |
+import subprocess |
+import sys |
+ |
+ |
+def main(): |
+ parser = argparse.ArgumentParser(description=__doc__) |
+ parser.add_argument('--strip', |
+ help='The strip binary to run', |
+ metavar='PATH') |
+ parser.add_argument('--unstripped-file', |
+ required=True, |
+ help='Executable file produced by linking command', |
+ metavar='FILE') |
+ parser.add_argument('--output', |
+ required=True, |
+ help='Final output executable file', |
+ metavar='FILE') |
+ parser.add_argument('command', nargs='+', |
+ help='Linking command') |
+ args = parser.parse_args() |
+ |
+ # First, run the actual link. |
+ result = subprocess.call(args.command) |
+ if result != 0: |
+ return result |
+ |
+ # Finally, strip the linked executable (if desired). |
+ if args.strip: |
+ command = [args.strip, '-o', args.output, args.unstripped_file] |
+ # TODO(mcgrathr): Make the switch unconditional after pnacl-finalize |
+ # is taught to accept it. |
+ if not args.strip.endswith('pnacl-finalize'): |
+ command.insert(1, '--strip-unneeded') |
+ result = subprocess.call(command) |
+ |
+ return result |
+ |
+ |
+if __name__ == "__main__": |
+ sys.exit(main()) |