| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Functions for dealing with determining --tool-prefix.""" | 5 """Functions for dealing with determining --tool-prefix.""" |
| 6 | 6 |
| 7 import distutils.spawn | 7 import distutils.spawn |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 | 10 |
| 11 _STATUS_DETECTED = 1 | 11 _STATUS_DETECTED = 1 |
| 12 _STATUS_VERIFIED = 2 | 12 _STATUS_VERIFIED = 2 |
| 13 | 13 |
| 14 | 14 |
| 15 class LazyPaths(object): | 15 class LazyPaths(object): |
| 16 def __init__(self, args=None, tool_prefix=None, output_directory=None, | 16 def __init__(self, tool_prefix=None, output_directory=None, |
| 17 input_file=None): | 17 any_path_within_output_directory=None): |
| 18 tool_prefix = tool_prefix or (args and args.tool_prefix) | |
| 19 output_directory = output_directory or (args and args.output_directory) | |
| 20 self._tool_prefix = tool_prefix | 18 self._tool_prefix = tool_prefix |
| 21 self._output_directory = output_directory | 19 self._output_directory = output_directory |
| 22 self._input_file = input_file | 20 self._any_path_within_output_directory = any_path_within_output_directory |
| 23 self._output_directory_status = _STATUS_DETECTED if output_directory else 0 | 21 self._output_directory_status = _STATUS_DETECTED if output_directory else 0 |
| 24 self._tool_prefix_status = _STATUS_DETECTED if tool_prefix else 0 | 22 self._tool_prefix_status = _STATUS_DETECTED if tool_prefix else 0 |
| 25 | 23 |
| 26 @property | 24 @property |
| 27 def tool_prefix(self): | 25 def tool_prefix(self): |
| 28 if self._tool_prefix_status < _STATUS_DETECTED: | 26 if self._tool_prefix_status < _STATUS_DETECTED: |
| 29 self._tool_prefix_status = _STATUS_DETECTED | 27 self._tool_prefix_status = _STATUS_DETECTED |
| 30 self._tool_prefix = self._DetectToolPrefix() or '' | 28 self._tool_prefix = self._DetectToolPrefix() or '' |
| 31 logging.debug('Detected --tool-prefix=%s', self._tool_prefix) | 29 logging.debug('Detected --tool-prefix=%s', self._tool_prefix) |
| 32 return self._tool_prefix | 30 return self._tool_prefix |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 full_path = distutils.spawn.find_executable(tool_prefix + 'c++filt') | 55 full_path = distutils.spawn.find_executable(tool_prefix + 'c++filt') |
| 58 else: | 56 else: |
| 59 full_path = tool_prefix + 'c++filt' | 57 full_path = tool_prefix + 'c++filt' |
| 60 | 58 |
| 61 if not full_path or not os.path.isfile(full_path): | 59 if not full_path or not os.path.isfile(full_path): |
| 62 raise Exception('Bad --tool-prefix. Path not found: %s' % full_path) | 60 raise Exception('Bad --tool-prefix. Path not found: %s' % full_path) |
| 63 logging.info('Using --tool-prefix=%s', self._tool_prefix) | 61 logging.info('Using --tool-prefix=%s', self._tool_prefix) |
| 64 return tool_prefix | 62 return tool_prefix |
| 65 | 63 |
| 66 def _DetectOutputDirectory(self): | 64 def _DetectOutputDirectory(self): |
| 67 # See if input file is in out/Release. | 65 # Try and find build.ninja. |
| 68 abs_path = os.path.abspath(self._input_file) | 66 abs_path = os.path.abspath(self._any_path_within_output_directory) |
| 69 release_idx = abs_path.find('Release') | 67 while True: |
| 70 if release_idx != -1: | 68 if os.path.exists(os.path.join(abs_path, 'build.ninja')): |
| 71 output_directory = abs_path[:release_idx] + 'Release' | 69 return os.path.relpath(abs_path) |
| 72 output_directory = os.path.relpath(abs_path[:release_idx] + '/Release') | 70 parent_dir = os.path.dirname(abs_path) |
| 73 return output_directory | 71 if parent_dir == abs_path: |
| 72 break |
| 73 abs_path = abs_path = parent_dir |
| 74 | 74 |
| 75 # See if CWD=output directory. | 75 # See if CWD=output directory. |
| 76 if os.path.exists('build.ninja'): | 76 if os.path.exists('build.ninja'): |
| 77 return '.' | 77 return '.' |
| 78 return None | 78 return None |
| 79 | 79 |
| 80 def _DetectToolPrefix(self): | 80 def _DetectToolPrefix(self): |
| 81 output_directory = self.output_directory | 81 output_directory = self.output_directory |
| 82 if output_directory: | 82 if output_directory: |
| 83 # Auto-detect from build_vars.txt | 83 # Auto-detect from build_vars.txt |
| 84 build_vars_path = os.path.join(output_directory, 'build_vars.txt') | 84 build_vars_path = os.path.join(output_directory, 'build_vars.txt') |
| 85 if os.path.exists(build_vars_path): | 85 if os.path.exists(build_vars_path): |
| 86 with open(build_vars_path) as f: | 86 with open(build_vars_path) as f: |
| 87 build_vars = dict(l.rstrip().split('=', 1) for l in f if '=' in l) | 87 build_vars = dict(l.rstrip().split('=', 1) for l in f if '=' in l) |
| 88 return os.path.normpath( | 88 return os.path.normpath( |
| 89 os.path.join(output_directory, build_vars['android_tool_prefix'])) | 89 os.path.join(output_directory, build_vars['android_tool_prefix'])) |
| 90 return None | 90 return None |
| OLD | NEW |