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.
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:
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()
28 return [output_api
.PresubmitError(errs
)]
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())
39 'resources/testharness.js',
40 'http/tests/resources/testharness.js',
41 'http/tests/w3c/resources/testharness.js',
43 'resources/testharnessreport.js',
44 'http/tests/resources/testharnessreport.js',
45 'http/tests/w3c/resources/testharnessreport.js',
47 'resources/idlharness.js',
48 'http/tests/w3c/resources/idlharness.js',
50 'resources/WebIDLParser.js',
51 'http/tests/w3c/resources/WebIDLParser.js',
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('/'))
61 return input_api
.os_path
.join('LayoutTests', *s
.split('/'))
65 if any(_local_path(p
) in dirty_files
for p
in group
):
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
))))
75 def CheckChangeOnUpload(input_api
, output_api
):
77 results
.extend(_CheckTestharnessResults(input_api
, output_api
))
78 results
.extend(_CheckIdenticalFiles(input_api
, output_api
))
82 def CheckChangeOnCommit(input_api
, output_api
):
84 results
.extend(_CheckTestharnessResults(input_api
, output_api
))
85 results
.extend(_CheckIdenticalFiles(input_api
, output_api
))