Christoffer Jansson | 4e8a773 | 2022-02-08 09:01:12 +0100 | [diff] [blame] | 1 | #!/usr/bin/env vpython3 |
| 2 | |
Henrik Kjellander | b5ffc14 | 2016-12-15 09:48:52 +0100 | [diff] [blame] | 3 | # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license |
| 6 | # that can be found in the LICENSE file in the root of the source |
| 7 | # tree. An additional intellectual property rights grant can be found |
| 8 | # in the file PATENTS. All contributing project authors may |
| 9 | # be found in the AUTHORS file in the root of the source tree. |
| 10 | |
Christoffer Jansson | 4e8a773 | 2022-02-08 09:01:12 +0100 | [diff] [blame] | 11 | # Runs PRESUBMIT.py in py3 mode by git cl presubmit. |
| 12 | USE_PYTHON3 = True |
| 13 | |
Edward Lemur | 27b2c9a | 2018-02-01 15:23:33 +0100 | [diff] [blame] | 14 | |
Henrik Kjellander | b5ffc14 | 2016-12-15 09:48:52 +0100 | [diff] [blame] | 15 | def _LicenseHeader(input_api): |
Christoffer Jansson | 4e8a773 | 2022-02-08 09:01:12 +0100 | [diff] [blame] | 16 | """Returns the license header regexp.""" |
| 17 | # Accept any year number from 2003 to the current year |
| 18 | current_year = int(input_api.time.strftime('%Y')) |
| 19 | allowed_years = (str(s) for s in reversed(range(2003, current_year + 1))) |
| 20 | years_re = '(' + '|'.join(allowed_years) + ')' |
| 21 | license_header = ( |
| 22 | r'.*? Copyright( \(c\))? %(year)s The WebRTC [Pp]roject [Aa]uthors\. ' |
| 23 | r'All [Rr]ights [Rr]eserved\.\n' |
| 24 | r'.*?\n' |
| 25 | r'.*? Use of this source code is governed by a BSD-style license\n' |
| 26 | r'.*? that can be found in the LICENSE file in the root of the source\n' |
| 27 | r'.*? tree\. An additional intellectual property rights grant can be ' |
| 28 | r'found\n' |
| 29 | r'.*? in the file PATENTS\. All contributing project authors may\n' |
| 30 | r'.*? be found in the AUTHORS file in the root of the source tree\.\n' |
| 31 | ) % { |
| 32 | 'year': years_re, |
| 33 | } |
| 34 | return license_header |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 35 | |
Henrik Kjellander | b5ffc14 | 2016-12-15 09:48:52 +0100 | [diff] [blame] | 36 | |
| 37 | def _CommonChecks(input_api, output_api): |
Christoffer Jansson | 4e8a773 | 2022-02-08 09:01:12 +0100 | [diff] [blame] | 38 | """Checks common to both upload and commit.""" |
| 39 | results = [] |
| 40 | results.extend( |
| 41 | input_api.canned_checks.CheckLicense(input_api, output_api, |
| 42 | _LicenseHeader(input_api))) |
| 43 | return results |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 44 | |
Henrik Kjellander | b5ffc14 | 2016-12-15 09:48:52 +0100 | [diff] [blame] | 45 | |
| 46 | def CheckChangeOnUpload(input_api, output_api): |
Christoffer Jansson | 4e8a773 | 2022-02-08 09:01:12 +0100 | [diff] [blame] | 47 | results = [] |
| 48 | results.extend(_CommonChecks(input_api, output_api)) |
| 49 | return results |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 50 | |
Henrik Kjellander | b5ffc14 | 2016-12-15 09:48:52 +0100 | [diff] [blame] | 51 | |
| 52 | def CheckChangeOnCommit(input_api, output_api): |
Christoffer Jansson | 4e8a773 | 2022-02-08 09:01:12 +0100 | [diff] [blame] | 53 | results = [] |
| 54 | results.extend(_CommonChecks(input_api, output_api)) |
| 55 | return results |