• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright (C) 2010 Google Inc. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7#
8# 1.  Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10# 2.  Redistributions in binary form must reproduce the above copyright
11#     notice, this list of conditions and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25"""deduplicate-tests -- print test results duplicated between platforms.
26
27If platform/mac-leopard is missing an expected test output, we fall back on
28platform/mac.  This means it's possible to grow redundant test outputs,
29where we have the same expected data in both a platform directory and another
30platform it falls back on.
31
32This command dumps out all such files.  You can use it like this:
33  deduplicate-tests --verbose  # print out the duplicated files
34  deduplicate-tests | xargs git rm   # delete them
35"""
36
37
38import optparse
39import webkitpy.common.system.logutils as logutils
40import webkitpy.layout_tests.deduplicate_tests as deduplicate_tests
41
42
43def parse_args():
44    """Provides a default set of command line args.
45
46    Returns a tuple of options, args from optparse"""
47
48    configuration_options = [
49        optparse.make_option("-v", "--verbose", dest="verbose",
50                             action="store_true", default=False,
51                             help="Verbose output."),
52        optparse.make_option("-g", "--glob", dest="glob_pattern",
53                             default="*-expected*",
54                             help="Specify the glob to filter the files, defaults to *-expected*."),
55    ]
56
57    option_list = (configuration_options)
58    option_parser = optparse.OptionParser(option_list=option_list)
59
60    options, _ = option_parser.parse_args()
61
62    return options
63
64
65def run(options):
66    logutils.configure_logging()
67    if options.verbose:
68        format = ("* %(test)s\n"
69                  "\tredundantly on %(platform)s and %(fallback)s\n"
70                  "\tconsider deleting %(path)s")
71    else:
72        format = "%(path)s"
73
74    for dupe in deduplicate_tests.deduplicate(options.glob_pattern):
75        print(format % dupe)
76
77
78def main():
79    options = parse_args()
80    run(options)
81
82
83if __name__ == '__main__':
84    main()
85