summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/toolchain/gcc_link_wrapper.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/libwebrtc/build/toolchain/gcc_link_wrapper.py
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/build/toolchain/gcc_link_wrapper.py')
-rwxr-xr-xthird_party/libwebrtc/build/toolchain/gcc_link_wrapper.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/third_party/libwebrtc/build/toolchain/gcc_link_wrapper.py b/third_party/libwebrtc/build/toolchain/gcc_link_wrapper.py
new file mode 100755
index 0000000000..b70de8b31c
--- /dev/null
+++ b/third_party/libwebrtc/build/toolchain/gcc_link_wrapper.py
@@ -0,0 +1,94 @@
+#!/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 os
+import subprocess
+import sys
+
+import wrapper_utils
+
+
+# When running on a Windows host and using a toolchain whose tools are
+# actually wrapper scripts (i.e. .bat files on Windows) rather than binary
+# executables, the "command" to run has to be prefixed with this magic.
+# The GN toolchain definitions take care of that for when GN/Ninja is
+# running the tool directly. When that command is passed in to this
+# script, it appears as a unitary string but needs to be split up so that
+# just 'cmd' is the actual command given to Python's subprocess module.
+BAT_PREFIX = 'cmd /c call '
+
+def CommandToRun(command):
+ if command[0].startswith(BAT_PREFIX):
+ command = command[0].split(None, 3) + command[1:]
+ return command
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--strip',
+ help='The strip binary to run',
+ metavar='PATH')
+ parser.add_argument('--unstripped-file',
+ help='Executable file produced by linking command',
+ metavar='FILE')
+ parser.add_argument('--map-file',
+ help=('Use --Wl,-Map to generate a map file. Will be '
+ 'gzipped if extension ends with .gz'),
+ metavar='FILE')
+ parser.add_argument('--dwp', help=('The dwp binary to run'), 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()
+
+ # Work-around for gold being slow-by-default. http://crbug.com/632230
+ fast_env = dict(os.environ)
+ fast_env['LC_ALL'] = 'C'
+ result = wrapper_utils.RunLinkWithOptionalMapFile(args.command, env=fast_env,
+ map_file=args.map_file)
+ if result != 0:
+ return result
+
+ # If dwp is set, then package debug info for this exe.
+ dwp_proc = None
+ if args.dwp:
+ exe_file = args.output
+ if args.unstripped_file:
+ exe_file = args.unstripped_file
+ # Suppress output here because it doesn't seem to be useful. The most
+ # common error is a segfault, which will happen if files are missing.
+ with open(os.devnull, "w") as devnull:
+ dwp_proc = subprocess.Popen(wrapper_utils.CommandToRun(
+ [args.dwp, '-e', exe_file, '-o', exe_file + '.dwp']),
+ stdout=devnull,
+ stderr=subprocess.STDOUT)
+
+ # Finally, strip the linked executable (if desired).
+ if args.strip:
+ result = subprocess.call(
+ CommandToRun([args.strip, '-o', args.output, args.unstripped_file]))
+
+ if dwp_proc:
+ dwp_result = dwp_proc.wait()
+ if dwp_result != 0:
+ sys.stderr.write('dwp failed with error code {}\n'.format(dwp_result))
+ return dwp_result
+
+ return result
+
+
+if __name__ == "__main__":
+ sys.exit(main())