Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/blink_finder.py

Issue 2496063002: Rename WebKitFinder -> BlinkFinder. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/common/blink_finder_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # 2 # Use of this source code is governed by a BSD-style license that can be
3 # Redistribution and use in source and binary forms, with or without 3 # found in the LICENSE file.
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 4
29 import os 5 import os
30 import sys 6 import sys
31 7
32 8
33 class WebKitFinder(object): 9 class BlinkFinder(object):
34 10
35 def __init__(self, filesystem): 11 def __init__(self, filesystem):
36 self._filesystem = filesystem 12 self._filesystem = filesystem
37 self._dirsep = filesystem.sep 13 self._dirsep = filesystem.sep
38 self._sys_path = sys.path 14 self._sys_path = sys.path
39 self._env_path = os.environ['PATH'].split(os.pathsep) 15 self._env_path = os.environ['PATH'].split(os.pathsep)
40 self._webkit_base = None 16 self._blink_base = None
41 self._chromium_base = None 17 self._chromium_base = None
42 self._depot_tools = None 18 self._depot_tools = None
43 19
44 def webkit_base(self): 20 def blink_base(self):
45 """Returns the absolute path to the top of the WebKit tree. 21 """Returns the absolute path to the Blink base directory.
46 22
47 Raises an AssertionError if the top dir can't be determined. 23 Raises an AssertionError if it can't be determined.
48 """ 24 """
49 # Note: This code somewhat duplicates the code in 25 # TODO(qyearsley): Consider changing the way that this and chromium_base
50 # scm.find_checkout_root(). However, that code only works if the top 26 # are done, if it can be simplified or made more robust now that blink i s
51 # of the SCM repository also matches the top of the WebKit tree. Some SV N users 27 # merged into the chromium repo. Also consider using the memoized decora tor.
52 # (the chromium test bots, for example), might only check out subdirecto ries like 28 if not self._blink_base:
53 # Tools/Scripts. This code will also work if there is no SCM system at a ll. 29 self._blink_base = self._blink_base
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__)) 30 module_path = self._filesystem.abspath(self._filesystem.path_to_modu le(self.__module__))
60 tools_index = module_path.rfind('Tools') 31 tools_index = module_path.rfind('Tools')
61 assert tools_index != -1, "could not find location of this checkout from %s" % module_path 32 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]) 33 self._blink_base = self._filesystem.normpath(module_path[0:tools_ind ex - 1])
63 return self._webkit_base 34 return self._blink_base
64 35
65 def chromium_base(self): 36 def chromium_base(self):
66 if not self._chromium_base: 37 if not self._chromium_base:
67 self._chromium_base = self._filesystem.dirname(self._filesystem.dirn ame(self.webkit_base())) 38 self._chromium_base = self._filesystem.dirname(self._filesystem.dirn ame(self.blink_base()))
68 return self._chromium_base 39 return self._chromium_base
69 40
70 def path_from_webkit_base(self, *comps): 41 def path_from_blink_base(self, *comps):
71 return self._filesystem.join(self.webkit_base(), *comps) 42 return self._filesystem.join(self.blink_base(), *comps)
72 43
73 def path_from_chromium_base(self, *comps): 44 def path_from_chromium_base(self, *comps):
74 return self._filesystem.join(self.chromium_base(), *comps) 45 return self._filesystem.join(self.chromium_base(), *comps)
75 46
76 def path_to_script(self, script_name): 47 def path_to_script(self, script_name):
77 """Returns the relative path to the script from the top of the WebKit tr ee.""" 48 """Returns the relative path to the script from the Blink base directory ."""
78 # This is intentionally relative in order to force callers to consider w hat 49 # 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). 50 # their current working directory is (and change to the top of the tree if necessary).
80 return self._filesystem.join("Tools", "Scripts", script_name) 51 return self._filesystem.join("Tools", "Scripts", script_name)
81 52
82 def layout_tests_dir(self): 53 def layout_tests_dir(self):
83 return self.path_from_webkit_base('LayoutTests') 54 return self.path_from_blink_base('LayoutTests')
84 55
85 def perf_tests_dir(self): 56 def perf_tests_dir(self):
86 return self.path_from_webkit_base('PerformanceTests') 57 return self.path_from_blink_base('PerformanceTests')
87 58
88 def layout_test_name(self, file_path): 59 def layout_test_name(self, file_path):
89 """Returns a layout test name, given the path from the repo root. 60 """Returns a layout test name, given the path from the repo root.
90 61
91 Note: this appears to not work on Windows; see crbug.com/658795. 62 Note: this appears to not work on Windows; see crbug.com/658795.
92 Also, this function duplicates functionality that's in 63 Also, this function duplicates functionality that's in
93 Port.relative_test_filename. 64 Port.relative_test_filename.
65
94 TODO(qyearsley): De-duplicate this and Port.relative_test_filename, 66 TODO(qyearsley): De-duplicate this and Port.relative_test_filename,
95 and ensure that it works properly with Windows paths. 67 and ensure that it works properly with Windows paths.
96 68
97 Args: 69 Args:
98 file_path: A relative path from the root of the Chromium repo. 70 file_path: A relative path from the root of the Chromium repo.
99 71
100 Returns: 72 Returns:
101 The normalized layout test name, which is just the relative path fro m 73 The normalized layout test name, which is just the relative path fro m
102 the LayoutTests directory, using forward slash as the path separator . 74 the LayoutTests directory, using forward slash as the path separator .
103 Returns None if the given file is not in the LayoutTests directory. 75 Returns None if the given file is not in the LayoutTests directory.
104 """ 76 """
105 layout_tests_abs_path = self._filesystem.join(self.webkit_base(), self.l ayout_tests_dir()) 77 layout_tests_abs_path = self._filesystem.join(self.blink_base(), self.la yout_tests_dir())
106 layout_tests_rel_path = self._filesystem.relpath(layout_tests_abs_path, self.chromium_base()) 78 layout_tests_rel_path = self._filesystem.relpath(layout_tests_abs_path, self.chromium_base())
107 if not file_path.startswith(layout_tests_rel_path): 79 if not file_path.startswith(layout_tests_rel_path):
108 return None 80 return None
109 return file_path[len(layout_tests_rel_path) + 1:] 81 return file_path[len(layout_tests_rel_path) + 1:]
110 82
111 def depot_tools_base(self): 83 def depot_tools_base(self):
112 if not self._depot_tools: 84 if not self._depot_tools:
113 # This basically duplicates src/build/find_depot_tools.py without th e side effects 85 # This basically duplicates src/build/find_depot_tools.py without th e side effects
114 # (adding the directory to sys.path and importing breakpad). 86 # (adding the directory to sys.path and importing breakpad).
115 self._depot_tools = (self._check_paths_for_depot_tools(self._sys_pat h) or 87 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 88 self._check_paths_for_depot_tools(self._env_pat h) or
117 self._check_upward_for_depot_tools()) 89 self._check_upward_for_depot_tools())
118 return self._depot_tools 90 return self._depot_tools
119 91
120 def _check_paths_for_depot_tools(self, paths): 92 def _check_paths_for_depot_tools(self, paths):
121 for path in paths: 93 for path in paths:
122 if path.rstrip(self._dirsep).endswith('depot_tools'): 94 if path.rstrip(self._dirsep).endswith('depot_tools'):
123 return path 95 return path
124 return None 96 return None
125 97
126 def _check_upward_for_depot_tools(self): 98 def _check_upward_for_depot_tools(self):
127 fs = self._filesystem 99 fs = self._filesystem
128 prev_dir = '' 100 prev_dir = ''
129 current_dir = fs.dirname(self._webkit_base) 101 current_dir = fs.dirname(self._blink_base)
130 while current_dir != prev_dir: 102 while current_dir != prev_dir:
131 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')): 103 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')):
132 return fs.join(current_dir, 'depot_tools') 104 return fs.join(current_dir, 'depot_tools')
133 prev_dir = current_dir 105 prev_dir = current_dir
134 current_dir = fs.dirname(current_dir) 106 current_dir = fs.dirname(current_dir)
135 107
136 def path_from_depot_tools_base(self, *comps): 108 def path_from_depot_tools_base(self, *comps):
137 return self._filesystem.join(self.depot_tools_base(), *comps) 109 return self._filesystem.join(self.depot_tools_base(), *comps)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/common/blink_finder_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698