OLD | NEW |
1 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Some utility methods for getting paths used by run_webkit_tests.py. | 5 """Some utility methods for getting paths used by run_webkit_tests.py. |
6 """ | 6 """ |
7 | 7 |
8 import errno | 8 import errno |
9 import os | 9 import os |
10 import platform_utils | 10 import platform_utils |
11 import subprocess | 11 import subprocess |
12 import sys | 12 import sys |
13 | 13 |
14 import google.path_utils | 14 import google.path_utils |
15 | 15 |
16 | 16 |
17 class PathNotFound(Exception): pass | 17 class PathNotFound(Exception): pass |
18 | 18 |
19 # Save some paths here so we don't keep re-evaling. | 19 # Save some paths here so we don't keep re-evaling. |
20 _webkit_root = None | 20 _webkit_root = None |
21 _layout_data_dir = None | 21 _layout_data_dir = None |
| 22 _layout_tests_dir = None |
22 # A map from platform description to directory list. | 23 # A map from platform description to directory list. |
23 _platform_results_dirs = {} | 24 _platform_results_dirs = {} |
24 | 25 |
25 # An instance of the PlatformUtility for use by methods mapped from there. | 26 # An instance of the PlatformUtility for use by methods mapped from there. |
26 _platform_util = None | 27 _platform_util = None |
27 | 28 |
28 # TODO this should probably be moved into path_utils as ToUnixPath(). | 29 # TODO this should probably be moved into path_utils as ToUnixPath(). |
29 def WinPathToUnix(path): | 30 def WinPathToUnix(path): |
30 """Convert a windows path to use unix-style path separators (a/b/c).""" | 31 """Convert a windows path to use unix-style path separators (a/b/c).""" |
31 return path.replace('\\', '/') | 32 return path.replace('\\', '/') |
(...skipping 12 matching lines...) Expand all Loading... |
44 def LayoutDataDir(): | 45 def LayoutDataDir(): |
45 """Gets the full path to the tests directory. Raises PathNotFound if | 46 """Gets the full path to the tests directory. Raises PathNotFound if |
46 we're unable to find it.""" | 47 we're unable to find it.""" |
47 global _layout_data_dir | 48 global _layout_data_dir |
48 if _layout_data_dir: | 49 if _layout_data_dir: |
49 return _layout_data_dir | 50 return _layout_data_dir |
50 _layout_data_dir = google.path_utils.FindUpward(WebKitRoot(), 'webkit', | 51 _layout_data_dir = google.path_utils.FindUpward(WebKitRoot(), 'webkit', |
51 'data', 'layout_tests') | 52 'data', 'layout_tests') |
52 return _layout_data_dir | 53 return _layout_data_dir |
53 | 54 |
| 55 def LayoutTestsDir(path = None): |
| 56 """Returns the full path to the directory containing layout tests, based on |
| 57 the supplied relative or absolute path to a layout tests. If the path contains |
| 58 "LayoutTests" directory, locates this directory, assuming it's either in |
| 59 in webkit/data/layout_tests or in third_party/WebKit.""" |
| 60 |
| 61 if path != None and path.find('LayoutTests') == -1: |
| 62 return LayoutDataDir() |
| 63 |
| 64 global _layout_tests_dir |
| 65 if _layout_tests_dir: |
| 66 return _layout_tests_dir |
| 67 |
| 68 if os.path.exists(os.path.join(LayoutDataDir(), 'LayoutTests')): |
| 69 _layout_tests_dir = LayoutDataDir() |
| 70 else: |
| 71 _layout_tests_dir = google.path_utils.FindUpward( |
| 72 google.path_utils.ScriptDir(), 'third_party', 'WebKit') |
| 73 |
| 74 return _layout_tests_dir |
| 75 |
54 def ChromiumPlatformResultsEnclosingDir(): | 76 def ChromiumPlatformResultsEnclosingDir(): |
55 """Returns the full path to the directory containing Chromium platform | 77 """Returns the full path to the directory containing Chromium platform |
56 result directories. | 78 result directories. |
57 """ | 79 """ |
58 # TODO(pamg): Once we move platform/chromium-* into LayoutTests/platform/, | 80 # TODO(pamg): Once we move platform/chromium-* into LayoutTests/platform/, |
59 # remove this and use PlatformResultsEnclosingDir() for everything. | 81 # remove this and use PlatformResultsEnclosingDir() for everything. |
60 return os.path.join(LayoutDataDir(), 'platform') | 82 return os.path.join(LayoutDataDir(), 'platform') |
61 | 83 |
62 def WebKitPlatformResultsEnclosingDir(): | 84 def WebKitPlatformResultsEnclosingDir(): |
63 """Gets the full path to just above the platform results directory.""" | 85 """Gets the full path to just above the platform results directory.""" |
64 return os.path.join(LayoutDataDir(), 'LayoutTests', 'platform') | 86 return os.path.join(LayoutTestsDir(), 'LayoutTests', 'platform') |
65 | 87 |
66 def PlatformResultsEnclosingDir(platform): | 88 def PlatformResultsEnclosingDir(platform): |
67 """Gets the path to just above the results directory for this platform.""" | 89 """Gets the path to just above the results directory for this platform.""" |
68 if platform.startswith('chromium'): | 90 if platform.startswith('chromium'): |
69 return ChromiumPlatformResultsEnclosingDir() | 91 return ChromiumPlatformResultsEnclosingDir() |
70 return WebKitPlatformResultsEnclosingDir() | 92 return WebKitPlatformResultsEnclosingDir() |
71 | 93 |
72 def ExpectedFilename(filename, suffix, platform): | 94 def ExpectedFilename(filename, suffix, platform): |
73 """Given a test name, returns an absolute path to its expected results. | 95 """Given a test name, returns an absolute path to its expected results. |
74 | 96 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if not os.path.exists(full_path): | 205 if not os.path.exists(full_path): |
184 # try output directory from either Xcode or chrome.sln | 206 # try output directory from either Xcode or chrome.sln |
185 full_path = platform_util.TestShellBinaryPath(target) | 207 full_path = platform_util.TestShellBinaryPath(target) |
186 if not os.path.exists(full_path): | 208 if not os.path.exists(full_path): |
187 raise PathNotFound('unable to find test_shell at %s' % full_path) | 209 raise PathNotFound('unable to find test_shell at %s' % full_path) |
188 return full_path | 210 return full_path |
189 | 211 |
190 def RelativeTestFilename(filename): | 212 def RelativeTestFilename(filename): |
191 """Provide the filename of the test relative to the layout data | 213 """Provide the filename of the test relative to the layout data |
192 directory as a unix style path (a/b/c).""" | 214 directory as a unix style path (a/b/c).""" |
193 return WinPathToUnix(filename[len(LayoutDataDir()) + 1:]) | 215 return WinPathToUnix(filename[len(LayoutTestsDir(filename)) + 1:]) |
194 | 216 |
195 def GetPlatformUtil(): | 217 def GetPlatformUtil(): |
196 """Returns a singleton instance of the PlatformUtility.""" | 218 """Returns a singleton instance of the PlatformUtility.""" |
197 global _platform_util | 219 global _platform_util |
198 if not _platform_util: | 220 if not _platform_util: |
199 # Avoid circular import by delaying it. | 221 # Avoid circular import by delaying it. |
200 import layout_package.platform_utils | 222 import layout_package.platform_utils |
201 _platform_util = ( | 223 _platform_util = ( |
202 layout_package.platform_utils.PlatformUtility(WebKitRoot())) | 224 layout_package.platform_utils.PlatformUtility(WebKitRoot())) |
203 return _platform_util | 225 return _platform_util |
204 | 226 |
205 # Map platform specific path utility functions. We do this as a convenience | 227 # Map platform specific path utility functions. We do this as a convenience |
206 # so importing path_utils will get all path related functions even if they are | 228 # so importing path_utils will get all path related functions even if they are |
207 # platform specific. | 229 # platform specific. |
208 def GetAbsolutePath(path): | 230 def GetAbsolutePath(path): |
209 return GetPlatformUtil().GetAbsolutePath(path) | 231 return GetPlatformUtil().GetAbsolutePath(path) |
210 | 232 |
211 def FilenameToUri(path): | 233 def FilenameToUri(path): |
212 return GetPlatformUtil().FilenameToUri(path) | 234 return GetPlatformUtil().FilenameToUri(path) |
213 | 235 |
214 def TestListPlatformDir(): | 236 def TestListPlatformDir(): |
215 return GetPlatformUtil().TestListPlatformDir() | 237 return GetPlatformUtil().TestListPlatformDir() |
216 | 238 |
217 def PlatformDir(): | 239 def PlatformDir(): |
218 return GetPlatformUtil().PlatformDir() | 240 return GetPlatformUtil().PlatformDir() |
219 | 241 |
220 def PlatformNewResultsDir(): | 242 def PlatformNewResultsDir(): |
221 return GetPlatformUtil().PlatformNewResultsDir() | 243 return GetPlatformUtil().PlatformNewResultsDir() |
OLD | NEW |