blob: 57d142e9d77daf9774510b758bf135b60a468d73 [file] [log] [blame]
Christoffer Jansson4e8a7732022-02-08 09:01:12 +01001#!/usr/bin/env vpython3
2
Henrik Kjellanderb5ffc142016-12-15 09:48:52 +01003# 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 Jansson4e8a7732022-02-08 09:01:12 +010011# Runs PRESUBMIT.py in py3 mode by git cl presubmit.
12USE_PYTHON3 = True
13
Edward Lemur27b2c9a2018-02-01 15:23:33 +010014
Henrik Kjellanderb5ffc142016-12-15 09:48:52 +010015def _LicenseHeader(input_api):
Christoffer Jansson4e8a7732022-02-08 09:01:12 +010016 """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 Bonadei8cc66952020-10-30 10:13:45 +010035
Henrik Kjellanderb5ffc142016-12-15 09:48:52 +010036
37def _CommonChecks(input_api, output_api):
Christoffer Jansson4e8a7732022-02-08 09:01:12 +010038 """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 Bonadei8cc66952020-10-30 10:13:45 +010044
Henrik Kjellanderb5ffc142016-12-15 09:48:52 +010045
46def CheckChangeOnUpload(input_api, output_api):
Christoffer Jansson4e8a7732022-02-08 09:01:12 +010047 results = []
48 results.extend(_CommonChecks(input_api, output_api))
49 return results
Mirko Bonadei8cc66952020-10-30 10:13:45 +010050
Henrik Kjellanderb5ffc142016-12-15 09:48:52 +010051
52def CheckChangeOnCommit(input_api, output_api):
Christoffer Jansson4e8a7732022-02-08 09:01:12 +010053 results = []
54 results.extend(_CommonChecks(input_api, output_api))
55 return results