1 # Copyright 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 """Chromium presubmit script for src/net/websockets.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details on the presubmit API built into gcl.
12 # TODO(ricea): Remove this once the old implementation has been removed and the
13 # list of files in the README file is no longer needed.
14 def _CheckReadMeComplete(input_api
, output_api
):
15 """Verifies that any new files have been added to the README file.
17 Checks that if any source files were added in this CL, that they were
18 also added to the README file. We do not warn about pre-existing
19 errors, as that would be annoying.
22 input_api: The InputApi object provided by the presubmit framework.
23 output_api: The OutputApi object provided by the framework.
26 A list of zero or more PresubmitPromptWarning objects.
28 # None passed to AffectedSourceFiles means "use the default filter", which
29 # does what we want, ie. returns files in the CL with filenames that look like
31 added_source_filenames
= set(input_api
.basename(af
.LocalPath())
32 for af
in input_api
.AffectedSourceFiles(None)
33 if af
.Action().startswith('A'))
34 if not added_source_filenames
:
36 readme
= input_api
.AffectedSourceFiles(
37 lambda af
: af
.LocalPath().endswith('/README'))
39 return [output_api
.PresubmitPromptWarning(
40 'One or more files were added to net/websockets without being added\n'
41 'to net/websockets/README.\n', added_source_filenames
)]
42 readme_added_filenames
= set(line
.strip() for line
in readme
[0].NewContents()
43 if line
.strip() in added_source_filenames
)
44 if readme_added_filenames
< added_source_filenames
:
45 return [output_api
.PresubmitPromptWarning(
46 'One or more files added to net/websockets but not found in the README '
47 'file.\n', added_source_filenames
- readme_added_filenames
)]
52 def CheckChangeOnUpload(input_api
, output_api
):
53 return _CheckReadMeComplete(input_api
, output_api
)
56 def CheckChangeOnCommit(input_api
, output_api
):
57 return _CheckReadMeComplete(input_api
, output_api
)