| OLD | NEW |
| 1 # Copyright 2015 The LUCI Authors. | 1 # Copyright 2015 The LUCI Authors. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 13 # limitations under the License. |
| 14 | 14 |
| 15 """Top-level presubmit script. | 15 """Top-level presubmit script. |
| 16 | 16 |
| 17 See https://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for | 17 See https://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
| 18 details on the presubmit API built into depot_tools. | 18 details on the presubmit API built into depot_tools. |
| 19 """ | 19 """ |
| 20 | 20 |
| 21 import os | 21 import os |
| 22 import re |
| 22 import sys | 23 import sys |
| 23 | 24 |
| 24 | 25 |
| 25 def PreCommitGo(input_api, output_api, pcg_mode): | 26 def PreCommitGo(input_api, output_api, pcg_mode): |
| 26 """Run go-specific checks via pre-commit-go (pcg) if it's in PATH.""" | 27 """Run go-specific checks via pre-commit-go (pcg) if it's in PATH.""" |
| 27 if input_api.is_committing: | 28 if input_api.is_committing: |
| 28 error_type = output_api.PresubmitError | 29 error_type = output_api.PresubmitError |
| 29 else: | 30 else: |
| 30 error_type = output_api.PresubmitPromptWarning | 31 error_type = output_api.PresubmitPromptWarning |
| 31 | 32 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 cmd.extend(['-r', 'HEAD~1']) | 52 cmd.extend(['-r', 'HEAD~1']) |
| 52 return input_api.RunTests([ | 53 return input_api.RunTests([ |
| 53 input_api.Command( | 54 input_api.Command( |
| 54 name='pre-commit-go: %s' % ', '.join(pcg_mode), | 55 name='pre-commit-go: %s' % ', '.join(pcg_mode), |
| 55 cmd=cmd, | 56 cmd=cmd, |
| 56 kwargs={}, | 57 kwargs={}, |
| 57 message=error_type), | 58 message=error_type), |
| 58 ]) | 59 ]) |
| 59 | 60 |
| 60 | 61 |
| 62 COPYRIGHT_TEMPLATE = """ |
| 63 Copyright YEARPATTERN The LUCI Authors. |
| 64 |
| 65 Licensed under the Apache License, Version 2.0 (the "License"); |
| 66 you may not use this file except in compliance with the License. |
| 67 You may obtain a copy of the License at |
| 68 |
| 69 http://www.apache.org/licenses/LICENSE-2.0 |
| 70 |
| 71 Unless required by applicable law or agreed to in writing, software |
| 72 distributed under the License is distributed on an "AS IS" BASIS, |
| 73 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 74 See the License for the specific language governing permissions and |
| 75 limitations under the License. |
| 76 """.strip() |
| 77 |
| 61 def header(input_api): | 78 def header(input_api): |
| 62 """Returns the expected license header regexp for this project.""" | 79 """Returns the expected license header regexp for this project.""" |
| 63 current_year = int(input_api.time.strftime('%Y')) | 80 current_year = int(input_api.time.strftime('%Y')) |
| 64 allowed_years = (str(s) for s in reversed(xrange(2011, current_year + 1))) | 81 allowed_years = (str(s) for s in reversed(xrange(2011, current_year + 1))) |
| 65 years_re = '(' + '|'.join(allowed_years) + ')' | 82 years_re = '(' + '|'.join(allowed_years) + ')' |
| 66 license_header = ( | 83 lines = [ |
| 67 r'.*? Copyright %(year)s The LUCI Authors\. ' | 84 ('.*? ' + re.escape(line)) if line else '.*?' |
| 68 r'All rights reserved\.\n' | 85 for line in COPYRIGHT_TEMPLATE.splitlines() |
| 69 r'.*? Use of this source code is governed under the Apache License, ' | 86 ] |
| 70 r'Version 2\.0\n' | 87 lines[0] = lines[0].replace('YEARPATTERN', years_re) |
| 71 r'.*? that can be found in the LICENSE file\.(?: \*/)?\n' | 88 return '\n'.join(lines) + '(?: \*/)?\n' |
| 72 ) % { | |
| 73 'year': years_re, | |
| 74 } | |
| 75 return license_header | |
| 76 | 89 |
| 77 | 90 |
| 78 def source_file_filter(input_api): | 91 def source_file_filter(input_api): |
| 79 """Returns filter that selects source code files only.""" | 92 """Returns filter that selects source code files only.""" |
| 80 bl = list(input_api.DEFAULT_BLACK_LIST) + [ | 93 bl = list(input_api.DEFAULT_BLACK_LIST) + [ |
| 81 r'.+\.pb\.go$', | 94 r'.+\.pb\.go$', |
| 82 r'.+_string\.go$', | 95 r'.+_string\.go$', |
| 83 ] | 96 ] |
| 84 wl = list(input_api.DEFAULT_WHITE_LIST) + [ | 97 wl = list(input_api.DEFAULT_WHITE_LIST) + [ |
| 85 r'.+\.go$', | 98 r'.+\.go$', |
| (...skipping 24 matching lines...) Expand all Loading... |
| 110 results = CommonChecks(input_api, output_api) | 123 results = CommonChecks(input_api, output_api) |
| 111 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 124 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 112 input_api, output_api)) | 125 input_api, output_api)) |
| 113 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( | 126 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( |
| 114 input_api, output_api)) | 127 input_api, output_api)) |
| 115 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( | 128 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( |
| 116 input_api, output_api)) | 129 input_api, output_api)) |
| 117 results.extend(PreCommitGo( | 130 results.extend(PreCommitGo( |
| 118 input_api, output_api, ['lint', 'pre-commit', 'pre-push'])) | 131 input_api, output_api, ['lint', 'pre-commit', 'pre-push'])) |
| 119 return results | 132 return results |
| OLD | NEW |