mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-22 16:37:40 +08:00
[libcxx] Update gen_link_script.py to support different input and output
This enables the use of this script from other build systems like GN which don't support post-build actions as well as for static archives. Differential Revision: https://reviews.llvm.org/D60309 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@358915 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -230,7 +230,8 @@ if (LIBCXX_ENABLE_SHARED)
|
|||||||
COMMAND
|
COMMAND
|
||||||
${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script.py
|
${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script.py
|
||||||
ARGS
|
ARGS
|
||||||
"$<TARGET_LINKER_FILE:cxx_shared>"
|
--input "$<TARGET_SONAME_FILE:cxx_shared>"
|
||||||
|
--output "$<TARGET_LINKER_FILE:cxx_shared>"
|
||||||
${LIBCXX_INTERFACE_LIBRARY_NAMES}
|
${LIBCXX_INTERFACE_LIBRARY_NAMES}
|
||||||
WORKING_DIRECTORY ${LIBCXX_BUILD_DIR}
|
WORKING_DIRECTORY ${LIBCXX_BUILD_DIR}
|
||||||
)
|
)
|
||||||
|
@@ -7,77 +7,48 @@
|
|||||||
#
|
#
|
||||||
#===----------------------------------------------------------------------===##
|
#===----------------------------------------------------------------------===##
|
||||||
|
|
||||||
|
"""
|
||||||
|
Generate a linker script that links libc++ to the proper ABI library.
|
||||||
|
An example script for c++abi would look like "INPUT(libc++.so.1 -lc++abi)".
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def print_and_exit(msg):
|
|
||||||
sys.stderr.write(msg + '\n')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def usage_and_exit():
|
|
||||||
print_and_exit("Usage: ./gen_link_script.py [--help] [--dryrun] <path/to/libcxx.so> <public_libs>...")
|
|
||||||
|
|
||||||
def help_and_exit():
|
|
||||||
help_msg = \
|
|
||||||
"""Usage
|
|
||||||
|
|
||||||
gen_link_script.py [--help] [--dryrun] <path/to/libcxx.so> <public_libs>...
|
|
||||||
|
|
||||||
Generate a linker script that links libc++ to the proper ABI library.
|
|
||||||
The script replaces the specified libc++ symlink.
|
|
||||||
An example script for c++abi would look like "INPUT(libc++.so.1 -lc++abi)".
|
|
||||||
|
|
||||||
Arguments
|
|
||||||
<path/to/libcxx.so> - The top level symlink to the versioned libc++ shared
|
|
||||||
library. This file is replaced with a linker script.
|
|
||||||
<public_libs> - List of library names to include in linker script.
|
|
||||||
|
|
||||||
Exit Status:
|
|
||||||
0 if OK,
|
|
||||||
1 if the action failed.
|
|
||||||
"""
|
|
||||||
print_and_exit(help_msg)
|
|
||||||
|
|
||||||
def parse_args():
|
|
||||||
args = list(sys.argv)
|
|
||||||
del args[0]
|
|
||||||
if len(args) == 0:
|
|
||||||
usage_and_exit()
|
|
||||||
if args[0] == '--help':
|
|
||||||
help_and_exit()
|
|
||||||
dryrun = '--dryrun' == args[0]
|
|
||||||
if dryrun:
|
|
||||||
del args[0]
|
|
||||||
if len(args) < 2:
|
|
||||||
usage_and_exit()
|
|
||||||
symlink_file = args[0]
|
|
||||||
public_libs = args[1:]
|
|
||||||
return dryrun, symlink_file, public_libs
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
dryrun, symlink_file, public_libs = parse_args()
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("--dryrun", help="Don't write any output",
|
||||||
# Check that the given libc++.so file is a valid symlink.
|
action="store_true", default=False)
|
||||||
if not os.path.islink(symlink_file):
|
parser.add_argument("--rename", action="store_true", default=False,
|
||||||
print_and_exit("symlink file %s is not a symlink" % symlink_file)
|
help="Rename the output as input so we can replace it")
|
||||||
|
parser.add_argument("--input", help="Path to libc++ library", required=True)
|
||||||
# Read the symlink so we know what libc++ to link to in the linker script.
|
parser.add_argument("--output", help="Path to libc++ linker script", required=True)
|
||||||
linked_libcxx = os.readlink(symlink_file)
|
parser.add_argument("libraries", nargs="+",
|
||||||
|
help="List of libraries libc++ depends on")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Prepare the list of public libraries to link.
|
# Prepare the list of public libraries to link.
|
||||||
public_libs = ['-l%s' % l for l in public_libs]
|
public_libs = ['-l%s' % l for l in args.libraries]
|
||||||
|
|
||||||
# Generate the linker script contents and print the script and destination
|
# Generate the linker script contents.
|
||||||
# information.
|
contents = "INPUT(%s)" % ' '.join([args.input] + public_libs)
|
||||||
contents = "INPUT(%s %s)" % (linked_libcxx, ' '.join(public_libs))
|
print("GENERATING SCRIPT: '%s' as file %s" % (contents, args.output))
|
||||||
print("GENERATING SCRIPT: '%s' as file %s" % (contents, symlink_file))
|
|
||||||
|
|
||||||
# Remove the existing libc++ symlink and replace it with the script.
|
if args.dryrun:
|
||||||
if not dryrun:
|
return 0
|
||||||
os.unlink(symlink_file)
|
|
||||||
with open(symlink_file, 'w') as f:
|
# Remove the existing libc++ symlink if it exists.
|
||||||
f.write(contents + "\n")
|
if os.path.islink(args.output):
|
||||||
|
os.unlink(args.output)
|
||||||
|
|
||||||
|
# Replace it with the linker script.
|
||||||
|
with open(args.output, 'w') as f:
|
||||||
|
f.write(contents + "\n")
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
sys.exit(main())
|
||||||
|
Reference in New Issue
Block a user