| 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 | |
| 33 class WebKitFinder(object): | |
| 34 | |
| 35 def __init__(self, filesystem): | |
| 36 self._filesystem = filesystem | |
| 37 self._dirsep = filesystem.sep | |
| 38 self._sys_path = sys.path | |
| 39 self._env_path = os.environ['PATH'].split(os.pathsep) | |
| 40 self._webkit_base = None | |
| 41 self._chromium_base = None | |
| 42 self._depot_tools = None | |
| 43 | |
| 44 def webkit_base(self): | |
| 45 """Returns the absolute path to the top of the WebKit tree. | |
| 46 | |
| 47 Raises an AssertionError if the top dir can't be determined. | |
| 48 """ | |
| 49 # Note: This code somewhat duplicates the code in | |
| 50 # scm.find_checkout_root(). However, that code only works if the top | |
| 51 # of the SCM repository also matches the top of the WebKit tree. Some SV
N users | |
| 52 # (the chromium test bots, for example), might only check out subdirecto
ries like | |
| 53 # Tools/Scripts. This code will also work if there is no SCM system at a
ll. | |
| 54 # TODO(qyearsley): Remove duplicate code; we're not concerned with SVN u
sers anymore. | |
| 55 # Also, instead of caching the result with a private instance variable,
we can use | |
| 56 # the memoized decorator. | |
| 57 if not self._webkit_base: | |
| 58 self._webkit_base = self._webkit_base | |
| 59 module_path = self._filesystem.abspath(self._filesystem.path_to_modu
le(self.__module__)) | |
| 60 tools_index = module_path.rfind('Tools') | |
| 61 assert tools_index != -1, "could not find location of this checkout
from %s" % module_path | |
| 62 self._webkit_base = self._filesystem.normpath(module_path[0:tools_in
dex - 1]) | |
| 63 return self._webkit_base | |
| 64 | |
| 65 def chromium_base(self): | |
| 66 if not self._chromium_base: | |
| 67 self._chromium_base = self._filesystem.dirname(self._filesystem.dirn
ame(self.webkit_base())) | |
| 68 return self._chromium_base | |
| 69 | |
| 70 def path_from_webkit_base(self, *comps): | |
| 71 return self._filesystem.join(self.webkit_base(), *comps) | |
| 72 | |
| 73 def path_from_chromium_base(self, *comps): | |
| 74 return self._filesystem.join(self.chromium_base(), *comps) | |
| 75 | |
| 76 def path_to_script(self, script_name): | |
| 77 """Returns the relative path to the script from the top of the WebKit tr
ee.""" | |
| 78 # This is intentionally relative in order to force callers to consider w
hat | |
| 79 # their current working directory is (and change to the top of the tree
if necessary). | |
| 80 return self._filesystem.join("Tools", "Scripts", script_name) | |
| 81 | |
| 82 def layout_tests_dir(self): | |
| 83 return self.path_from_webkit_base('LayoutTests') | |
| 84 | |
| 85 def perf_tests_dir(self): | |
| 86 return self.path_from_webkit_base('PerformanceTests') | |
| 87 | |
| 88 def layout_test_name(self, file_path): | |
| 89 """Returns a layout test name, given the path from the repo root. | |
| 90 | |
| 91 Note: this appears to not work on Windows; see crbug.com/658795. | |
| 92 Also, this function duplicates functionality that's in | |
| 93 Port.relative_test_filename. | |
| 94 TODO(qyearsley): De-duplicate this and Port.relative_test_filename, | |
| 95 and ensure that it works properly with Windows paths. | |
| 96 | |
| 97 Args: | |
| 98 file_path: A relative path from the root of the Chromium repo. | |
| 99 | |
| 100 Returns: | |
| 101 The normalized layout test name, which is just the relative path fro
m | |
| 102 the LayoutTests directory, using forward slash as the path separator
. | |
| 103 Returns None if the given file is not in the LayoutTests directory. | |
| 104 """ | |
| 105 layout_tests_abs_path = self._filesystem.join(self.webkit_base(), self.l
ayout_tests_dir()) | |
| 106 layout_tests_rel_path = self._filesystem.relpath(layout_tests_abs_path,
self.chromium_base()) | |
| 107 if not file_path.startswith(layout_tests_rel_path): | |
| 108 return None | |
| 109 return file_path[len(layout_tests_rel_path) + 1:] | |
| 110 | |
| 111 def depot_tools_base(self): | |
| 112 if not self._depot_tools: | |
| 113 # This basically duplicates src/build/find_depot_tools.py without th
e side effects | |
| 114 # (adding the directory to sys.path and importing breakpad). | |
| 115 self._depot_tools = (self._check_paths_for_depot_tools(self._sys_pat
h) or | |
| 116 self._check_paths_for_depot_tools(self._env_pat
h) or | |
| 117 self._check_upward_for_depot_tools()) | |
| 118 return self._depot_tools | |
| 119 | |
| 120 def _check_paths_for_depot_tools(self, paths): | |
| 121 for path in paths: | |
| 122 if path.rstrip(self._dirsep).endswith('depot_tools'): | |
| 123 return path | |
| 124 return None | |
| 125 | |
| 126 def _check_upward_for_depot_tools(self): | |
| 127 fs = self._filesystem | |
| 128 prev_dir = '' | |
| 129 current_dir = fs.dirname(self._webkit_base) | |
| 130 while current_dir != prev_dir: | |
| 131 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')): | |
| 132 return fs.join(current_dir, 'depot_tools') | |
| 133 prev_dir = current_dir | |
| 134 current_dir = fs.dirname(current_dir) | |
| 135 | |
| 136 def path_from_depot_tools_base(self, *comps): | |
| 137 return self._filesystem.join(self.depot_tools_base(), *comps) | |
| OLD | NEW |