Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: build/toolchain/mac/linker_driver.py

Issue 2157573002: [Mac/GN] Add a new linker_driver.py option to save unstripped linker output. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compiler config Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/toolchain/mac/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 13 matching lines...) Expand all
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,dsym,<dsym_path_prefix> 27 # -Wcrl,dsym,<dsym_path_prefix>
28 # After invoking the linker, this will run `dsymutil` on the linker's 28 # 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 29 # output, producing a dSYM bundle, stored at dsym_path_prefix. As an
30 # example, if the linker driver were invoked with: 30 # example, if the linker driver were invoked with:
31 # "... -o out/gn/obj/foo/libbar.dylib ... -Wcrl,dsym,out/gn ..." 31 # "... -o out/gn/obj/foo/libbar.dylib ... -Wcrl,dsym,out/gn ..."
32 # The resulting dSYM would be out/gn/libbar.dylib.dSYM/. 32 # The resulting dSYM would be out/gn/libbar.dylib.dSYM/.
33 # 33 #
34 # -Wcrl,unstripped,<unstripped_path_prefix>
35 # After invoking the linker, and before strip, this will save a copy of
36 # the unstripped linker output in the directory unstripped_path_prefix.
37 #
34 # -Wcrl,strip,<strip_arguments> 38 # -Wcrl,strip,<strip_arguments>
35 # After invoking the linker, and optionally dsymutil, this will run 39 # After invoking the linker, and optionally dsymutil, this will run
36 # the strip command on the linker's output. strip_arguments are 40 # the strip command on the linker's output. strip_arguments are
37 # comma-separated arguments to be passed to the strip command. 41 # comma-separated arguments to be passed to the strip command.
38 42
39 def Main(args): 43 def Main(args):
40 """Main function for the linker driver. Separates out the arguments for 44 """Main function for the linker driver. Separates out the arguments for
41 the main compiler driver and the linker driver, then invokes all the 45 the main compiler driver and the linker driver, then invokes all the
42 required tools. 46 required tools.
43 47
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 linker_out = _FindLinkerOutput(full_args) 132 linker_out = _FindLinkerOutput(full_args)
129 (head, tail) = os.path.split(linker_out) 133 (head, tail) = os.path.split(linker_out)
130 dsym_out = os.path.join(dsym_path_prefix, tail + '.dSYM') 134 dsym_out = os.path.join(dsym_path_prefix, tail + '.dSYM')
131 135
132 # Remove old dSYMs before invoking dsymutil. 136 # Remove old dSYMs before invoking dsymutil.
133 _RemovePath(dsym_out) 137 _RemovePath(dsym_out)
134 subprocess.check_call(['xcrun', 'dsymutil', '-o', dsym_out, linker_out]) 138 subprocess.check_call(['xcrun', 'dsymutil', '-o', dsym_out, linker_out])
135 return [dsym_out] 139 return [dsym_out]
136 140
137 141
142 def RunSaveUnstripped(unstripped_path_prefix, full_args):
143 """Linker driver action for -Wcrl,unstripped,<unstripped_path_prefix>. Copies
144 the linker output to |unstripped_path_prefix| before stripping.
145
146 Args:
147 unstripped_path_prefix: string, The path at which the unstripped output
148 should be located.
149 full_args: list of string, Full argument list for the linker driver.
150
151 Returns:
152 list of string, Build step outputs.
153 """
154 if not len(unstripped_path_prefix):
155 raise ValueError('Unspecified unstripped output file')
156
157 linker_out = _FindLinkerOutput(full_args)
158 (head, tail) = os.path.split(linker_out)
159 unstripped_out = os.path.join(unstripped_path_prefix, tail + '.unstripped')
160
161 shutil.copyfile(linker_out, unstripped_out)
162 return [unstripped_out]
163
164
138 def RunStrip(strip_args_string, full_args): 165 def RunStrip(strip_args_string, full_args):
139 """Linker driver action for -Wcrl,strip,<strip_arguments>. 166 """Linker driver action for -Wcrl,strip,<strip_arguments>.
140 167
141 Args: 168 Args:
142 strip_args_string: string, Comma-separated arguments for `strip`. 169 strip_args_string: string, Comma-separated arguments for `strip`.
143 full_args: list of string, Full arguments for the linker driver. 170 full_args: list of string, Full arguments for the linker driver.
144 171
145 Returns: 172 Returns:
146 list of string, Build step outputs. 173 list of string, Build step outputs.
147 """ 174 """
(...skipping 23 matching lines...) Expand all
171 198
172 199
173 _LINKER_DRIVER_ARG_PREFIX = '-Wcrl,' 200 _LINKER_DRIVER_ARG_PREFIX = '-Wcrl,'
174 201
175 """List of linker driver actions. The sort order of this list affects the 202 """List of linker driver actions. The sort order of this list affects the
176 order in which the actions are invoked. The first item in the tuple is the 203 order in which the actions are invoked. The first item in the tuple is the
177 argument's -Wcrl,<sub_argument> and the second is the function to invoke. 204 argument's -Wcrl,<sub_argument> and the second is the function to invoke.
178 """ 205 """
179 _LINKER_DRIVER_ACTIONS = [ 206 _LINKER_DRIVER_ACTIONS = [
180 ('dsym,', RunDsymUtil), 207 ('dsym,', RunDsymUtil),
208 ('unstripped,', RunSaveUnstripped),
181 ('strip,', RunStrip), 209 ('strip,', RunStrip),
182 ] 210 ]
183 211
184 212
185 if __name__ == '__main__': 213 if __name__ == '__main__':
186 Main(sys.argv) 214 Main(sys.argv)
187 sys.exit(0) 215 sys.exit(0)
OLDNEW
« no previous file with comments | « build/toolchain/mac/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698