From bf157d2fe534ca3f496da0a606b68c9cfb666660 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Thu, 11 Jan 2018 13:39:14 -0600 Subject: [PATCH] enhanced boilerplate checking Signed-off-by: Mike Brown --- hack/boilerplate/boilerplate.Dockerfile.txt | 3 +- hack/boilerplate/boilerplate.Makefile.txt | 3 +- hack/boilerplate/boilerplate.go.txt | 3 +- hack/boilerplate/boilerplate.py | 50 ++++++++++++++++++--- hack/boilerplate/boilerplate.py.txt | 3 +- hack/boilerplate/boilerplate.sh.txt | 3 +- hack/update-proto.sh | 3 +- 7 files changed, 50 insertions(+), 18 deletions(-) diff --git a/hack/boilerplate/boilerplate.Dockerfile.txt b/hack/boilerplate/boilerplate.Dockerfile.txt index 384f325ab..f7b7dee73 100644 --- a/hack/boilerplate/boilerplate.Dockerfile.txt +++ b/hack/boilerplate/boilerplate.Dockerfile.txt @@ -1,4 +1,4 @@ -# Copyright YEAR The Kubernetes Authors. +# Copyright YEAR AUTHORS. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/hack/boilerplate/boilerplate.Makefile.txt b/hack/boilerplate/boilerplate.Makefile.txt index 384f325ab..f7b7dee73 100644 --- a/hack/boilerplate/boilerplate.Makefile.txt +++ b/hack/boilerplate/boilerplate.Makefile.txt @@ -1,4 +1,4 @@ -# Copyright YEAR The Kubernetes Authors. +# Copyright YEAR AUTHORS. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/hack/boilerplate/boilerplate.go.txt b/hack/boilerplate/boilerplate.go.txt index 59e740c1e..4c70526f8 100644 --- a/hack/boilerplate/boilerplate.go.txt +++ b/hack/boilerplate/boilerplate.go.txt @@ -1,5 +1,5 @@ /* -Copyright YEAR The Kubernetes Authors. +Copyright YEAR AUTHORS. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,4 +13,3 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - diff --git a/hack/boilerplate/boilerplate.py b/hack/boilerplate/boilerplate.py index 448fe68b4..cdd73ba11 100755 --- a/hack/boilerplate/boilerplate.py +++ b/hack/boilerplate/boilerplate.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # Copyright 2015 The Kubernetes Authors. +# Copyright 2018 The Containerd Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -100,21 +101,52 @@ def file_passes(filename, refs, regexs): file=verbose_out) return False - # trim our file to the same number of lines as the reference file - data = data[:len(ref)] - p = regexs["year"] - for d in data: + found = 0 + for d in ref: if p.search(d): - print('File %s is missing the year' % filename, file=verbose_out) - return False + found = 1 + break + if found == 0: + print('File %s is missing the year' % filename, file=verbose_out) + return False # Replace all occurrences of the regex "CURRENT_YEAR|...|2016|2015|2014" with "YEAR" p = regexs["date"] for i, d in enumerate(data): (data[i], found) = p.subn('YEAR', d) - if found != 0: + + p = regexs["authors"] + found = 0 + for d in ref: + if p.search(d): + found = 1 break + if found == 0: + print('File %s is missing AUTHORS' % filename, file=verbose_out) + return False + + # Replace all occurrences of the regex "The validNameHere Authors" with "AUTHORS" + p = regexs["auth"] + for i, d in enumerate(data): + (data[i], found) = p.subn('AUTHORS', d) + + # Remove extra copyright notices only one is necessary + p = regexs["copyright"] + keepgoing = 1 + while keepgoing == 1: + keepgoing = 0 + count = 0 + for d in data: + if p.search(d): + count = count + 1 + if count > 1: + keepgoing = 1 + data.remove(d) + break + + # trim our file to the same number of lines as the reference file + data = data[:len(ref)] # if we don't match the reference at this point, fail if ref != data: @@ -185,6 +217,10 @@ def get_regexs(): regexs["go_build_constraints"] = re.compile(r"^(// \+build.*\n)+\n", re.MULTILINE) # strip #!.* from shell scripts regexs["shebang"] = re.compile(r"^(#!.*\n)\n*", re.MULTILINE) + regexs["authors"] = re.compile( 'AUTHORS' ) + authors = [ 'The Kubernetes Authors', 'The Containerd Authors' ] + regexs["auth"] = re.compile( '(%s)' % "|".join(map(lambda l: str(l), authors)) ) + regexs["copyright"] = re.compile( 'Copyright YEAR AUTHORS' ) return regexs def main(): diff --git a/hack/boilerplate/boilerplate.py.txt b/hack/boilerplate/boilerplate.py.txt index 384f325ab..f7b7dee73 100644 --- a/hack/boilerplate/boilerplate.py.txt +++ b/hack/boilerplate/boilerplate.py.txt @@ -1,4 +1,4 @@ -# Copyright YEAR The Kubernetes Authors. +# Copyright YEAR AUTHORS. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/hack/boilerplate/boilerplate.sh.txt b/hack/boilerplate/boilerplate.sh.txt index 384f325ab..f7b7dee73 100644 --- a/hack/boilerplate/boilerplate.sh.txt +++ b/hack/boilerplate/boilerplate.sh.txt @@ -1,4 +1,4 @@ -# Copyright YEAR The Kubernetes Authors. +# Copyright YEAR AUTHORS. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/hack/update-proto.sh b/hack/update-proto.sh index 0c2564133..b330d6195 100755 --- a/hack/update-proto.sh +++ b/hack/update-proto.sh @@ -1,6 +1,7 @@ #!/bin/bash # Copyright 2017 The Kubernetes Authors. +# Copyright 2018 The Containerd Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,7 +26,7 @@ go get k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo if ! which protoc-gen-gogo >/dev/null; then echo "GOPATH is not in PATH" exit 1 -fi +fi function cleanup { rm -f ${API_ROOT}/api.pb.go.bak