1 # 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 26 # List of files that should not be committed to 27 DO_NOT_SUBMIT_FILES = [ 28 "talk/app/webrtc/mediaconstraintsinterface.h", 29 "talk/app/webrtc/webrtcsdp_unittest.cc", 30 "talk/base/linux.cc", 31 "talk/base/linux.h", 32 "talk/base/linux_unittest.cc", 33 "talk/main.scons", 34 "talk/media/base/hybridvideoengine.cc", 35 "talk/media/base/mediaengine.cc", 36 "talk/media/base/mutedvideocapturer.cc", 37 "talk/media/base/streamparams.h", 38 "talk/media/base/videocapturer.cc", 39 "talk/media/base/videocapturer.h", 40 "talk/media/base/videocapturer_unittest.cc", 41 "talk/media/base/videoengine_unittest.h", 42 "talk/media/devices/devicemanager.cc", 43 "talk/media/webrtc/fakewebrtcvideoengine.h", 44 "talk/media/webrtc/fakewebrtcvoiceengine.h", 45 "talk/media/webrtc/webrtcexport.h", 46 "talk/media/webrtc/webrtcmediaengine.h", 47 "talk/media/webrtc/webrtcvideoengine.cc", 48 "talk/media/webrtc/webrtcvideoengine.h", 49 "talk/media/webrtc/webrtcvideoengine_unittest.cc", 50 "talk/media/webrtc/webrtcvoiceengine.cc", 51 "talk/media/webrtc/webrtcvoiceengine.h", 52 "talk/media/webrtc/webrtcvoiceengine_unittest.cc", 53 "talk/p2p/base/session.cc", 54 "talk/session/media/channel.cc", 55 "talk/session/media/mediasession_unittest.cc"] 56 57 def _LicenseHeader(input_api): 58 """Returns the license header regexp.""" 59 # Accept any year number from start of project to the current year 60 current_year = int(input_api.time.strftime('%Y')) 61 allowed_years = (str(s) for s in reversed(xrange(2004, current_year + 1))) 62 years_re = '(' + '|'.join(allowed_years) + ')' 63 license_header = ( 64 r'.*? libjingle\n' 65 r'.*? Copyright %(year)s,? Google Inc\.\n' 66 r'.*?\n' 67 r'.*? Redistribution and use in source and binary forms, with or without' 68 r'\n' 69 r'.*? modification, are permitted provided that the following conditions ' 70 r'are met:\n' 71 r'.*?\n' 72 r'.*? 1\. Redistributions of source code must retain the above copyright ' 73 r'notice,\n' 74 r'.*? this list of conditions and the following disclaimer\.\n' 75 r'.*? 2\. Redistributions in binary form must reproduce the above ' 76 r'copyright notice,\n' 77 r'.*? this list of conditions and the following disclaimer in the ' 78 r'documentation\n' 79 r'.*? and/or other materials provided with the distribution\.\n' 80 r'.*? 3\. The name of the author may not be used to endorse or promote ' 81 r'products\n' 82 r'.*? derived from this software without specific prior written ' 83 r'permission\.\n' 84 r'.*?\n' 85 r'.*? THIS SOFTWARE IS PROVIDED BY THE AUTHOR \`\`AS IS\'\' AND ANY ' 86 r'EXPRESS OR IMPLIED\n' 87 r'.*? WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ' 88 r'OF\n' 89 r'.*? MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ' 90 r'DISCLAIMED\. IN NO\n' 91 r'.*? EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, ' 92 r'INCIDENTAL,\n' 93 r'.*? SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \(INCLUDING, ' 94 r'BUT NOT LIMITED TO,\n' 95 r'.*? PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ' 96 r'PROFITS;\n' 97 r'.*? OR BUSINESS INTERRUPTION\) HOWEVER CAUSED AND ON ANY THEORY OF ' 98 r'LIABILITY,\n' 99 r'.*? WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \(INCLUDING ' 100 r'NEGLIGENCE OR\n' 101 r'.*? OTHERWISE\) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ' 102 r'EVEN IF\n' 103 r'.*? ADVISED OF THE POSSIBILITY OF SUCH DAMAGE\.\n' 104 ) % { 105 'year': years_re, 106 } 107 return license_header 108 109 def _ProtectedFiles(input_api, output_api): 110 results = [] 111 changed_files = [] 112 for f in input_api.AffectedFiles(): 113 changed_files.append(f.LocalPath()) 114 bad_files = list(set(DO_NOT_SUBMIT_FILES) & set(changed_files)) 115 if bad_files: 116 error_type = output_api.PresubmitError 117 results.append(error_type( 118 'The following affected files are only allowed to be updated when ' 119 'importing libjingle', 120 bad_files)) 121 return results 122 123 def _CommonChecks(input_api, output_api): 124 """Checks common to both upload and commit.""" 125 results = [] 126 results.extend(input_api.canned_checks.CheckLicense( 127 input_api, output_api, _LicenseHeader(input_api))) 128 results.extend(_ProtectedFiles(input_api, output_api)) 129 return results 130 131 def CheckChangeOnUpload(input_api, output_api): 132 results = [] 133 results.extend(_CommonChecks(input_api, output_api)) 134 return results 135 136 def CheckChangeOnCommit(input_api, output_api): 137 results = [] 138 results.extend(_CommonChecks(input_api, output_api)) 139 return results 140