| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2012 Google Inc. All rights reserved. | |
| 2 # | |
| 3 # Redistribution and use in source and binary forms, with or without | |
| 4 # modification, are permitted provided that the following conditions are | |
| 5 # met: | |
| 6 # | |
| 7 # * Redistributions of source code must retain the above copyright | |
| 8 # notice, this list of conditions and the following disclaimer. | |
| 9 # * Redistributions in binary form must reproduce the above | |
| 10 # copyright notice, this list of conditions and the following disclaimer | |
| 11 # in the documentation and/or other materials provided with the | |
| 12 # distribution. | |
| 13 # * Neither the name of Google Inc. nor the names of its | |
| 14 # contributors may be used to endorse or promote products derived from | |
| 15 # this software without specific prior written permission. | |
| 16 # | |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 | |
| 29 import os | |
| 30 import sys | |
| 31 | |
| 32 from webkitpy.common.memoized import memoized | |
| 33 | |
| 34 | |
| 35 def add_typ_dir_to_sys_path(): | |
| 36 path_to_typ = get_typ_dir() | |
| 37 if path_to_typ not in sys.path: | |
| 38 sys.path.append(path_to_typ) | |
| 39 | |
| 40 | |
| 41 def add_bindings_scripts_dir_to_sys_path(): | |
| 42 path_to_bindings_scripts = get_bindings_scripts_dir() | |
| 43 if path_to_bindings_scripts not in sys.path: | |
| 44 sys.path.append(path_to_bindings_scripts) | |
| 45 | |
| 46 | |
| 47 def get_bindings_scripts_dir(): | |
| 48 return os.path.join(get_source_dir(), 'bindings', 'scripts') | |
| 49 | |
| 50 | |
| 51 def get_blink_dir(): | |
| 52 return os.path.dirname(os.path.dirname(get_scripts_dir())) | |
| 53 | |
| 54 | |
| 55 def get_chromium_src_dir(): | |
| 56 return os.path.dirname(os.path.dirname(get_blink_dir())) | |
| 57 | |
| 58 | |
| 59 def get_scripts_dir(): | |
| 60 return os.path.dirname( | |
| 61 os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) | |
| 62 | |
| 63 | |
| 64 def get_source_dir(): | |
| 65 return os.path.join(get_blink_dir(), 'Source') | |
| 66 | |
| 67 | |
| 68 def get_typ_dir(): | |
| 69 return os.path.join(get_chromium_src_dir(), 'third_party', 'typ') | |
| 70 | |
| 71 | |
| 72 def get_webkitpy_thirdparty_dir(): | |
| 73 return os.path.join(get_scripts_dir(), 'webkitpy', 'thirdparty') | |
| 74 | |
| 75 | |
| 76 class WebKitFinder(object): | |
| 77 | |
| 78 def __init__(self, filesystem): | |
| 79 self._filesystem = filesystem | |
| 80 self._dirsep = filesystem.sep | |
| 81 self._sys_path = sys.path | |
| 82 self._env_path = os.environ['PATH'].split(os.pathsep) | |
| 83 | |
| 84 @memoized | |
| 85 def _webkit_base(self): | |
| 86 """Returns the absolute path to the top of the WebKit tree. | |
| 87 | |
| 88 Raises an AssertionError if the top dir can't be determined. | |
| 89 """ | |
| 90 # TODO(qyearsley): This code somewhat duplicates the code in | |
| 91 # git.find_checkout_root(). | |
| 92 module_path = self._filesystem.abspath(self._filesystem.path_to_module(s
elf.__module__)) | |
| 93 tools_index = module_path.rfind('Tools') | |
| 94 assert tools_index != -1, 'could not find location of this checkout from
%s' % module_path | |
| 95 return self._filesystem.normpath(module_path[0:tools_index - 1]) | |
| 96 | |
| 97 @memoized | |
| 98 def chromium_base(self): | |
| 99 return self._filesystem.dirname(self._filesystem.dirname(self._webkit_ba
se())) | |
| 100 | |
| 101 # Do not expose this function in order to make the code robust against | |
| 102 # directory structure changes. | |
| 103 def _path_from_webkit_base(self, *comps): | |
| 104 return self._filesystem.join(self._webkit_base(), *comps) | |
| 105 | |
| 106 def path_from_chromium_base(self, *comps): | |
| 107 return self._filesystem.join(self.chromium_base(), *comps) | |
| 108 | |
| 109 def path_from_blink_source(self, *comps): | |
| 110 return self._filesystem.join(self._filesystem.join(self._webkit_base(),
'Source'), *comps) | |
| 111 | |
| 112 def path_from_tools_scripts(self, *comps): | |
| 113 return self._filesystem.join(self._filesystem.join(self._webkit_base(),
'Tools', 'Scripts'), *comps) | |
| 114 | |
| 115 def layout_tests_dir(self): | |
| 116 return self._path_from_webkit_base('LayoutTests') | |
| 117 | |
| 118 def path_from_layout_tests(self, *comps): | |
| 119 return self._filesystem.join(self.layout_tests_dir(), *comps) | |
| 120 | |
| 121 def perf_tests_dir(self): | |
| 122 return self._path_from_webkit_base('PerformanceTests') | |
| 123 | |
| 124 def layout_test_name(self, file_path): | |
| 125 """Returns a layout test name, given the path from the repo root. | |
| 126 | |
| 127 Note: this appears to not work on Windows; see crbug.com/658795. | |
| 128 Also, this function duplicates functionality that's in | |
| 129 Port.relative_test_filename. | |
| 130 TODO(qyearsley): De-duplicate this and Port.relative_test_filename, | |
| 131 and ensure that it works properly with Windows paths. | |
| 132 | |
| 133 Args: | |
| 134 file_path: A relative path from the root of the Chromium repo. | |
| 135 | |
| 136 Returns: | |
| 137 The normalized layout test name, which is just the relative path fro
m | |
| 138 the LayoutTests directory, using forward slash as the path separator
. | |
| 139 Returns None if the given file is not in the LayoutTests directory. | |
| 140 """ | |
| 141 layout_tests_rel_path = self._filesystem.relpath(self.layout_tests_dir()
, self.chromium_base()) | |
| 142 if not file_path.startswith(layout_tests_rel_path): | |
| 143 return None | |
| 144 return file_path[len(layout_tests_rel_path) + 1:] | |
| 145 | |
| 146 @memoized | |
| 147 def depot_tools_base(self): | |
| 148 # This basically duplicates src/build/find_depot_tools.py without the si
de effects | |
| 149 # (adding the directory to sys.path and importing breakpad). | |
| 150 return (self._check_paths_for_depot_tools(self._sys_path) or | |
| 151 self._check_paths_for_depot_tools(self._env_path) or | |
| 152 self._check_upward_for_depot_tools()) | |
| 153 | |
| 154 def _check_paths_for_depot_tools(self, paths): | |
| 155 for path in paths: | |
| 156 if path.rstrip(self._dirsep).endswith('depot_tools'): | |
| 157 return path | |
| 158 return None | |
| 159 | |
| 160 def _check_upward_for_depot_tools(self): | |
| 161 fs = self._filesystem | |
| 162 prev_dir = '' | |
| 163 current_dir = fs.dirname(self._webkit_base()) | |
| 164 while current_dir != prev_dir: | |
| 165 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')): | |
| 166 return fs.join(current_dir, 'depot_tools') | |
| 167 prev_dir = current_dir | |
| 168 current_dir = fs.dirname(current_dir) | |
| 169 | |
| 170 def path_from_depot_tools_base(self, *comps): | |
| 171 return self._filesystem.join(self.depot_tools_base(), *comps) | |
| OLD | NEW |