summaryrefslogtreecommitdiffstats
path: root/build/toolchain/gcc_link_wrapper.py
diff options
context:
space:
mode:
authormcgrathr <mcgrathr@chromium.org>2015-11-09 14:28:36 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-09 22:29:36 +0000
commit46f8e4a291285770abb2357402fe8e662e00df2e (patch)
tree724ec1ecab818ff505f45dbd93b23a426d84df27 /build/toolchain/gcc_link_wrapper.py
parentaa0d38670f55033607bc4d2513f877db516a4b1c (diff)
downloadchromium_src-46f8e4a291285770abb2357402fe8e662e00df2e.zip
chromium_src-46f8e4a291285770abb2357402fe8e662e00df2e.tar.gz
chromium_src-46f8e4a291285770abb2357402fe8e662e00df2e.tar.bz2
GN: Avoid nontrivial shell commands in gcc_toolchain tool("link")
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 sh syntax (not even '&&'). The "link" tool does more than a simple command when 'strip' or 'postlink' variables are set, and used POSIX sh syntax to in these cases. To make this tool portable, make it use a Python script instead of those complex shell command lines. The 'postlink' variable was used only for the pnacl toolchain's "finalize" step and it can just as well use the 'strip' variable for that purpose, so simplify things by eliminating 'postlink' entirely. BUG= 512869 R=dpranke@chromium.org, dschuff@chromium.org Review URL: https://codereview.chromium.org/1432603003 Cr-Commit-Position: refs/heads/master@{#358684}
Diffstat (limited to 'build/toolchain/gcc_link_wrapper.py')
-rwxr-xr-xbuild/toolchain/gcc_link_wrapper.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/build/toolchain/gcc_link_wrapper.py b/build/toolchain/gcc_link_wrapper.py
new file mode 100755
index 0000000..74eb460
--- /dev/null
+++ b/build/toolchain/gcc_link_wrapper.py
@@ -0,0 +1,49 @@
+#!/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 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:
+ result = subprocess.call([args.strip, '--strip-unneeded',
+ '-o', args.output, args.unstripped_file])
+
+ return result
+
+
+if __name__ == "__main__":
+ sys.exit(main())