OLD | NEW |
1 # Copyright (C) 2011, Google Inc. All rights reserved. | 1 # Copyright (C) 2011, 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 30 matching lines...) Expand all Loading... |
41 if inverted_dictionary.get(value): | 41 if inverted_dictionary.get(value): |
42 inverted_dictionary[value].append(key) | 42 inverted_dictionary[value].append(key) |
43 else: | 43 else: |
44 inverted_dictionary[value] = [key] | 44 inverted_dictionary[value] = [key] |
45 return inverted_dictionary | 45 return inverted_dictionary |
46 | 46 |
47 | 47 |
48 class BaselineOptimizer(object): | 48 class BaselineOptimizer(object): |
49 ROOT_LAYOUT_TESTS_DIRECTORY = 'LayoutTests' | 49 ROOT_LAYOUT_TESTS_DIRECTORY = 'LayoutTests' |
50 | 50 |
51 def __init__(self, host, port_names): | 51 def __init__(self, host, port_names, skip_scm_commands): |
52 self._filesystem = host.filesystem | 52 self._filesystem = host.filesystem |
53 self._port_factory = host.port_factory | 53 self._port_factory = host.port_factory |
| 54 self._skip_scm_commands = skip_scm_commands |
| 55 self._files_to_delete = [] |
| 56 self._files_to_add = [] |
54 self._scm = host.scm() | 57 self._scm = host.scm() |
55 self._port_names = port_names | 58 self._port_names = port_names |
56 # Only used by unittests. | 59 # Only used by unittests. |
57 self.new_results_by_directory = [] | 60 self.new_results_by_directory = [] |
58 | 61 |
59 def _baseline_root(self, port, baseline_name): | 62 def _baseline_root(self, port, baseline_name): |
60 virtual_suite = port.lookup_virtual_suite(baseline_name) | 63 virtual_suite = port.lookup_virtual_suite(baseline_name) |
61 if virtual_suite: | 64 if virtual_suite: |
62 return self._filesystem.join(self.ROOT_LAYOUT_TESTS_DIRECTORY, virtu
al_suite.name) | 65 return self._filesystem.join(self.ROOT_LAYOUT_TESTS_DIRECTORY, virtu
al_suite.name) |
63 return self.ROOT_LAYOUT_TESTS_DIRECTORY | 66 return self.ROOT_LAYOUT_TESTS_DIRECTORY |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if self._scm.exists(file_name): | 220 if self._scm.exists(file_name): |
218 scm_files.append(file_name) | 221 scm_files.append(file_name) |
219 else: | 222 else: |
220 fs_files.append(file_name) | 223 fs_files.append(file_name) |
221 | 224 |
222 if scm_files or fs_files: | 225 if scm_files or fs_files: |
223 if scm_files: | 226 if scm_files: |
224 _log.debug(" Deleting (SCM):") | 227 _log.debug(" Deleting (SCM):") |
225 for platform_dir in sorted(self._platform(filename) for filename
in scm_files): | 228 for platform_dir in sorted(self._platform(filename) for filename
in scm_files): |
226 _log.debug(" " + platform_dir) | 229 _log.debug(" " + platform_dir) |
227 self._scm.delete_list(scm_files) | 230 if self._skip_scm_commands: |
| 231 self._files_to_delete.extend(scm_files) |
| 232 else: |
| 233 self._scm.delete_list(scm_files) |
228 if fs_files: | 234 if fs_files: |
229 _log.debug(" Deleting (file system):") | 235 _log.debug(" Deleting (file system):") |
230 for platform_dir in sorted(self._platform(filename) for filename
in fs_files): | 236 for platform_dir in sorted(self._platform(filename) for filename
in fs_files): |
231 _log.debug(" " + platform_dir) | 237 _log.debug(" " + platform_dir) |
232 for filename in fs_files: | 238 for filename in fs_files: |
233 self._filesystem.remove(filename) | 239 self._filesystem.remove(filename) |
234 else: | 240 else: |
235 _log.debug(" (Nothing to delete)") | 241 _log.debug(" (Nothing to delete)") |
236 | 242 |
237 file_names = [] | 243 file_names = [] |
238 for directory, result in new_results_by_directory.items(): | 244 for directory, result in new_results_by_directory.items(): |
239 if results_by_directory.get(directory) != result: | 245 if results_by_directory.get(directory) != result: |
240 destination = self._join_directory(directory, baseline_name) | 246 destination = self._join_directory(directory, baseline_name) |
241 self._filesystem.maybe_make_directory(self._filesystem.split(des
tination)[0]) | 247 self._filesystem.maybe_make_directory(self._filesystem.split(des
tination)[0]) |
242 self._filesystem.write_binary_file(destination, data_for_result[
result]) | 248 self._filesystem.write_binary_file(destination, data_for_result[
result]) |
243 file_names.append(destination) | 249 file_names.append(destination) |
244 | 250 |
245 if file_names: | 251 if file_names: |
246 _log.debug(" Adding:") | 252 _log.debug(" Adding:") |
247 for platform_dir in sorted(self._platform(filename) for filename in
file_names): | 253 for platform_dir in sorted(self._platform(filename) for filename in
file_names): |
248 _log.debug(" " + platform_dir) | 254 _log.debug(" " + platform_dir) |
249 self._scm.add_list(file_names) | 255 if self._skip_scm_commands: |
| 256 # Have adds win over deletes. |
| 257 self._files_to_delete = list(set(self._files_to_delete) - set(fi
le_names)) |
| 258 self._files_to_add.extend(file_names) |
| 259 else: |
| 260 self._scm.add_list(file_names) |
250 else: | 261 else: |
251 _log.debug(" (Nothing to add)") | 262 _log.debug(" (Nothing to add)") |
252 | 263 |
253 def write_by_directory(self, results_by_directory, writer, indent): | 264 def write_by_directory(self, results_by_directory, writer, indent): |
254 for path in sorted(results_by_directory): | 265 for path in sorted(results_by_directory): |
255 writer("%s%s: %s" % (indent, self._platform(path), results_by_direct
ory[path][0:6])) | 266 writer("%s%s: %s" % (indent, self._platform(path), results_by_direct
ory[path][0:6])) |
256 | 267 |
257 def _optimize_subtree(self, baseline_name): | 268 def _optimize_subtree(self, baseline_name): |
258 basename = self._filesystem.basename(baseline_name) | 269 basename = self._filesystem.basename(baseline_name) |
259 results_by_directory, new_results_by_directory = self._find_optimal_resu
lt_placement(baseline_name) | 270 results_by_directory, new_results_by_directory = self._find_optimal_resu
lt_placement(baseline_name) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 for port_name in self._port_names: | 307 for port_name in self._port_names: |
297 directories = self._relative_baseline_search_paths(port_name, non_vi
rtual_baseline_name) | 308 directories = self._relative_baseline_search_paths(port_name, non_vi
rtual_baseline_name) |
298 for directory in directories: | 309 for directory in directories: |
299 if directory not in results_by_directory: | 310 if directory not in results_by_directory: |
300 continue | 311 continue |
301 if results_by_directory[directory] != root_sha1: | 312 if results_by_directory[directory] != root_sha1: |
302 return | 313 return |
303 break | 314 break |
304 | 315 |
305 _log.debug("Deleting redundant virtual root expected result.") | 316 _log.debug("Deleting redundant virtual root expected result.") |
306 self._scm.delete(virtual_root_expected_baseline_path) | 317 if self._skip_scm_commands: |
| 318 self._files_to_delete.append(virtual_root_expected_baseline_path) |
| 319 else: |
| 320 self._scm.delete(virtual_root_expected_baseline_path) |
307 | 321 |
308 def optimize(self, baseline_name): | 322 def optimize(self, baseline_name): |
309 # The virtual fallback path is the same as the non-virtual one tacked on
to the bottom of the non-virtual path. | 323 # The virtual fallback path is the same as the non-virtual one tacked on
to the bottom of the non-virtual path. |
310 # See https://docs.google.com/a/chromium.org/drawings/d/1eGdsIKzJ2dxDDBb
UaIABrN4aMLD1bqJTfyxNGZsTdmg/edit for | 324 # See https://docs.google.com/a/chromium.org/drawings/d/1eGdsIKzJ2dxDDBb
UaIABrN4aMLD1bqJTfyxNGZsTdmg/edit for |
311 # a visual representation of this. | 325 # a visual representation of this. |
312 # | 326 # |
313 # So, we can optimize the virtual path, then the virtual root and then t
he regular path. | 327 # So, we can optimize the virtual path, then the virtual root and then t
he regular path. |
314 | 328 |
315 _log.debug("Optimizing regular fallback path.") | 329 _log.debug("Optimizing regular fallback path.") |
316 result = self._optimize_subtree(baseline_name) | 330 result = self._optimize_subtree(baseline_name) |
317 non_virtual_baseline_name = self._port_factory.get().lookup_virtual_test
_base(baseline_name) | 331 non_virtual_baseline_name = self._port_factory.get().lookup_virtual_test
_base(baseline_name) |
318 if not non_virtual_baseline_name: | 332 if not non_virtual_baseline_name: |
319 return result | 333 return result, self._files_to_delete, self._files_to_add |
320 | 334 |
321 self._optimize_virtual_root(baseline_name, non_virtual_baseline_name) | 335 self._optimize_virtual_root(baseline_name, non_virtual_baseline_name) |
322 | 336 |
323 _log.debug("Optimizing non-virtual fallback path.") | 337 _log.debug("Optimizing non-virtual fallback path.") |
324 result |= self._optimize_subtree(non_virtual_baseline_name) | 338 result |= self._optimize_subtree(non_virtual_baseline_name) |
325 return result | 339 return result, self._files_to_delete, self._files_to_add |
OLD | NEW |