Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import os | 29 import os |
| 30 import sys | 30 import sys |
| 31 | 31 |
| 32 from webkitpy.common.memoized import memoized | |
| 33 | |
| 32 | 34 |
| 33 def add_typ_dir_to_sys_path(): | 35 def add_typ_dir_to_sys_path(): |
| 34 path_to_typ = get_typ_dir() | 36 path_to_typ = get_typ_dir() |
| 35 if path_to_typ not in sys.path: | 37 if path_to_typ not in sys.path: |
| 36 sys.path.append(path_to_typ) | 38 sys.path.append(path_to_typ) |
| 37 | 39 |
| 38 | 40 |
| 39 def add_bindings_scripts_dir_to_sys_path(): | 41 def add_bindings_scripts_dir_to_sys_path(): |
| 40 path_to_bindings_scripts = get_bindings_scripts_dir() | 42 path_to_bindings_scripts = get_bindings_scripts_dir() |
| 41 if path_to_bindings_scripts not in sys.path: | 43 if path_to_bindings_scripts not in sys.path: |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 71 return os.path.join(get_scripts_dir(), 'webkitpy', 'thirdparty') | 73 return os.path.join(get_scripts_dir(), 'webkitpy', 'thirdparty') |
| 72 | 74 |
| 73 | 75 |
| 74 class WebKitFinder(object): | 76 class WebKitFinder(object): |
| 75 | 77 |
| 76 def __init__(self, filesystem): | 78 def __init__(self, filesystem): |
| 77 self._filesystem = filesystem | 79 self._filesystem = filesystem |
| 78 self._dirsep = filesystem.sep | 80 self._dirsep = filesystem.sep |
| 79 self._sys_path = sys.path | 81 self._sys_path = sys.path |
| 80 self._env_path = os.environ['PATH'].split(os.pathsep) | 82 self._env_path = os.environ['PATH'].split(os.pathsep) |
| 81 self._webkit_base = None | |
| 82 self._chromium_base = None | 83 self._chromium_base = None |
| 83 self._depot_tools = None | 84 self._depot_tools = None |
| 84 | 85 |
| 85 # TODO(tkent): Make this private. We should use functions for | 86 # This function is not public. We should use functions for sub-directories |
| 86 # sub-directories in order to make the code robust against directory | 87 # in order to make the code robust against directory structure changes. |
|
qyearsley
2017/05/09 21:46:28
This comment should be unnecessary, since we have
tkent
2017/05/10 23:42:21
ok, removed.
| |
| 87 # structure changes. | 88 @memoized |
| 88 def webkit_base(self): | 89 def _webkit_base(self): |
| 89 """Returns the absolute path to the top of the WebKit tree. | 90 """Returns the absolute path to the top of the WebKit tree. |
| 90 | 91 |
| 91 Raises an AssertionError if the top dir can't be determined. | 92 Raises an AssertionError if the top dir can't be determined. |
| 92 """ | 93 """ |
| 93 # TODO(qyearsley): This code somewhat duplicates the code in | 94 # TODO(qyearsley): This code somewhat duplicates the code in |
| 94 # git.find_checkout_root(). | 95 # git.find_checkout_root(). |
| 95 if not self._webkit_base: | 96 module_path = self._filesystem.abspath(self._filesystem.path_to_module(s elf.__module__)) |
| 96 self._webkit_base = self._webkit_base | 97 tools_index = module_path.rfind('Tools') |
| 97 module_path = self._filesystem.abspath(self._filesystem.path_to_modu le(self.__module__)) | 98 assert tools_index != -1, 'could not find location of this checkout from %s' % module_path |
| 98 tools_index = module_path.rfind('Tools') | 99 return self._filesystem.normpath(module_path[0:tools_index - 1]) |
| 99 assert tools_index != -1, 'could not find location of this checkout from %s' % module_path | |
| 100 self._webkit_base = self._filesystem.normpath(module_path[0:tools_in dex - 1]) | |
| 101 return self._webkit_base | |
| 102 | 100 |
| 103 def chromium_base(self): | 101 def chromium_base(self): |
| 104 if not self._chromium_base: | 102 if not self._chromium_base: |
| 105 self._chromium_base = self._filesystem.dirname(self._filesystem.dirn ame(self.webkit_base())) | 103 self._chromium_base = self._filesystem.dirname(self._filesystem.dirn ame(self._webkit_base())) |
|
qyearsley
2017/05/09 21:46:28
Potential minor change for consistency: Now that _
tkent
2017/05/10 23:42:21
I'll do it in a separated CL.
| |
| 106 return self._chromium_base | 104 return self._chromium_base |
| 107 | 105 |
| 108 # Do not expose this function in order to make the code robust against | 106 # Do not expose this function in order to make the code robust against |
| 109 # directory structure changes. | 107 # directory structure changes. |
| 110 def _path_from_webkit_base(self, *comps): | 108 def _path_from_webkit_base(self, *comps): |
| 111 return self._filesystem.join(self.webkit_base(), *comps) | 109 return self._filesystem.join(self._webkit_base(), *comps) |
| 112 | 110 |
| 113 def path_from_chromium_base(self, *comps): | 111 def path_from_chromium_base(self, *comps): |
| 114 return self._filesystem.join(self.chromium_base(), *comps) | 112 return self._filesystem.join(self.chromium_base(), *comps) |
| 115 | 113 |
| 116 def path_from_blink_source(self, *comps): | 114 def path_from_blink_source(self, *comps): |
| 117 return self._filesystem.join(self._filesystem.join(self.webkit_base(), ' Source'), *comps) | 115 return self._filesystem.join(self._filesystem.join(self._webkit_base(), 'Source'), *comps) |
| 118 | 116 |
| 119 def path_from_tools_scripts(self, *comps): | 117 def path_from_tools_scripts(self, *comps): |
| 120 return self._filesystem.join(self._filesystem.join(self.webkit_base(), ' Tools', 'Scripts'), *comps) | 118 return self._filesystem.join(self._filesystem.join(self._webkit_base(), 'Tools', 'Scripts'), *comps) |
| 121 | 119 |
| 122 def layout_tests_dir(self): | 120 def layout_tests_dir(self): |
| 123 return self._path_from_webkit_base('LayoutTests') | 121 return self._path_from_webkit_base('LayoutTests') |
| 124 | 122 |
| 125 def path_from_layout_tests(self, *comps): | 123 def path_from_layout_tests(self, *comps): |
| 126 return self._filesystem.join(self.layout_tests_dir(), *comps) | 124 return self._filesystem.join(self.layout_tests_dir(), *comps) |
| 127 | 125 |
| 128 def perf_tests_dir(self): | 126 def perf_tests_dir(self): |
| 129 return self._path_from_webkit_base('PerformanceTests') | 127 return self._path_from_webkit_base('PerformanceTests') |
| 130 | 128 |
| 131 def layout_test_name(self, file_path): | 129 def layout_test_name(self, file_path): |
| 132 """Returns a layout test name, given the path from the repo root. | 130 """Returns a layout test name, given the path from the repo root. |
| 133 | 131 |
| 134 Note: this appears to not work on Windows; see crbug.com/658795. | 132 Note: this appears to not work on Windows; see crbug.com/658795. |
| 135 Also, this function duplicates functionality that's in | 133 Also, this function duplicates functionality that's in |
| 136 Port.relative_test_filename. | 134 Port.relative_test_filename. |
| 137 TODO(qyearsley): De-duplicate this and Port.relative_test_filename, | 135 TODO(qyearsley): De-duplicate this and Port.relative_test_filename, |
| 138 and ensure that it works properly with Windows paths. | 136 and ensure that it works properly with Windows paths. |
| 139 | 137 |
| 140 Args: | 138 Args: |
| 141 file_path: A relative path from the root of the Chromium repo. | 139 file_path: A relative path from the root of the Chromium repo. |
| 142 | 140 |
| 143 Returns: | 141 Returns: |
| 144 The normalized layout test name, which is just the relative path fro m | 142 The normalized layout test name, which is just the relative path fro m |
| 145 the LayoutTests directory, using forward slash as the path separator . | 143 the LayoutTests directory, using forward slash as the path separator . |
| 146 Returns None if the given file is not in the LayoutTests directory. | 144 Returns None if the given file is not in the LayoutTests directory. |
| 147 """ | 145 """ |
| 148 layout_tests_abs_path = self._filesystem.join(self.webkit_base(), self.l ayout_tests_dir()) | 146 layout_tests_rel_path = self._filesystem.relpath(self.layout_tests_dir() , self.chromium_base()) |
| 149 layout_tests_rel_path = self._filesystem.relpath(layout_tests_abs_path, self.chromium_base()) | |
| 150 if not file_path.startswith(layout_tests_rel_path): | 147 if not file_path.startswith(layout_tests_rel_path): |
| 151 return None | 148 return None |
| 152 return file_path[len(layout_tests_rel_path) + 1:] | 149 return file_path[len(layout_tests_rel_path) + 1:] |
| 153 | 150 |
| 154 def depot_tools_base(self): | 151 def depot_tools_base(self): |
| 155 if not self._depot_tools: | 152 if not self._depot_tools: |
| 156 # This basically duplicates src/build/find_depot_tools.py without th e side effects | 153 # This basically duplicates src/build/find_depot_tools.py without th e side effects |
| 157 # (adding the directory to sys.path and importing breakpad). | 154 # (adding the directory to sys.path and importing breakpad). |
| 158 self._depot_tools = (self._check_paths_for_depot_tools(self._sys_pat h) or | 155 self._depot_tools = (self._check_paths_for_depot_tools(self._sys_pat h) or |
| 159 self._check_paths_for_depot_tools(self._env_pat h) or | 156 self._check_paths_for_depot_tools(self._env_pat h) or |
| 160 self._check_upward_for_depot_tools()) | 157 self._check_upward_for_depot_tools()) |
| 161 return self._depot_tools | 158 return self._depot_tools |
| 162 | 159 |
| 163 def _check_paths_for_depot_tools(self, paths): | 160 def _check_paths_for_depot_tools(self, paths): |
| 164 for path in paths: | 161 for path in paths: |
| 165 if path.rstrip(self._dirsep).endswith('depot_tools'): | 162 if path.rstrip(self._dirsep).endswith('depot_tools'): |
| 166 return path | 163 return path |
| 167 return None | 164 return None |
| 168 | 165 |
| 169 def _check_upward_for_depot_tools(self): | 166 def _check_upward_for_depot_tools(self): |
| 170 fs = self._filesystem | 167 fs = self._filesystem |
| 171 prev_dir = '' | 168 prev_dir = '' |
| 172 current_dir = fs.dirname(self._webkit_base) | 169 current_dir = fs.dirname(self._webkit_base()) |
| 173 while current_dir != prev_dir: | 170 while current_dir != prev_dir: |
| 174 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')): | 171 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')): |
| 175 return fs.join(current_dir, 'depot_tools') | 172 return fs.join(current_dir, 'depot_tools') |
| 176 prev_dir = current_dir | 173 prev_dir = current_dir |
| 177 current_dir = fs.dirname(current_dir) | 174 current_dir = fs.dirname(current_dir) |
| 178 | 175 |
| 179 def path_from_depot_tools_base(self, *comps): | 176 def path_from_depot_tools_base(self, *comps): |
| 180 return self._filesystem.join(self.depot_tools_base(), *comps) | 177 return self._filesystem.join(self.depot_tools_base(), *comps) |
| OLD | NEW |