| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. | 3 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import os.path | 8 import os.path |
| 9 import shutil | 9 import shutil |
| 10 import subprocess | 10 import subprocess |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 # The linker_driver.py is responsible for forwarding a linker invocation to | 13 # The linker_driver.py is responsible for forwarding a linker invocation to |
| 14 # the compiler driver, while processing special arguments itself. | 14 # the compiler driver, while processing special arguments itself. |
| 15 # | 15 # |
| 16 # Usage: linker_driver.py clang++ main.o -L. -llib -o prog -Wcrl,dsym,out | 16 # Usage: linker_driver.py clang++ main.o -L. -llib -o prog -Wcrl,dsym,out |
| 17 # | 17 # |
| 18 # On Mac, the logical step of linking is handled by three discrete tools to | 18 # On Mac, the logical step of linking is handled by three discrete tools to |
| 19 # perform the image link, debug info link, and strip. The linker_driver.py | 19 # perform the image link, debug info link, and strip. The linker_driver.py |
| 20 # combines these three steps into a single tool. | 20 # combines these three steps into a single tool. |
| 21 # | 21 # |
| 22 # The command passed to the linker_driver.py should be the compiler driver | 22 # The command passed to the linker_driver.py should be the compiler driver |
| 23 # invocation for the linker. It is first invoked unaltered (except for the | 23 # invocation for the linker. It is first invoked unaltered (except for the |
| 24 # removal of the special driver arguments, described below). Then the driver | 24 # removal of the special driver arguments, described below). Then the driver |
| 25 # performs additional actions, based on these arguments: | 25 # performs additional actions, based on these arguments: |
| 26 # | 26 # |
| 27 # -Wcrl,installname,<old_intall_name>,<new_install_name> |
| 28 # After invoking the linker, this will run `install_name_tool` on the |
| 29 # linker's output. It will use the -change option to change a dylib's |
| 30 # install name from old to new. |
| 31 # |
| 27 # -Wcrl,dsym,<dsym_path_prefix> | 32 # -Wcrl,dsym,<dsym_path_prefix> |
| 28 # After invoking the linker, this will run `dsymutil` on the linker's | 33 # After invoking the linker, this will run `dsymutil` on the linker's |
| 29 # output, producing a dSYM bundle, stored at dsym_path_prefix. As an | 34 # output, producing a dSYM bundle, stored at dsym_path_prefix. As an |
| 30 # example, if the linker driver were invoked with: | 35 # example, if the linker driver were invoked with: |
| 31 # "... -o out/gn/obj/foo/libbar.dylib ... -Wcrl,dsym,out/gn ..." | 36 # "... -o out/gn/obj/foo/libbar.dylib ... -Wcrl,dsym,out/gn ..." |
| 32 # The resulting dSYM would be out/gn/libbar.dylib.dSYM/. | 37 # The resulting dSYM would be out/gn/libbar.dylib.dSYM/. |
| 33 # | 38 # |
| 34 # -Wcrl,unstripped,<unstripped_path_prefix> | 39 # -Wcrl,unstripped,<unstripped_path_prefix> |
| 35 # After invoking the linker, and before strip, this will save a copy of | 40 # After invoking the linker, and before strip, this will save a copy of |
| 36 # the unstripped linker output in the directory unstripped_path_prefix. | 41 # the unstripped linker output in the directory unstripped_path_prefix. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 112 |
| 108 for driver_action in _LINKER_DRIVER_ACTIONS: | 113 for driver_action in _LINKER_DRIVER_ACTIONS: |
| 109 (name, action) = driver_action | 114 (name, action) = driver_action |
| 110 if sub_arg.startswith(name): | 115 if sub_arg.startswith(name): |
| 111 return (name, | 116 return (name, |
| 112 lambda full_args: action(sub_arg[len(name):], full_args)) | 117 lambda full_args: action(sub_arg[len(name):], full_args)) |
| 113 | 118 |
| 114 raise ValueError('Unknown linker driver argument: %s' % (arg,)) | 119 raise ValueError('Unknown linker driver argument: %s' % (arg,)) |
| 115 | 120 |
| 116 | 121 |
| 122 def RunInstallNameTool(old_comma_new, full_args): |
| 123 """Linker driver action for -Wcrl,installname,<old>,<new>. Invokes |
| 124 `install_name_tool -change <old> <new>` on the linker's output. |
| 125 |
| 126 Args: |
| 127 old_comma_new: string, The comma-separated old and new install names to |
| 128 change. |
| 129 full_args: list of string, Full argument list for the linker driver. |
| 130 |
| 131 Returns: |
| 132 list of string, Build step outputs. |
| 133 """ |
| 134 (old, new) = old_comma_new.split(',') |
| 135 if not len(old) or not len(new): |
| 136 raise ValueError('Unspecified old and new paths') |
| 137 |
| 138 linker_out = _FindLinkerOutput(full_args) |
| 139 subprocess.check_call( |
| 140 ['xcrun', 'install_name_tool', '-change', old, new, linker_out]) |
| 141 return [] |
| 142 |
| 143 |
| 117 def RunDsymUtil(dsym_path_prefix, full_args): | 144 def RunDsymUtil(dsym_path_prefix, full_args): |
| 118 """Linker driver action for -Wcrl,dsym,<dsym-path-prefix>. Invokes dsymutil | 145 """Linker driver action for -Wcrl,dsym,<dsym-path-prefix>. Invokes dsymutil |
| 119 on the linker's output and produces a dsym file at |dsym_file| path. | 146 on the linker's output and produces a dsym file at |dsym_file| path. |
| 120 | 147 |
| 121 Args: | 148 Args: |
| 122 dsym_path_prefix: string, The path at which the dsymutil output should be | 149 dsym_path_prefix: string, The path at which the dsymutil output should be |
| 123 located. | 150 located. |
| 124 full_args: list of string, Full argument list for the linker driver. | 151 full_args: list of string, Full argument list for the linker driver. |
| 125 | 152 |
| 126 Returns: | 153 Returns: |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 os.unlink(path) | 232 os.unlink(path) |
| 206 | 233 |
| 207 | 234 |
| 208 _LINKER_DRIVER_ARG_PREFIX = '-Wcrl,' | 235 _LINKER_DRIVER_ARG_PREFIX = '-Wcrl,' |
| 209 | 236 |
| 210 """List of linker driver actions. The sort order of this list affects the | 237 """List of linker driver actions. The sort order of this list affects the |
| 211 order in which the actions are invoked. The first item in the tuple is the | 238 order in which the actions are invoked. The first item in the tuple is the |
| 212 argument's -Wcrl,<sub_argument> and the second is the function to invoke. | 239 argument's -Wcrl,<sub_argument> and the second is the function to invoke. |
| 213 """ | 240 """ |
| 214 _LINKER_DRIVER_ACTIONS = [ | 241 _LINKER_DRIVER_ACTIONS = [ |
| 242 ('installname,', RunInstallNameTool), |
| 215 ('dsym,', RunDsymUtil), | 243 ('dsym,', RunDsymUtil), |
| 216 ('unstripped,', RunSaveUnstripped), | 244 ('unstripped,', RunSaveUnstripped), |
| 217 ('strip,', RunStrip), | 245 ('strip,', RunStrip), |
| 218 ] | 246 ] |
| 219 | 247 |
| 220 | 248 |
| 221 if __name__ == '__main__': | 249 if __name__ == '__main__': |
| 222 Main(sys.argv) | 250 Main(sys.argv) |
| 223 sys.exit(0) | 251 sys.exit(0) |
| OLD | NEW |