Add copyright checks to sanity; make them verify copyright year is valid

pull/4604/head
Craig Tiller 9 years ago
parent 418411f75d
commit de3da74866
  1. 2
      include/grpc++/security/credentials.h
  2. 2
      src/core/security/jwt_verifier.c
  3. 62
      src/php/ext/grpc/LICENSE
  4. 98
      tools/distrib/check_copyright.py
  5. 1
      tools/run_tests/run_sanity.sh

@ -1,6 +1,6 @@
/* /*
* *
* Copyright 2015, Google Inc. * Copyright 2015-2016, Google Inc.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

@ -1,6 +1,6 @@
/* /*
* *
* Copyright 2015, Google Inc. * Copyright 2015-2016, Google Inc.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

@ -1,32 +1,30 @@
/* Copyright 2015, Google Inc.
* All rights reserved.
* Copyright 2015, Google Inc.
* All rights reserved. Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* Redistribution and use in source and binary forms, with or without met:
* modification, are permitted provided that the following conditions are
* met: * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions of source code must retain the above copyright * Redistributions in binary form must reproduce the above
* notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer
* * Redistributions in binary form must reproduce the above in the documentation and/or other materials provided with the
* copyright notice, this list of conditions and the following disclaimer distribution.
* in the documentation and/or other materials provided with the * Neither the name of Google Inc. nor the names of its
* distribution. contributors may be used to endorse or promote products derived from
* * Neither the name of Google Inc. nor the names of its this software without specific prior written permission.
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

@ -1,6 +1,6 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
# Copyright 2015, Google Inc. # Copyright 2015-2016, Google Inc.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -30,7 +30,9 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import argparse import argparse
import datetime
import os import os
import re
import sys import sys
import subprocess import subprocess
@ -52,10 +54,6 @@ argp.add_argument('-a', '--ancient',
default=0, default=0,
action='store_const', action='store_const',
const=1) const=1)
argp.add_argument('-f', '--fix',
default=0,
action='store_const',
const=1)
args = argp.parse_args() args = argp.parse_args()
# open the license text # open the license text
@ -66,34 +64,46 @@ with open('LICENSE') as f:
# key is the file extension, value is a format string # key is the file extension, value is a format string
# that given a line of license text, returns what should # that given a line of license text, returns what should
# be in the file # be in the file
LICENSE_FMT = { LICENSE_PREFIX = {
'.c': ' * %s', '.c': r'\s*\*\s*',
'.cc': ' * %s', '.cc': r'\s*\*\s*',
'.h': ' * %s', '.h': r'\s*\*\s*',
'.m': ' * %s', '.m': r'\s*\*\s*',
'.php': ' * %s', '.php': r'\s*\*\s*',
'.py': '# %s', '.js': r'\s*\*\s*',
'.rb': '# %s', '.py': r'#\s*',
'.sh': '# %s', '.rb': r'#\s*',
'.proto': '// %s', '.sh': r'#\s*',
'.js': ' * %s', '.proto': r'//\s*',
'.cs': '// %s', '.cs': r'//\s*',
'.mak': '# %s', '.mak': r'#\s*',
'Makefile': '# %s', 'Makefile': r'#\s*',
'Dockerfile': '# %s', 'Dockerfile': r'#\s*',
'LICENSE': '',
} }
KNOWN_BAD = set([ KNOWN_BAD = set([
'src/php/tests/bootstrap.php', 'src/php/tests/bootstrap.php',
]) ])
# pregenerate the actual text that we should have
LICENSE_TEXT = dict(
(k, '\n'.join((v % line).rstrip() for line in LICENSE))
for k, v in LICENSE_FMT.iteritems())
OLD_LICENSE_TEXT = dict( RE_YEAR = r'Copyright (?:[0-9]+\-)?([0-9]+), Google Inc\.'
(k, v.replace('2015', '2014')) for k, v in LICENSE_TEXT.iteritems()) RE_LICENSE = dict(
(k, r'\n'.join(
LICENSE_PREFIX[k] +
(RE_YEAR if re.search(RE_YEAR, line) else re.escape(line))
for line in LICENSE))
for k, v in LICENSE_PREFIX.iteritems())
def load(name):
with open(name) as f:
return '\n'.join(line.rstrip() for line in f.read().splitlines())
assert(re.search(RE_LICENSE['LICENSE'], load('LICENSE')))
assert(re.search(RE_LICENSE['Makefile'], load('Makefile')))
def log(cond, why, filename): def log(cond, why, filename):
if not cond: return if not cond: return
@ -102,30 +112,32 @@ def log(cond, why, filename):
else: else:
print filename print filename
# scan files, validate the text # scan files, validate the text
for filename in subprocess.check_output('git ls-tree -r --name-only -r HEAD', for filename in subprocess.check_output('git ls-tree -r --name-only -r HEAD',
shell=True).splitlines(): shell=True).splitlines():
if filename in KNOWN_BAD: continue if filename in KNOWN_BAD: continue
ext = os.path.splitext(filename)[1] ext = os.path.splitext(filename)[1]
base = os.path.basename(filename) base = os.path.basename(filename)
if ext in LICENSE_TEXT: if ext in RE_LICENSE:
license = LICENSE_TEXT[ext] re_license = RE_LICENSE[ext]
old_license = OLD_LICENSE_TEXT[ext] elif base in RE_LICENSE:
elif base in LICENSE_TEXT: re_license = RE_LICENSE[base]
license = LICENSE_TEXT[base]
old_license = OLD_LICENSE_TEXT[base]
else: else:
log(args.skips, 'skip', filename) log(args.skips, 'skip', filename)
continue continue
with open(filename) as f: text = load(filename)
text = '\n'.join(line.rstrip() for line in f.read().splitlines()) ok = True
if license in text: m = re.search(re_license, text)
pass if m:
elif old_license in text: last_modified = int(subprocess.check_output('git log -1 --format="%ad" --date=short -- ' + filename, shell=True)[0:4])
log(args.ancient, 'old', filename) latest_claimed = int(m.group(1))
if args.fix: if last_modified > latest_claimed:
with open(filename, 'w') as f: print '%s modified %d but copyright only extends to %d' % (filename, last_modified, latest_claimed)
f.write(text.replace('Copyright 2014, Google Inc.', 'Copyright 2015, Google Inc.') + '\n') ok = False
elif 'DO NOT EDIT' not in text and 'AssemblyInfo.cs' not in filename: elif 'DO NOT EDIT' not in text and 'AssemblyInfo.cs' not in filename and filename != 'src/boringssl/err_data.c':
log(1, 'missing', filename) log(1, 'copyright missing', filename)
ok = False
sys.exit(0 if ok else 1)

@ -58,5 +58,6 @@ if [ -f cache.mk ] ; then
fi fi
./tools/buildgen/generate_projects.sh ./tools/buildgen/generate_projects.sh
./tools/distrib/check_copyright.py
./tools/distrib/clang_format_code.sh ./tools/distrib/clang_format_code.sh

Loading…
Cancel
Save