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

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

Issue 2865403006: webkitpy: Memoize chromium_base() and depot_tools_base(). (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | 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 (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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return os.path.join(get_scripts_dir(), 'webkitpy', 'thirdparty') 73 return os.path.join(get_scripts_dir(), 'webkitpy', 'thirdparty')
74 74
75 75
76 class WebKitFinder(object): 76 class WebKitFinder(object):
77 77
78 def __init__(self, filesystem): 78 def __init__(self, filesystem):
79 self._filesystem = filesystem 79 self._filesystem = filesystem
80 self._dirsep = filesystem.sep 80 self._dirsep = filesystem.sep
81 self._sys_path = sys.path 81 self._sys_path = sys.path
82 self._env_path = os.environ['PATH'].split(os.pathsep) 82 self._env_path = os.environ['PATH'].split(os.pathsep)
83 self._chromium_base = None
84 self._depot_tools = None
85 83
86 @memoized 84 @memoized
87 def _webkit_base(self): 85 def _webkit_base(self):
88 """Returns the absolute path to the top of the WebKit tree. 86 """Returns the absolute path to the top of the WebKit tree.
89 87
90 Raises an AssertionError if the top dir can't be determined. 88 Raises an AssertionError if the top dir can't be determined.
91 """ 89 """
92 # TODO(qyearsley): This code somewhat duplicates the code in 90 # TODO(qyearsley): This code somewhat duplicates the code in
93 # git.find_checkout_root(). 91 # git.find_checkout_root().
94 module_path = self._filesystem.abspath(self._filesystem.path_to_module(s elf.__module__)) 92 module_path = self._filesystem.abspath(self._filesystem.path_to_module(s elf.__module__))
95 tools_index = module_path.rfind('Tools') 93 tools_index = module_path.rfind('Tools')
96 assert tools_index != -1, 'could not find location of this checkout from %s' % module_path 94 assert tools_index != -1, 'could not find location of this checkout from %s' % module_path
97 return self._filesystem.normpath(module_path[0:tools_index - 1]) 95 return self._filesystem.normpath(module_path[0:tools_index - 1])
98 96
97 @memoized
99 def chromium_base(self): 98 def chromium_base(self):
100 if not self._chromium_base: 99 return self._filesystem.dirname(self._filesystem.dirname(self._webkit_ba se()))
101 self._chromium_base = self._filesystem.dirname(self._filesystem.dirn ame(self._webkit_base()))
102 return self._chromium_base
103 100
104 # Do not expose this function in order to make the code robust against 101 # Do not expose this function in order to make the code robust against
105 # directory structure changes. 102 # directory structure changes.
106 def _path_from_webkit_base(self, *comps): 103 def _path_from_webkit_base(self, *comps):
107 return self._filesystem.join(self._webkit_base(), *comps) 104 return self._filesystem.join(self._webkit_base(), *comps)
108 105
109 def path_from_chromium_base(self, *comps): 106 def path_from_chromium_base(self, *comps):
110 return self._filesystem.join(self.chromium_base(), *comps) 107 return self._filesystem.join(self.chromium_base(), *comps)
111 108
112 def path_from_blink_source(self, *comps): 109 def path_from_blink_source(self, *comps):
(...skipping 26 matching lines...) Expand all
139 Returns: 136 Returns:
140 The normalized layout test name, which is just the relative path fro m 137 The normalized layout test name, which is just the relative path fro m
141 the LayoutTests directory, using forward slash as the path separator . 138 the LayoutTests directory, using forward slash as the path separator .
142 Returns None if the given file is not in the LayoutTests directory. 139 Returns None if the given file is not in the LayoutTests directory.
143 """ 140 """
144 layout_tests_rel_path = self._filesystem.relpath(self.layout_tests_dir() , self.chromium_base()) 141 layout_tests_rel_path = self._filesystem.relpath(self.layout_tests_dir() , self.chromium_base())
145 if not file_path.startswith(layout_tests_rel_path): 142 if not file_path.startswith(layout_tests_rel_path):
146 return None 143 return None
147 return file_path[len(layout_tests_rel_path) + 1:] 144 return file_path[len(layout_tests_rel_path) + 1:]
148 145
146 @memoized
149 def depot_tools_base(self): 147 def depot_tools_base(self):
150 if not self._depot_tools: 148 # This basically duplicates src/build/find_depot_tools.py without the si de effects
151 # This basically duplicates src/build/find_depot_tools.py without th e side effects 149 # (adding the directory to sys.path and importing breakpad).
152 # (adding the directory to sys.path and importing breakpad). 150 return (self._check_paths_for_depot_tools(self._sys_path) or
153 self._depot_tools = (self._check_paths_for_depot_tools(self._sys_pat h) or 151 self._check_paths_for_depot_tools(self._env_path) or
154 self._check_paths_for_depot_tools(self._env_pat h) or 152 self._check_upward_for_depot_tools())
155 self._check_upward_for_depot_tools())
156 return self._depot_tools
157 153
158 def _check_paths_for_depot_tools(self, paths): 154 def _check_paths_for_depot_tools(self, paths):
159 for path in paths: 155 for path in paths:
160 if path.rstrip(self._dirsep).endswith('depot_tools'): 156 if path.rstrip(self._dirsep).endswith('depot_tools'):
161 return path 157 return path
162 return None 158 return None
163 159
164 def _check_upward_for_depot_tools(self): 160 def _check_upward_for_depot_tools(self):
165 fs = self._filesystem 161 fs = self._filesystem
166 prev_dir = '' 162 prev_dir = ''
167 current_dir = fs.dirname(self._webkit_base()) 163 current_dir = fs.dirname(self._webkit_base())
168 while current_dir != prev_dir: 164 while current_dir != prev_dir:
169 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')): 165 if fs.exists(fs.join(current_dir, 'depot_tools', 'pylint.py')):
170 return fs.join(current_dir, 'depot_tools') 166 return fs.join(current_dir, 'depot_tools')
171 prev_dir = current_dir 167 prev_dir = current_dir
172 current_dir = fs.dirname(current_dir) 168 current_dir = fs.dirname(current_dir)
173 169
174 def path_from_depot_tools_base(self, *comps): 170 def path_from_depot_tools_base(self, *comps):
175 return self._filesystem.join(self.depot_tools_base(), *comps) 171 return self._filesystem.join(self.depot_tools_base(), *comps)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698