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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 strip_command.append(_FindLinkerOutput(full_args)) | 151 strip_command.append(_FindLinkerOutput(full_args)) |
152 subprocess.check_call(strip_command) | 152 subprocess.check_call(strip_command) |
153 return [] | 153 return [] |
154 | 154 |
155 | 155 |
156 def _FindLinkerOutput(full_args): | 156 def _FindLinkerOutput(full_args): |
157 """Finds the output of the linker by looking for the output flag in its | 157 """Finds the output of the linker by looking for the output flag in its |
158 argument list. As this is a required linker argument, raises an error if it | 158 argument list. As this is a required linker argument, raises an error if it |
159 cannot be found. | 159 cannot be found. |
160 """ | 160 """ |
161 return full_args[full_args.index('-o') + 1] | 161 # The linker_driver.py script may be used to wrap either the compiler linker |
162 # (uses -o to configure the output) or lipo (uses -output to configure the | |
163 # output). Since wrapping the compiler linker is the most likely possibility | |
164 # use try/except and fallback to checking for -output if -o is not found. | |
165 try: | |
166 output_flag_index = full_args.index('-o') | |
167 except ValueError as _: | |
Robert Sesek
2016/07/18 20:09:43
Don't need an |as _| here if you're just catching
sdefresne
2016/07/19 09:12:13
Done.
| |
168 output_flag_index = full_args.index('-output') | |
169 return full_args[output_flag_index + 1] | |
162 | 170 |
163 | 171 |
164 def _RemovePath(path): | 172 def _RemovePath(path): |
165 """Removes the file or directory at |path| if it exists.""" | 173 """Removes the file or directory at |path| if it exists.""" |
166 if os.path.exists(path): | 174 if os.path.exists(path): |
167 if os.path.isdir(path): | 175 if os.path.isdir(path): |
168 shutil.rmtree(path) | 176 shutil.rmtree(path) |
169 else: | 177 else: |
170 os.unlink(path) | 178 os.unlink(path) |
171 | 179 |
172 | 180 |
173 _LINKER_DRIVER_ARG_PREFIX = '-Wcrl,' | 181 _LINKER_DRIVER_ARG_PREFIX = '-Wcrl,' |
174 | 182 |
175 """List of linker driver actions. The sort order of this list affects the | 183 """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 | 184 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. | 185 argument's -Wcrl,<sub_argument> and the second is the function to invoke. |
178 """ | 186 """ |
179 _LINKER_DRIVER_ACTIONS = [ | 187 _LINKER_DRIVER_ACTIONS = [ |
180 ('dsym,', RunDsymUtil), | 188 ('dsym,', RunDsymUtil), |
181 ('strip,', RunStrip), | 189 ('strip,', RunStrip), |
182 ] | 190 ] |
183 | 191 |
184 | 192 |
185 if __name__ == '__main__': | 193 if __name__ == '__main__': |
186 Main(sys.argv) | 194 Main(sys.argv) |
187 sys.exit(0) | 195 sys.exit(0) |
OLD | NEW |