Chromium Code Reviews| Index: net/websockets/PRESUBMIT.py |
| diff --git a/net/websockets/PRESUBMIT.py b/net/websockets/PRESUBMIT.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9243696e2c7e6846ddb650471b12a9555a98b1a1 |
| --- /dev/null |
| +++ b/net/websockets/PRESUBMIT.py |
| @@ -0,0 +1,65 @@ |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Chromium presubmit script for src/net/websockets. |
| + |
| +See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| +for more details on the presubmit API built into gcl. |
| +""" |
| + |
| + |
| +# TODO(ricea): Remove this once the old implementation has been removed and the |
| +# list of files in the README file is no longer needed. |
| +def CheckReadMeComplete(input_api, output_api): |
| + """Verifies that any new files have been added to the README file. |
| + |
| + Checks that if any source files were added in this CL, that they were |
| + also added to the README file. We do not warn about pre-existing |
| + errors, as that would be annoying. |
| + |
| + Args: |
| + input_api: The InputApi object provided by the presubmit framework. |
| + output_api: The OutputApi object provided by the framework. |
| + |
| + Returns: |
| + A list of zero or more PresubmitPromptWarning objects. |
| + """ |
| + # None passed to AffectedSourceFiles means "use the default filter", which |
| + # does what we want, ie. returns files in the CL with filenames that look like |
| + # source code. |
| + added_source_files = [af for af in input_api.AffectedSourceFiles(None) |
|
yhirano
2013/07/11 01:44:34
Maybe you can delete added_source_files by creatin
Adam Rice
2013/07/11 06:42:37
Good idea, thank you.
|
| + if af.Action().startswith('A')] |
| + if not added_source_files: |
| + return [] |
| + readme = input_api.AffectedSourceFiles( |
| + lambda af: af.LocalPath().endswith('/README')) |
| + added_source_filenames = set(input_api.basename(sf.LocalPath()) |
| + for sf in added_source_files) |
| + if not readme: |
| + return [output_api.PresubmitPromptWarning( |
| + 'One or more files were added to net/websockets without being added\n' |
| + 'to net/websockets/README.\n', added_source_filenames)] |
| + for line in readme[0].NewContents(): |
|
yhirano
2013/07/11 01:44:34
Can you introduce readme_added_filenames = set([li
yhirano
2013/07/11 01:47:35
rewrite the following lines by using set operation
Adam Rice
2013/07/11 06:42:37
Very nice. Implemented.
Adam Rice
2013/07/11 06:42:37
No problem. I understood what you meant.
|
| + if line.strip() in added_source_filenames: |
| + added_source_filenames.remove(line.strip()) |
| + if added_source_filenames: |
| + return [output_api.PresubmitPromptWarning( |
| + 'One or more files added to net/websockets but not found in the README ' |
| + 'file.\n', added_source_filenames)] |
| + else: |
| + return [] |
| + |
| + |
| +def CheckChange(input_api, output_api): |
| + results = [] |
| + results += CheckReadMeComplete(input_api, output_api) |
| + return results |
| + |
| + |
| +def CheckChangeOnUpload(input_api, output_api): |
| + return CheckChange(input_api, output_api) |
| + |
| + |
| +def CheckChangeOnCommit(input_api, output_api): |
| + return CheckChange(input_api, output_api) |