OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 """Classes for merging layout tests results directories together. | 5 """Classes for merging layout tests results directories together. |
6 | 6 |
7 This is split into three parts: | 7 This is split into three parts: |
8 | 8 |
9 * Generic code to merge JSON data together. | 9 * Generic code to merge JSON data together. |
10 * Generic code to merge directories together. | 10 * Generic code to merge directories together. |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 423 |
424 self.filesystem = filesystem or FileSystem() | 424 self.filesystem = filesystem or FileSystem() |
425 | 425 |
426 # Default to just checking the file contents matches. | 426 # Default to just checking the file contents matches. |
427 self.add_helper(lambda *args: True, MergeFilesMatchingContents(self.file
system)) | 427 self.add_helper(lambda *args: True, MergeFilesMatchingContents(self.file
system)) |
428 # Copy the file it it's the only one. | 428 # Copy the file it it's the only one. |
429 self.add_helper(lambda _, to_merge: len(to_merge) == 1, MergeFilesOne(se
lf.filesystem)) | 429 self.add_helper(lambda _, to_merge: len(to_merge) == 1, MergeFilesOne(se
lf.filesystem)) |
430 | 430 |
431 def merge(self, output_dir, to_merge_dirs): | 431 def merge(self, output_dir, to_merge_dirs): |
432 output_dir = self.filesystem.realpath(self.filesystem.abspath(output_dir
)) | 432 output_dir = self.filesystem.realpath(self.filesystem.abspath(output_dir
)) |
433 if self.filesystem.exists(output_dir): | |
434 raise OSError("Output directory %s exists." % output_dir) | |
435 | 433 |
436 merge_dirs = [] | 434 merge_dirs = [] |
437 # Normalize the given directory values. | 435 # Normalize the given directory values. |
438 for base_dir in to_merge_dirs: | 436 for base_dir in to_merge_dirs: |
439 merge_dirs.append(self.filesystem.realpath(self.filesystem.abspath(b
ase_dir))) | 437 merge_dirs.append(self.filesystem.realpath(self.filesystem.abspath(b
ase_dir))) |
440 merge_dirs.sort() | 438 merge_dirs.sort() |
441 | 439 |
442 _log.debug("Merging following paths:") | 440 _log.debug("Merging following paths:") |
443 _log.debug(DeferredPrettyPrint(merge_dirs)) | 441 _log.debug(DeferredPrettyPrint(merge_dirs)) |
444 | 442 |
(...skipping 14 matching lines...) Expand all Loading... |
459 for f in filenames: | 457 for f in filenames: |
460 # rel_file is the path of f relative to the base directory | 458 # rel_file is the path of f relative to the base directory |
461 rel_file = self.filesystem.join(dir_path, f)[len(base_dir) +
1:] | 459 rel_file = self.filesystem.join(dir_path, f)[len(base_dir) +
1:] |
462 files.setdefault(rel_file, []).append(base_dir) | 460 files.setdefault(rel_file, []).append(base_dir) |
463 | 461 |
464 # Go through each file and try to merge it. | 462 # Go through each file and try to merge it. |
465 # partial_file_path is the file relative to the directories. | 463 # partial_file_path is the file relative to the directories. |
466 for partial_file_path, in_dirs in sorted(files.iteritems()): | 464 for partial_file_path, in_dirs in sorted(files.iteritems()): |
467 out_path = self.filesystem.join(output_dir, partial_file_path) | 465 out_path = self.filesystem.join(output_dir, partial_file_path) |
468 if self.filesystem.exists(out_path): | 466 if self.filesystem.exists(out_path): |
469 raise MergeFailure('File %s already exist in output.' % ( | 467 raise MergeFailure( |
470 out_path)) | 468 'File %s already exist in output.', out_path, None, None) |
471 | 469 |
472 dirname = self.filesystem.dirname(out_path) | 470 dirname = self.filesystem.dirname(out_path) |
473 if not self.filesystem.exists(dirname): | 471 if not self.filesystem.exists(dirname): |
474 self.filesystem.maybe_make_directory(dirname) | 472 self.filesystem.maybe_make_directory(dirname) |
475 | 473 |
476 to_merge = [self.filesystem.join(d, partial_file_path) for d in in_d
irs] | 474 to_merge = [self.filesystem.join(d, partial_file_path) for d in in_d
irs] |
477 | 475 |
478 _log.debug("Creating merged %s from %s", out_path, to_merge) | 476 _log.debug("Creating merged %s from %s", out_path, to_merge) |
479 | 477 |
480 for match_func, merge_func in reversed(self.helpers): | 478 for match_func, merge_func in reversed(self.helpers): |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 599 |
602 self.add_helper( | 600 self.add_helper( |
603 FilenameMatch('failing_results.json'), | 601 FilenameMatch('failing_results.json'), |
604 results_json_file_merger) | 602 results_json_file_merger) |
605 self.add_helper( | 603 self.add_helper( |
606 FilenameMatch('full_results.json'), | 604 FilenameMatch('full_results.json'), |
607 results_json_file_merger) | 605 results_json_file_merger) |
608 self.add_helper( | 606 self.add_helper( |
609 FilenameMatch('output.json'), | 607 FilenameMatch('output.json'), |
610 results_json_file_merger) | 608 results_json_file_merger) |
OLD | NEW |