Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / PRESUBMIT.py
blob0fb932d6292d3918e446a69e1a4957c6e94816e2
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """LayoutTests/ presubmit script for Blink.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl.
9 """
11 import filecmp
14 def _CheckTestharnessResults(input_api, output_api):
15 expected_files = [f.AbsoluteLocalPath() for f in input_api.AffectedFiles() if f.LocalPath().endswith('-expected.txt') and f.Action() != 'D']
16 if len(expected_files) == 0:
17 return []
19 checker_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
20 '..', 'Tools', 'Scripts', 'check-testharness-expected-pass')
22 args = [input_api.python_executable, checker_path]
23 args.extend(expected_files)
24 _, errs = input_api.subprocess.Popen(args,
25 stdout=input_api.subprocess.PIPE,
26 stderr=input_api.subprocess.PIPE).communicate()
27 if errs:
28 return [output_api.PresubmitError(errs)]
29 return []
32 def _CheckIdenticalFiles(input_api, output_api):
33 """Verifies that certain files are identical in various locations.
34 These files should always be updated together."""
36 dirty_files = set(input_api.LocalPaths())
38 groups = [[
39 'resources/testharness.js',
40 'http/tests/resources/testharness.js',
41 'http/tests/w3c/resources/testharness.js',
42 ], [
43 'resources/testharnessreport.js',
44 'http/tests/resources/testharnessreport.js',
45 'http/tests/w3c/resources/testharnessreport.js',
46 ], [
47 'resources/idlharness.js',
48 'http/tests/w3c/resources/idlharness.js',
49 ], [
50 'resources/WebIDLParser.js',
51 'http/tests/w3c/resources/WebIDLParser.js',
52 ], [
53 'resources/testharness-helpers.js',
54 'http/tests/resources/testharness-helpers.js',
57 def _absolute_path(s):
58 return input_api.os_path.join(input_api.PresubmitLocalPath(), *s.split('/'))
60 def _local_path(s):
61 return input_api.os_path.join('LayoutTests', *s.split('/'))
63 errors = []
64 for group in groups:
65 if any(_local_path(p) in dirty_files for p in group):
66 a = group[0]
67 for b in group[1:]:
68 if not filecmp.cmp(_absolute_path(a), _absolute_path(b), shallow=False):
69 errors.append(output_api.PresubmitError(
70 'Files that should match differ: (see https://crbug.com/362788)\n' +
71 ' %s <=> %s' % (_local_path(a), _local_path(b))))
72 return errors
75 def CheckChangeOnUpload(input_api, output_api):
76 results = []
77 results.extend(_CheckTestharnessResults(input_api, output_api))
78 results.extend(_CheckIdenticalFiles(input_api, output_api))
79 return results
82 def CheckChangeOnCommit(input_api, output_api):
83 results = []
84 results.extend(_CheckTestharnessResults(input_api, output_api))
85 results.extend(_CheckIdenticalFiles(input_api, output_api))
86 return results