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