1# Copyright 2020 The Tint Authors 2# 3# Licensed under the Apache License, Version 2.0 (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 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Presubmit script for Tint. 15See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 16for more details about the presubmit API built into depot_tools. 17""" 18 19 20def _LicenseHeader(input_api): 21 """Returns the license header regexp.""" 22 # Accept any year number from 2019 to the current year 23 current_year = int(input_api.time.strftime('%Y')) 24 allowed_years = (str(s) for s in reversed(xrange(2019, current_year + 1))) 25 years_re = '(' + '|'.join(allowed_years) + ')' 26 license_header = ( 27 r'.*? Copyright( \(c\))? %(year)s The Tint [Aa]uthors\n ' 28 r'.*?\n' 29 r'.*? Licensed under the Apache License, Version 2.0 (the "License");\n' 30 r'.*? you may not use this file except in compliance with the License.\n' 31 r'.*? You may obtain a copy of the License at\n' 32 r'.*?\n' 33 r'.*? http://www.apache.org/licenses/LICENSE-2.0\n' 34 r'.*?\n' 35 r'.*? Unless required by applicable law or agreed to in writing, software\n' 36 r'.*? distributed under the License is distributed on an "AS IS" BASIS,\n' 37 r'.*? WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n' 38 r'.*? See the License for the specific language governing permissions and\n' 39 r'.*? limitations under the License.\n') % { 40 'year': years_re, 41 } 42 return license_header 43 44 45def CheckChange(input_api, output_api): 46 results = [] 47 48 results += input_api.canned_checks.CheckChangeHasDescription( 49 input_api, output_api) 50 results += input_api.canned_checks.CheckPatchFormatted(input_api, 51 output_api, 52 check_python=True) 53 results += input_api.canned_checks.CheckGNFormatted(input_api, output_api) 54 results += input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol( 55 input_api, output_api) 56 results += input_api.canned_checks.CheckChangeHasNoTabs( 57 input_api, output_api) 58 results += input_api.canned_checks.CheckChangeTodoHasOwner( 59 input_api, output_api) 60 results += input_api.canned_checks.CheckChangeHasNoStrayWhitespace( 61 input_api, output_api) 62 results += input_api.canned_checks.CheckDoNotSubmit(input_api, output_api) 63 results += input_api.canned_checks.CheckChangeLintsClean(input_api, 64 output_api, 65 lint_filters="") 66 results += input_api.canned_checks.CheckGenderNeutral( 67 input_api, output_api) 68 69 return results 70 71 72def CheckChangeOnUpload(input_api, output_api): 73 return CheckChange(input_api, output_api) 74 75 76def CheckChangeOnCommit(input_api, output_api): 77 return CheckChange(input_api, output_api) 78