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 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 strip_command.append(_FindLinkerOutput(full_args)) | 178 strip_command.append(_FindLinkerOutput(full_args)) |
179 subprocess.check_call(strip_command) | 179 subprocess.check_call(strip_command) |
180 return [] | 180 return [] |
181 | 181 |
182 | 182 |
183 def _FindLinkerOutput(full_args): | 183 def _FindLinkerOutput(full_args): |
184 """Finds the output of the linker by looking for the output flag in its | 184 """Finds the output of the linker by looking for the output flag in its |
185 argument list. As this is a required linker argument, raises an error if it | 185 argument list. As this is a required linker argument, raises an error if it |
186 cannot be found. | 186 cannot be found. |
187 """ | 187 """ |
188 return full_args[full_args.index('-o') + 1] | 188 # The linker_driver.py script may be used to wrap either the compiler linker |
| 189 # (uses -o to configure the output) or lipo (uses -output to configure the |
| 190 # output). Since wrapping the compiler linker is the most likely possibility |
| 191 # use try/except and fallback to checking for -output if -o is not found. |
| 192 try: |
| 193 output_flag_index = full_args.index('-o') |
| 194 except ValueError: |
| 195 output_flag_index = full_args.index('-output') |
| 196 return full_args[output_flag_index + 1] |
189 | 197 |
190 | 198 |
191 def _RemovePath(path): | 199 def _RemovePath(path): |
192 """Removes the file or directory at |path| if it exists.""" | 200 """Removes the file or directory at |path| if it exists.""" |
193 if os.path.exists(path): | 201 if os.path.exists(path): |
194 if os.path.isdir(path): | 202 if os.path.isdir(path): |
195 shutil.rmtree(path) | 203 shutil.rmtree(path) |
196 else: | 204 else: |
197 os.unlink(path) | 205 os.unlink(path) |
198 | 206 |
199 | 207 |
200 _LINKER_DRIVER_ARG_PREFIX = '-Wcrl,' | 208 _LINKER_DRIVER_ARG_PREFIX = '-Wcrl,' |
201 | 209 |
202 """List of linker driver actions. The sort order of this list affects the | 210 """List of linker driver actions. The sort order of this list affects the |
203 order in which the actions are invoked. The first item in the tuple is the | 211 order in which the actions are invoked. The first item in the tuple is the |
204 argument's -Wcrl,<sub_argument> and the second is the function to invoke. | 212 argument's -Wcrl,<sub_argument> and the second is the function to invoke. |
205 """ | 213 """ |
206 _LINKER_DRIVER_ACTIONS = [ | 214 _LINKER_DRIVER_ACTIONS = [ |
207 ('dsym,', RunDsymUtil), | 215 ('dsym,', RunDsymUtil), |
208 ('unstripped,', RunSaveUnstripped), | 216 ('unstripped,', RunSaveUnstripped), |
209 ('strip,', RunStrip), | 217 ('strip,', RunStrip), |
210 ] | 218 ] |
211 | 219 |
212 | 220 |
213 if __name__ == '__main__': | 221 if __name__ == '__main__': |
214 Main(sys.argv) | 222 Main(sys.argv) |
215 sys.exit(0) | 223 sys.exit(0) |
OLD | NEW |