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

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

Issue 2831883002: webkitpy: Reduce usage of path_from_webkit_base(). (Closed)
Patch Set: . Created 3 years, 8 months 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
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 def __init__(self, filesystem): 76 def __init__(self, filesystem):
77 self._filesystem = filesystem 77 self._filesystem = filesystem
78 self._dirsep = filesystem.sep 78 self._dirsep = filesystem.sep
79 self._sys_path = sys.path 79 self._sys_path = sys.path
80 self._env_path = os.environ['PATH'].split(os.pathsep) 80 self._env_path = os.environ['PATH'].split(os.pathsep)
81 self._webkit_base = None 81 self._webkit_base = None
82 self._chromium_base = None 82 self._chromium_base = None
83 self._depot_tools = None 83 self._depot_tools = None
84 84
85 # TODO(tkent): Make this private. We should use functions for
86 # sub-directories in order to make the code robust against directory
87 # structure changes.
85 def webkit_base(self): 88 def webkit_base(self):
86 """Returns the absolute path to the top of the WebKit tree. 89 """Returns the absolute path to the top of the WebKit tree.
87 90
88 Raises an AssertionError if the top dir can't be determined. 91 Raises an AssertionError if the top dir can't be determined.
89 """ 92 """
90 # TODO(qyearsley): This code somewhat duplicates the code in 93 # TODO(qyearsley): This code somewhat duplicates the code in
91 # git.find_checkout_root(). 94 # git.find_checkout_root().
92 if not self._webkit_base: 95 if not self._webkit_base:
93 self._webkit_base = self._webkit_base 96 self._webkit_base = self._webkit_base
94 module_path = self._filesystem.abspath(self._filesystem.path_to_modu le(self.__module__)) 97 module_path = self._filesystem.abspath(self._filesystem.path_to_modu le(self.__module__))
95 tools_index = module_path.rfind('Tools') 98 tools_index = module_path.rfind('Tools')
96 assert tools_index != -1, 'could not find location of this checkout from %s' % module_path 99 assert tools_index != -1, 'could not find location of this checkout from %s' % module_path
97 self._webkit_base = self._filesystem.normpath(module_path[0:tools_in dex - 1]) 100 self._webkit_base = self._filesystem.normpath(module_path[0:tools_in dex - 1])
98 return self._webkit_base 101 return self._webkit_base
99 102
100 def chromium_base(self): 103 def chromium_base(self):
101 if not self._chromium_base: 104 if not self._chromium_base:
102 self._chromium_base = self._filesystem.dirname(self._filesystem.dirn ame(self.webkit_base())) 105 self._chromium_base = self._filesystem.dirname(self._filesystem.dirn ame(self.webkit_base()))
103 return self._chromium_base 106 return self._chromium_base
104 107
108 # TODO(tkent): Make this private. We should use functions for
109 # sub-directories in order to make the code robust against directory
110 # structure changes.
105 def path_from_webkit_base(self, *comps): 111 def path_from_webkit_base(self, *comps):
106 return self._filesystem.join(self.webkit_base(), *comps) 112 return self._filesystem.join(self.webkit_base(), *comps)
107 113
108 def path_from_chromium_base(self, *comps): 114 def path_from_chromium_base(self, *comps):
109 return self._filesystem.join(self.chromium_base(), *comps) 115 return self._filesystem.join(self.chromium_base(), *comps)
110 116
117 def path_from_blink_source(self, *comps):
qyearsley 2017/04/20 23:25:22 Later on, after the move, this will just be //web,
118 return self._filesystem.join(self._filesystem.join(self.webkit_base(), ' Source'), *comps)
119
111 def path_to_script(self, script_name): 120 def path_to_script(self, script_name):
112 """Returns the relative path to the script from the top of the WebKit tr ee.""" 121 """Returns the relative path to the script from the top of the WebKit tr ee."""
113 # This is intentionally relative in order to force callers to consider w hat 122 # This is intentionally relative in order to force callers to consider w hat
114 # their current working directory is (and change to the top of the tree if necessary). 123 # their current working directory is (and change to the top of the tree if necessary).
115 return self._filesystem.join('Tools', 'Scripts', script_name) 124 return self._filesystem.join('Tools', 'Scripts', script_name)
116 125
126 def path_from_tools_scripts(self, *comps):
127 return self._filesystem.join(self._filesystem.join(self.webkit_base(), ' Tools', 'Scripts'), *comps)
qyearsley 2017/04/20 23:25:22 I suppose later this will be be called path_from_t
128
117 def layout_tests_dir(self): 129 def layout_tests_dir(self):
118 return self.path_from_webkit_base('LayoutTests') 130 return self.path_from_webkit_base('LayoutTests')
119 131
132 def path_from_layout_tests(self, *comps):
133 return self._filesystem.join(self.layout_tests_dir(), *comps)
134
120 def perf_tests_dir(self): 135 def perf_tests_dir(self):
121 return self.path_from_webkit_base('PerformanceTests') 136 return self.path_from_webkit_base('PerformanceTests')
122 137
123 def layout_test_name(self, file_path): 138 def layout_test_name(self, file_path):
124 """Returns a layout test name, given the path from the repo root. 139 """Returns a layout test name, given the path from the repo root.
125 140
126 Note: this appears to not work on Windows; see crbug.com/658795. 141 Note: this appears to not work on Windows; see crbug.com/658795.
127 Also, this function duplicates functionality that's in 142 Also, this function duplicates functionality that's in
128 Port.relative_test_filename. 143 Port.relative_test_filename.
129 TODO(qyearsley): De-duplicate this and Port.relative_test_filename, 144 TODO(qyearsley): De-duplicate this and Port.relative_test_filename,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 prev_dir = '' 178 prev_dir = ''
164 current_dir = fs.dirname(self._webkit_base) 179 current_dir = fs.dirname(self._webkit_base)
165 while current_dir != prev_dir: 180 while current_dir != prev_dir:
166 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')): 181 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')):
167 return fs.join(current_dir, 'depot_tools') 182 return fs.join(current_dir, 'depot_tools')
168 prev_dir = current_dir 183 prev_dir = current_dir
169 current_dir = fs.dirname(current_dir) 184 current_dir = fs.dirname(current_dir)
170 185
171 def path_from_depot_tools_base(self, *comps): 186 def path_from_depot_tools_base(self, *comps):
172 return self._filesystem.join(self.depot_tools_base(), *comps) 187 return self._filesystem.join(self.depot_tools_base(), *comps)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698