| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 if inverted_dictionary.get(value): | 42 if inverted_dictionary.get(value): |
| 43 inverted_dictionary[value].append(key) | 43 inverted_dictionary[value].append(key) |
| 44 else: | 44 else: |
| 45 inverted_dictionary[value] = [key] | 45 inverted_dictionary[value] = [key] |
| 46 return inverted_dictionary | 46 return inverted_dictionary |
| 47 | 47 |
| 48 | 48 |
| 49 class BaselineOptimizer(object): | 49 class BaselineOptimizer(object): |
| 50 ROOT_LAYOUT_TESTS_DIRECTORY = 'LayoutTests' | 50 ROOT_LAYOUT_TESTS_DIRECTORY = 'LayoutTests' |
| 51 | 51 |
| 52 def __init__(self, host, port, port_names, skip_scm_commands): | 52 def __init__(self, host, port, port_names): |
| 53 self._filesystem = host.filesystem | 53 self._filesystem = host.filesystem |
| 54 self._skip_scm_commands = skip_scm_commands | |
| 55 self._files_to_delete = [] | |
| 56 self._files_to_add = [] | |
| 57 self._scm = host.scm() | |
| 58 self._default_port = port | 54 self._default_port = port |
| 59 self._ports = {} | 55 self._ports = {} |
| 60 for port_name in port_names: | 56 for port_name in port_names: |
| 61 self._ports[port_name] = host.port_factory.get(port_name) | 57 self._ports[port_name] = host.port_factory.get(port_name) |
| 62 | 58 |
| 63 self._webkit_base = port.webkit_base() | 59 self._webkit_base = port.webkit_base() |
| 64 self._layout_tests_dir = port.layout_tests_dir() | 60 self._layout_tests_dir = port.layout_tests_dir() |
| 65 | 61 |
| 66 # Only used by unittests. | 62 # Only used by unittests. |
| 67 self.new_results_by_directory = [] | 63 self.new_results_by_directory = [] |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 return filename.replace(platform_dir, '').split(self._filesystem.sep
)[0] | 215 return filename.replace(platform_dir, '').split(self._filesystem.sep
)[0] |
| 220 return '(generic)' | 216 return '(generic)' |
| 221 | 217 |
| 222 def _move_baselines(self, baseline_name, results_by_directory, new_results_b
y_directory): | 218 def _move_baselines(self, baseline_name, results_by_directory, new_results_b
y_directory): |
| 223 data_for_result = {} | 219 data_for_result = {} |
| 224 for directory, result in results_by_directory.items(): | 220 for directory, result in results_by_directory.items(): |
| 225 if not result in data_for_result: | 221 if not result in data_for_result: |
| 226 source = self._join_directory(directory, baseline_name) | 222 source = self._join_directory(directory, baseline_name) |
| 227 data_for_result[result] = self._filesystem.read_binary_file(sour
ce) | 223 data_for_result[result] = self._filesystem.read_binary_file(sour
ce) |
| 228 | 224 |
| 229 scm_files = [] | |
| 230 fs_files = [] | 225 fs_files = [] |
| 231 for directory, result in results_by_directory.items(): | 226 for directory, result in results_by_directory.items(): |
| 232 if new_results_by_directory.get(directory) != result: | 227 if new_results_by_directory.get(directory) != result: |
| 233 file_name = self._join_directory(directory, baseline_name) | 228 file_name = self._join_directory(directory, baseline_name) |
| 234 if self._scm.exists(file_name): | 229 if self._filesystem.exists(file_name): |
| 235 scm_files.append(file_name) | |
| 236 elif self._filesystem.exists(file_name): | |
| 237 fs_files.append(file_name) | 230 fs_files.append(file_name) |
| 238 | 231 |
| 239 if scm_files or fs_files: | 232 if fs_files: |
| 240 if scm_files: | 233 _log.debug(" Deleting (file system):") |
| 241 _log.debug(" Deleting (SCM):") | 234 for platform_dir in sorted(self._platform(filename) for filename in
fs_files): |
| 242 for platform_dir in sorted(self._platform(filename) for filename
in scm_files): | 235 _log.debug(" " + platform_dir) |
| 243 _log.debug(" " + platform_dir) | 236 for filename in fs_files: |
| 244 if self._skip_scm_commands: | 237 self._filesystem.remove(filename) |
| 245 self._files_to_delete.extend(scm_files) | |
| 246 else: | |
| 247 self._scm.delete_list(scm_files) | |
| 248 if fs_files: | |
| 249 _log.debug(" Deleting (file system):") | |
| 250 for platform_dir in sorted(self._platform(filename) for filename
in fs_files): | |
| 251 _log.debug(" " + platform_dir) | |
| 252 for filename in fs_files: | |
| 253 self._filesystem.remove(filename) | |
| 254 else: | 238 else: |
| 255 _log.debug(" (Nothing to delete)") | 239 _log.debug(" (Nothing to delete)") |
| 256 | 240 |
| 257 file_names = [] | 241 file_names = [] |
| 258 for directory, result in new_results_by_directory.items(): | 242 for directory, result in new_results_by_directory.items(): |
| 259 if results_by_directory.get(directory) != result: | 243 if results_by_directory.get(directory) != result: |
| 260 destination = self._join_directory(directory, baseline_name) | 244 destination = self._join_directory(directory, baseline_name) |
| 261 self._filesystem.maybe_make_directory(self._filesystem.split(des
tination)[0]) | 245 self._filesystem.maybe_make_directory(self._filesystem.split(des
tination)[0]) |
| 262 self._filesystem.write_binary_file(destination, data_for_result[
result]) | 246 self._filesystem.write_binary_file(destination, data_for_result[
result]) |
| 263 file_names.append(destination) | 247 file_names.append(destination) |
| 264 | 248 |
| 265 if file_names: | 249 if file_names: |
| 266 _log.debug(" Adding:") | 250 _log.debug(" Adding:") |
| 267 for platform_dir in sorted(self._platform(filename) for filename in
file_names): | 251 for platform_dir in sorted(self._platform(filename) for filename in
file_names): |
| 268 _log.debug(" " + platform_dir) | 252 _log.debug(" " + platform_dir) |
| 269 if self._skip_scm_commands: | |
| 270 # Have adds win over deletes. | |
| 271 self._files_to_delete = list(set(self._files_to_delete) - set(fi
le_names)) | |
| 272 self._files_to_add.extend(file_names) | |
| 273 else: | |
| 274 self._scm.add_list(file_names) | |
| 275 else: | 253 else: |
| 276 _log.debug(" (Nothing to add)") | 254 _log.debug(" (Nothing to add)") |
| 277 | 255 |
| 278 def write_by_directory(self, results_by_directory, writer, indent): | 256 def write_by_directory(self, results_by_directory, writer, indent): |
| 279 for path in sorted(results_by_directory): | 257 for path in sorted(results_by_directory): |
| 280 writer("%s%s: %s" % (indent, self._platform(path), results_by_direct
ory[path][0:6])) | 258 writer("%s%s: %s" % (indent, self._platform(path), results_by_direct
ory[path][0:6])) |
| 281 | 259 |
| 282 def _optimize_subtree(self, baseline_name): | 260 def _optimize_subtree(self, baseline_name): |
| 283 basename = self._filesystem.basename(baseline_name) | 261 basename = self._filesystem.basename(baseline_name) |
| 284 results_by_directory, new_results_by_directory = self._find_optimal_resu
lt_placement(baseline_name) | 262 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... |
| 321 for port in self._ports.values(): | 299 for port in self._ports.values(): |
| 322 directories = self._relative_baseline_search_paths(port, non_virtual
_baseline_name) | 300 directories = self._relative_baseline_search_paths(port, non_virtual
_baseline_name) |
| 323 for directory in directories: | 301 for directory in directories: |
| 324 if directory not in results_by_directory: | 302 if directory not in results_by_directory: |
| 325 continue | 303 continue |
| 326 if results_by_directory[directory] != root_sha1: | 304 if results_by_directory[directory] != root_sha1: |
| 327 return | 305 return |
| 328 break | 306 break |
| 329 | 307 |
| 330 _log.debug("Deleting redundant virtual root expected result.") | 308 _log.debug("Deleting redundant virtual root expected result.") |
| 331 if self._skip_scm_commands and virtual_root_expected_baseline_path in se
lf._files_to_add: | 309 _log.debug(" Deleting (file system): " + virtual_root_expected_baseli
ne_path) |
| 332 self._files_to_add.remove(virtual_root_expected_baseline_path) | 310 self._filesystem.remove(virtual_root_expected_baseline_path) |
| 333 if self._scm.exists(virtual_root_expected_baseline_path): | |
| 334 _log.debug(" Deleting (SCM): " + virtual_root_expected_baseline_p
ath) | |
| 335 if self._skip_scm_commands: | |
| 336 self._files_to_delete.append(virtual_root_expected_baseline_path
) | |
| 337 else: | |
| 338 self._scm.delete(virtual_root_expected_baseline_path) | |
| 339 else: | |
| 340 _log.debug(" Deleting (file system): " + virtual_root_expected_ba
seline_path) | |
| 341 self._filesystem.remove(virtual_root_expected_baseline_path) | |
| 342 | 311 |
| 343 def optimize(self, baseline_name): | 312 def optimize(self, baseline_name): |
| 344 # The virtual fallback path is the same as the non-virtual one tacked on
to the bottom of the non-virtual path. | 313 # The virtual fallback path is the same as the non-virtual one tacked on
to the bottom of the non-virtual path. |
| 345 # See https://docs.google.com/a/chromium.org/drawings/d/1eGdsIKzJ2dxDDBb
UaIABrN4aMLD1bqJTfyxNGZsTdmg/edit for | 314 # See https://docs.google.com/a/chromium.org/drawings/d/1eGdsIKzJ2dxDDBb
UaIABrN4aMLD1bqJTfyxNGZsTdmg/edit for |
| 346 # a visual representation of this. | 315 # a visual representation of this. |
| 347 # | 316 # |
| 348 # So, we can optimize the virtual path, then the virtual root and then t
he regular path. | 317 # So, we can optimize the virtual path, then the virtual root and then t
he regular path. |
| 349 | 318 |
| 350 self._files_to_delete = [] | |
| 351 self._files_to_add = [] | |
| 352 _log.debug("Optimizing regular fallback path.") | 319 _log.debug("Optimizing regular fallback path.") |
| 353 result = self._optimize_subtree(baseline_name) | 320 result = self._optimize_subtree(baseline_name) |
| 354 non_virtual_baseline_name = self._virtual_base(baseline_name) | 321 non_virtual_baseline_name = self._virtual_base(baseline_name) |
| 355 if not non_virtual_baseline_name: | 322 if not non_virtual_baseline_name: |
| 356 return result, self._files_to_delete, self._files_to_add | 323 return result |
| 357 | 324 |
| 358 self._optimize_virtual_root(baseline_name, non_virtual_baseline_name) | 325 self._optimize_virtual_root(baseline_name, non_virtual_baseline_name) |
| 359 | 326 |
| 360 _log.debug("Optimizing non-virtual fallback path.") | 327 _log.debug("Optimizing non-virtual fallback path.") |
| 361 result |= self._optimize_subtree(non_virtual_baseline_name) | 328 result |= self._optimize_subtree(non_virtual_baseline_name) |
| 362 return result, self._files_to_delete, self._files_to_add | 329 return result |
| OLD | NEW |