blob: aa46bb4ae18fbffe8cf5c2ff0964558bd60c5993 [file] [log] [blame]
henrike@webrtc.org390fcb72013-07-22 22:32:50 +00001# libjingle
2# Copyright 2013 Google Inc.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#
7# 1. Redistributions of source code must retain the above copyright notice,
8# this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright notice,
10# this list of conditions and the following disclaimer in the documentation
11# and/or other materials provided with the distribution.
12# 3. The name of the author may not be used to endorse or promote products
13# derived from this software without specific prior written permission.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
henrike@webrtc.orgea40bd02013-07-29 18:20:07 +000026# List of files that should not be committed to
27DO_NOT_SUBMIT_FILES = [
henrike@webrtc.orgea40bd02013-07-29 18:20:07 +000028 "talk/media/base/mutedvideocapturer.cc",
henrike@webrtc.orgea40bd02013-07-29 18:20:07 +000029 "talk/media/base/videocapturer.cc",
30 "talk/media/base/videocapturer.h",
31 "talk/media/base/videocapturer_unittest.cc",
32 "talk/media/base/videoengine_unittest.h",
33 "talk/media/devices/devicemanager.cc",
34 "talk/media/webrtc/fakewebrtcvideoengine.h",
35 "talk/media/webrtc/fakewebrtcvoiceengine.h",
36 "talk/media/webrtc/webrtcexport.h",
37 "talk/media/webrtc/webrtcmediaengine.h",
38 "talk/media/webrtc/webrtcvideoengine.cc",
39 "talk/media/webrtc/webrtcvideoengine.h",
40 "talk/media/webrtc/webrtcvideoengine_unittest.cc",
41 "talk/media/webrtc/webrtcvoiceengine.cc",
42 "talk/media/webrtc/webrtcvoiceengine.h",
43 "talk/media/webrtc/webrtcvoiceengine_unittest.cc",
henrike@webrtc.orgaeb0c282014-04-17 14:15:43 +000044 "talk/session/media/channel.cc"]
henrike@webrtc.orgea40bd02013-07-29 18:20:07 +000045
henrike@webrtc.org390fcb72013-07-22 22:32:50 +000046def _LicenseHeader(input_api):
47 """Returns the license header regexp."""
fischman@webrtc.orgc3d93c62013-08-05 15:01:33 +000048 # Accept any year number from start of project to the current year
henrike@webrtc.org390fcb72013-07-22 22:32:50 +000049 current_year = int(input_api.time.strftime('%Y'))
fischman@webrtc.orgc3d93c62013-08-05 15:01:33 +000050 allowed_years = (str(s) for s in reversed(xrange(2004, current_year + 1)))
henrike@webrtc.org390fcb72013-07-22 22:32:50 +000051 years_re = '(' + '|'.join(allowed_years) + ')'
52 license_header = (
53 r'.*? libjingle\n'
fischman@webrtc.org33584f92013-07-25 16:43:30 +000054 r'.*? Copyright %(year)s,? Google Inc\.\n'
henrike@webrtc.org390fcb72013-07-22 22:32:50 +000055 r'.*?\n'
56 r'.*? Redistribution and use in source and binary forms, with or without'
57 r'\n'
58 r'.*? modification, are permitted provided that the following conditions '
59 r'are met:\n'
60 r'.*?\n'
61 r'.*? 1\. Redistributions of source code must retain the above copyright '
62 r'notice,\n'
63 r'.*? this list of conditions and the following disclaimer\.\n'
64 r'.*? 2\. Redistributions in binary form must reproduce the above '
65 r'copyright notice,\n'
66 r'.*? this list of conditions and the following disclaimer in the '
67 r'documentation\n'
68 r'.*? and/or other materials provided with the distribution\.\n'
69 r'.*? 3\. The name of the author may not be used to endorse or promote '
70 r'products\n'
71 r'.*? derived from this software without specific prior written '
72 r'permission\.\n'
73 r'.*?\n'
74 r'.*? THIS SOFTWARE IS PROVIDED BY THE AUTHOR \`\`AS IS\'\' AND ANY '
75 r'EXPRESS OR IMPLIED\n'
76 r'.*? WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES '
77 r'OF\n'
78 r'.*? MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE '
79 r'DISCLAIMED\. IN NO\n'
80 r'.*? EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, '
81 r'INCIDENTAL,\n'
82 r'.*? SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \(INCLUDING, '
83 r'BUT NOT LIMITED TO,\n'
84 r'.*? PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR '
85 r'PROFITS;\n'
86 r'.*? OR BUSINESS INTERRUPTION\) HOWEVER CAUSED AND ON ANY THEORY OF '
87 r'LIABILITY,\n'
88 r'.*? WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \(INCLUDING '
89 r'NEGLIGENCE OR\n'
90 r'.*? OTHERWISE\) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, '
91 r'EVEN IF\n'
92 r'.*? ADVISED OF THE POSSIBILITY OF SUCH DAMAGE\.\n'
93 ) % {
94 'year': years_re,
95 }
96 return license_header
97
henrike@webrtc.orgea40bd02013-07-29 18:20:07 +000098def _ProtectedFiles(input_api, output_api):
99 results = []
100 changed_files = []
101 for f in input_api.AffectedFiles():
102 changed_files.append(f.LocalPath())
103 bad_files = list(set(DO_NOT_SUBMIT_FILES) & set(changed_files))
104 if bad_files:
105 error_type = output_api.PresubmitError
106 results.append(error_type(
107 'The following affected files are only allowed to be updated when '
108 'importing libjingle',
109 bad_files))
110 return results
111
henrike@webrtc.org390fcb72013-07-22 22:32:50 +0000112def _CommonChecks(input_api, output_api):
113 """Checks common to both upload and commit."""
114 results = []
115 results.extend(input_api.canned_checks.CheckLicense(
116 input_api, output_api, _LicenseHeader(input_api)))
henrike@webrtc.orgea40bd02013-07-29 18:20:07 +0000117 results.extend(_ProtectedFiles(input_api, output_api))
henrike@webrtc.org390fcb72013-07-22 22:32:50 +0000118 return results
119
120def CheckChangeOnUpload(input_api, output_api):
121 results = []
122 results.extend(_CommonChecks(input_api, output_api))
123 return results
124
125def CheckChangeOnCommit(input_api, output_api):
126 results = []
127 results.extend(_CommonChecks(input_api, output_api))
128 return results