blob: c2dfd0e6fd2635b83efb60f7e20f4ad4aa759869 [file] [log] [blame]
Henrik Kjellanderb5ffc142016-12-15 08:48:521# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
2#
3# Use of this source code is governed by a BSD-style license
4# that can be found in the LICENSE file in the root of the source
5# tree. An additional intellectual property rights grant can be found
6# in the file PATENTS. All contributing project authors may
7# be found in the AUTHORS file in the root of the source tree.
8
Edward Lemur27b2c9a2018-02-01 14:23:339import os
10
11
Henrik Kjellanderb5ffc142016-12-15 08:48:5212def _LicenseHeader(input_api):
13 """Returns the license header regexp."""
14 # Accept any year number from 2003 to the current year
15 current_year = int(input_api.time.strftime('%Y'))
16 allowed_years = (str(s) for s in reversed(xrange(2003, current_year + 1)))
17 years_re = '(' + '|'.join(allowed_years) + ')'
18 license_header = (
19 r'.*? Copyright( \(c\))? %(year)s The WebRTC [Pp]roject [Aa]uthors\. '
20 r'All [Rr]ights [Rr]eserved\.\n'
21 r'.*?\n'
22 r'.*? Use of this source code is governed by a BSD-style license\n'
23 r'.*? that can be found in the LICENSE file in the root of the source\n'
24 r'.*? tree\. An additional intellectual property rights grant can be '
25 r'found\n'
26 r'.*? in the file PATENTS\. All contributing project authors may\n'
27 r'.*? be found in the AUTHORS file in the root of the source tree\.\n'
28 ) % {
29 'year': years_re,
30 }
31 return license_header
32
Edward Lemur27b2c9a2018-02-01 14:23:3333def _CheckValgrindFiles(input_api, output_api):
34 """Check that valgrind-webrtc.gni contains all existing files."""
35 valgrind_dir = os.path.join('tools_webrtc', 'valgrind')
36 with open(os.path.join('valgrind', 'valgrind-webrtc.gni')) as f:
37 valgrind_webrtc = f.read()
38
39 results = []
40 for f in input_api.AffectedFiles():
41 f = f.LocalPath()
42 if (f.startswith(valgrind_dir)
43 and f not in valgrind_webrtc
44 and not f.endswith('valgrind-webrtc.gni')):
45 results.append(' * %s\n' % f)
46
47 if results:
48 results = [output_api.PresubmitError(
49 'The following files are not listed in '
50 'tools_webrtc/valgrind/valgrind-webrt.gni. Please add them, so they can '
51 'be isolated and uploaded to swarming:\n' +
52 ''.join(file_path for file_path in results))]
53 return results
54
Henrik Kjellanderb5ffc142016-12-15 08:48:5255def _CommonChecks(input_api, output_api):
56 """Checks common to both upload and commit."""
57 results = []
58 results.extend(input_api.canned_checks.CheckLicense(
59 input_api, output_api, _LicenseHeader(input_api)))
Edward Lemur27b2c9a2018-02-01 14:23:3360 results.extend(_CheckValgrindFiles(input_api, output_api))
Henrik Kjellanderb5ffc142016-12-15 08:48:5261 return results
62
63def CheckChangeOnUpload(input_api, output_api):
64 results = []
65 results.extend(_CommonChecks(input_api, output_api))
66 return results
67
68def CheckChangeOnCommit(input_api, output_api):
69 results = []
70 results.extend(_CommonChecks(input_api, output_api))
71 return results