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