OLD | NEW |
---|---|
1 # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 1 # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
2 # | 2 # |
3 # Use of this source code is governed by a BSD-style license | 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 | 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 | 5 # tree. An additional intellectual property rights grant can be found |
6 # in the file PATENTS. All contributing project authors may | 6 # in the file PATENTS. All contributing project authors may |
7 # be found in the AUTHORS file in the root of the source tree. | 7 # be found in the AUTHORS file in the root of the source tree. |
8 | 8 |
9 import subprocess | |
10 | |
11 | |
12 def _RunCommand(command, cwd): | |
13 """Runs a command and returns the output from that command.""" | |
14 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | |
15 cwd=cwd) | |
16 stdout = p.stdout.read() | |
17 stderr = p.stderr.read() | |
18 p.wait() | |
19 p.stdout.close() | |
20 p.stderr.close() | |
21 return p.returncode, stdout, stderr | |
22 | |
9 def _LicenseHeader(input_api): | 23 def _LicenseHeader(input_api): |
10 """Returns the license header regexp.""" | 24 """Returns the license header regexp.""" |
11 # Accept any year number from 2003 to the current year | 25 # Accept any year number from 2003 to the current year |
12 current_year = int(input_api.time.strftime('%Y')) | 26 current_year = int(input_api.time.strftime('%Y')) |
13 allowed_years = (str(s) for s in reversed(xrange(2003, current_year + 1))) | 27 allowed_years = (str(s) for s in reversed(xrange(2003, current_year + 1))) |
14 years_re = '(' + '|'.join(allowed_years) + ')' | 28 years_re = '(' + '|'.join(allowed_years) + ')' |
15 license_header = ( | 29 license_header = ( |
16 r'.*? Copyright( \(c\))? %(year)s The WebRTC [Pp]roject [Aa]uthors\. ' | 30 r'.*? Copyright( \(c\))? %(year)s The WebRTC [Pp]roject [Aa]uthors\. ' |
17 r'All [Rr]ights [Rr]eserved\.\n' | 31 r'All [Rr]ights [Rr]eserved\.\n' |
18 r'.*?\n' | 32 r'.*?\n' |
19 r'.*? Use of this source code is governed by a BSD-style license\n' | 33 r'.*? Use of this source code is governed by a BSD-style license\n' |
20 r'.*? that can be found in the LICENSE file in the root of the source\n' | 34 r'.*? that can be found in the LICENSE file in the root of the source\n' |
21 r'.*? tree\. An additional intellectual property rights grant can be ' | 35 r'.*? tree\. An additional intellectual property rights grant can be ' |
22 r'found\n' | 36 r'found\n' |
23 r'.*? in the file PATENTS\. All contributing project authors may\n' | 37 r'.*? in the file PATENTS\. All contributing project authors may\n' |
24 r'.*? be found in the AUTHORS file in the root of the source tree\.\n' | 38 r'.*? be found in the AUTHORS file in the root of the source tree\.\n' |
25 ) % { | 39 ) % { |
26 'year': years_re, | 40 'year': years_re, |
27 } | 41 } |
28 return license_header | 42 return license_header |
29 | 43 |
44 def _CheckPackageBoundariesTest(input_api, output_api): | |
kjellander_webrtc
2017/01/19 10:51:26
Please remove this and make the test use the Pytho
| |
45 """Checks that check_package_boundaries.py is working correctly.""" | |
46 cwd = input_api.PresubmitLocalPath() | |
47 command = ['python', 'check_package_boundaries_test.py'] | |
48 returncode, _, stderr = _RunCommand(command, cwd) | |
49 if returncode: | |
50 return [output_api.PresubmitError( | |
51 'check_package_boundaries test failed:\n\n' | |
52 '%s' % stderr)] | |
53 return [] | |
54 | |
30 def _CommonChecks(input_api, output_api): | 55 def _CommonChecks(input_api, output_api): |
31 """Checks common to both upload and commit.""" | 56 """Checks common to both upload and commit.""" |
32 results = [] | 57 results = [] |
33 results.extend(input_api.canned_checks.CheckLicense( | 58 results.extend(input_api.canned_checks.CheckLicense( |
34 input_api, output_api, _LicenseHeader(input_api))) | 59 input_api, output_api, _LicenseHeader(input_api))) |
60 results.extend(_CheckPackageBoundariesTest(input_api, output_api)) | |
35 return results | 61 return results |
36 | 62 |
37 def CheckChangeOnUpload(input_api, output_api): | 63 def CheckChangeOnUpload(input_api, output_api): |
38 results = [] | 64 results = [] |
39 results.extend(_CommonChecks(input_api, output_api)) | 65 results.extend(_CommonChecks(input_api, output_api)) |
40 return results | 66 return results |
41 | 67 |
42 def CheckChangeOnCommit(input_api, output_api): | 68 def CheckChangeOnCommit(input_api, output_api): |
43 results = [] | 69 results = [] |
44 results.extend(_CommonChecks(input_api, output_api)) | 70 results.extend(_CommonChecks(input_api, output_api)) |
45 return results | 71 return results |
OLD | NEW |