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