[email protected] | 99f1a48 | 2011-04-12 00:11:23 | [diff] [blame^] | 1 | # Copyright (c) 2011 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. |
| 4 | |
| 5 | def _CheckThirdPartyReadmesUpdated(input_api, output_api): |
| 6 | """ |
| 7 | Checks to make sure that README.chromium files are properly updated |
| 8 | when dependancies in third_party are modified. |
| 9 | """ |
| 10 | readmes = [] |
| 11 | files = [] |
| 12 | errors = [] |
| 13 | for f in input_api.AffectedFiles(): |
| 14 | if f.LocalPath().startswith('third_party' + input_api.os_path.sep): |
| 15 | files.append(f) |
| 16 | if f.LocalPath().endswith("README.chromium"): |
| 17 | readmes.append(f) |
| 18 | if files and not readmes: |
| 19 | errors.append(output_api.PresubmitPromptWarning( |
| 20 | 'When updating or adding third party code the appropriate\n' |
| 21 | '\'README.chromium\' file should also be updated with the correct\n' |
| 22 | 'version and package information.', files)) |
| 23 | if not readmes: |
| 24 | return errors |
| 25 | |
| 26 | name_pattern = input_api.re.compile( |
| 27 | r'^Name: [a-zA-Z0-9_\-\.]+\r?$', |
| 28 | input_api.re.IGNORECASE | input_api.re.MULTILINE) |
| 29 | shortname_pattern = input_api.re.compile( |
| 30 | r'^Short Name: [a-zA-Z0-9_\-\.]+\r?$', |
| 31 | input_api.re.IGNORECASE | input_api.re.MULTILINE) |
| 32 | version_pattern = input_api.re.compile( |
| 33 | r'^Version: [a-zA-Z0-9_\-\.]+\r?$', |
| 34 | input_api.re.IGNORECASE | input_api.re.MULTILINE) |
| 35 | release_pattern = input_api.re.compile( |
| 36 | r'Security Critical: (yes)|(no)\r?$', |
| 37 | input_api.re.IGNORECASE | input_api.re.MULTILINE) |
| 38 | |
| 39 | for f in readmes: |
| 40 | contents = input_api.ReadFile(f) |
| 41 | if (not shortname_pattern.search(contents) |
| 42 | and not name_pattern.search(contents)): |
| 43 | errors.append(output_api.PresubmitError( |
| 44 | 'Third party README files should contain either a \'Short Name\' or\n' |
| 45 | 'a \'Name\' which is the name under which the package is\n' |
| 46 | 'distributed. Check README.chromium.template for details.', |
| 47 | [f])) |
| 48 | if not version_pattern.search(contents): |
| 49 | errors.append(output_api.PresubmitError( |
| 50 | 'Third party README files should contain a \'Version\' field.\n' |
| 51 | 'If the package is not versioned or the version is not known\n' |
| 52 | 'list the version as \'unknown\'.\n' |
| 53 | 'Check README.chromium.template for details.', |
| 54 | [f])) |
| 55 | if not release_pattern.search(contents): |
| 56 | errors.append(output_api.PresubmitError( |
| 57 | 'Third party README files should contain a \'Security Critical\'\n' |
| 58 | 'field. This field specifies whether the package is built with\n' |
| 59 | 'Chromium. Check README.chromium.template for details.', |
| 60 | [f])) |
| 61 | return errors |
| 62 | |
| 63 | |
| 64 | def CheckChangeOnUpload(input_api, output_api): |
| 65 | results = [] |
| 66 | results.extend(_CheckThirdPartyReadmesUpdated(input_api, output_api)) |
| 67 | return results |