diff --git a/hack/boilerplate/boilerplate.py b/hack/boilerplate/boilerplate.py index 89224186aca..eaf758b9fe5 100755 --- a/hack/boilerplate/boilerplate.py +++ b/hack/boilerplate/boilerplate.py @@ -62,10 +62,6 @@ def get_refs(): def is_generated_file(filename, data, regexs): - for d in skipped_ungenerated_files: - if d in filename: - return False - p = regexs["generated"] return p.search(data) @@ -151,21 +147,15 @@ def file_extension(filename): return os.path.splitext(filename)[1].split(".")[-1].lower() -skipped_dirs = ['third_party', '_gopath', '_output', '.git', 'cluster/env.sh', - "vendor", "test/e2e/generated/bindata.go", "hack/boilerplate/test", - "staging/src/k8s.io/kubectl/pkg/generated/bindata.go"] - -# list all the files contain 'DO NOT EDIT', but are not generated -skipped_ungenerated_files = [ - 'hack/update-generated-swagger-docs.sh', - 'hack/boilerplate/boilerplate.py' -] +skipped_names = ['third_party', '_gopath', '_output', '.git', 'cluster/env.sh', + "vendor", "test/e2e/generated/bindata.go", "hack/boilerplate/test", + "staging/src/k8s.io/kubectl/pkg/generated/bindata.go"] def normalize_files(files): newfiles = [] for pathname in files: - if any(x in pathname for x in skipped_dirs): + if any(x in pathname for x in skipped_names): continue newfiles.append(pathname) for i, pathname in enumerate(newfiles): @@ -184,9 +174,13 @@ def get_files(extensions): # as we would prune these later in normalize_files(). But doing it # cuts down the amount of filesystem walking we do and cuts down # the size of the file list - for d in skipped_dirs: + for d in skipped_names: if d in dirs: dirs.remove(d) + for d in dirs: + # dirs that start with __ are ignored + if re.match("^__", d): + dirs.remove(d) for name in walkfiles: pathname = os.path.join(root, name) @@ -222,7 +216,7 @@ def get_regexs(): # strip #!.* from scripts regexs["shebang"] = re.compile(r"^(#!.*\n)\n*", re.MULTILINE) # Search for generated files - regexs["generated"] = re.compile('DO NOT EDIT') + regexs["generated"] = re.compile(r"^[/*#]+ +.* DO NOT EDIT\.$", re.MULTILINE) return regexs diff --git a/hack/update-generated-swagger-docs.sh b/hack/update-generated-swagger-docs.sh index dedf8e7db42..545f7f0a850 100755 --- a/hack/update-generated-swagger-docs.sh +++ b/hack/update-generated-swagger-docs.sh @@ -41,19 +41,21 @@ gen_types_swagger_doc() { { echo -e "$(cat hack/boilerplate/boilerplate.generatego.txt)\n" echo "package ${group_version##*/}" + # Indenting here prevents the boilerplate checker from thinking this file + # is generated - gofmt will fix the indents anyway. cat < "${TMPFILE}"