diff --git a/build/root/Makefile.generated_files b/build/root/Makefile.generated_files index 669230c334..a743cfa503 100644 --- a/build/root/Makefile.generated_files +++ b/build/root/Makefile.generated_files @@ -158,8 +158,14 @@ $(foreach dir, $(ALL_GO_DIRS), \ FILES=$$(ls $$@.tmp; \ - cmp -s $@.tmp $@ || touch $@.stamp; \ + if ! cmp -s $@.tmp $@; then \ + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: gofiles changed for $@"; \ + fi; \ + touch $@.stamp; \ + fi; \ mv $@.tmp $@ + # This is required to fill in the DAG, since some cases (e.g. 'make clean all') # will reference the .stamp file when it doesn't exist. We don't need to # rebuild it in that case, just keep make happy. @@ -215,18 +221,22 @@ DEEPCOPY_DIRS := $(shell \ DEEPCOPY_FILES := $(addsuffix /$(DEEPCOPY_FILENAME), $(DEEPCOPY_DIRS)) # Shell function for reuse in rules. -RUN_GEN_DEEPCOPY = \ - function run_gen_deepcopy() { \ - if [[ -f $(META_DIR)/$(DEEPCOPY_GEN).todo ]]; then \ - ./hack/run-in-gopath.sh $(DEEPCOPY_GEN) \ - --v $(KUBE_VERBOSE) \ - --logtostderr \ - -i $$(cat $(META_DIR)/$(DEEPCOPY_GEN).todo | paste -sd, -) \ - --bounding-dirs $(PRJ_SRC_PATH),"k8s.io/api" \ - -O $(DEEPCOPY_BASENAME) \ - "$$@"; \ - fi \ - }; \ +RUN_GEN_DEEPCOPY = \ + function run_gen_deepcopy() { \ + if [[ -f $(META_DIR)/$(DEEPCOPY_GEN).todo ]]; then \ + pkgs=$$(cat $(META_DIR)/$(DEEPCOPY_GEN).todo | paste -sd, -); \ + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: running $(DEEPCOPY_GEN) for $$pkgs"; \ + fi; \ + ./hack/run-in-gopath.sh $(DEEPCOPY_GEN) \ + --v $(KUBE_VERBOSE) \ + --logtostderr \ + -i "$$pkgs" \ + --bounding-dirs $(PRJ_SRC_PATH),"k8s.io/api" \ + -O $(DEEPCOPY_BASENAME) \ + "$$@"; \ + fi \ + }; \ run_gen_deepcopy # This rule aggregates the set of files to generate and then generates them all @@ -263,6 +273,10 @@ $(shell rm -f $(META_DIR)/$(DEEPCOPY_GEN)*.todo) # it up and trigger the batch from the 'generated_files' target. $(DEEPCOPY_FILES): $(DEEPCOPY_GEN) mkdir -p $$(dirname $(META_DIR)/$(DEEPCOPY_GEN)) + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: deepcopy needed $(@D): $?"; \ + ls -lf --full-time $@ $? || true; \ + fi echo $(PRJ_SRC_PATH)/$(@D) >> $(META_DIR)/$(DEEPCOPY_GEN).todo # This calculates the dependencies for the generator tool, so we only rebuild @@ -274,7 +288,7 @@ $(META_DIR)/$(DEEPCOPY_GEN).mk: (echo -n "$(DEEPCOPY_GEN): "; \ ./hack/run-in-gopath.sh go list \ -f '{{.ImportPath}}{{"\n"}}{{range .Deps}}{{.}}{{"\n"}}{{end}}' \ - ./vendor/k8s.io/code-generator/cmd/deepcopy-gen \ + ./vendor/k8s.io/code-generator/cmd/deepcopy-gen \ | grep --color=never "^$(PRJ_SRC_PATH)/" \ | xargs ./hack/run-in-gopath.sh go list \ -f '{{$$d := .Dir}}{{$$d}}{{"\n"}}{{range .GoFiles}}{{$$d}}/{{.}}{{"\n"}}{{end}}' \ @@ -283,7 +297,13 @@ $(META_DIR)/$(DEEPCOPY_GEN).mk: | tr '=,' '\n\t' \ | sed "s|$$(pwd -P)/||"; \ ) > $@.tmp; \ - cmp -s $@.tmp $@ || cat $@.tmp > $@ && rm -f $@.tmp + if ! cmp -s $@.tmp $@; then \ + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: $(DEEPCOPY_GEN).mk changed"; \ + fi; \ + cat $@.tmp > $@; \ + rm -f $@.tmp; \ + fi # Include dependency info for the generator tool. This will cause the rule of # the same name to be considered and if it is updated, make will restart. @@ -339,18 +359,22 @@ DEFAULTER_DIRS := $(shell \ DEFAULTER_FILES := $(addsuffix /$(DEFAULTER_FILENAME), $(DEFAULTER_DIRS)) -RUN_GEN_DEFAULTER := \ - function run_gen_defaulter() { \ - if [[ -f $(META_DIR)/$(DEFAULTER_GEN).todo ]]; then \ - ./hack/run-in-gopath.sh $(DEFAULTER_GEN) \ - --v $(KUBE_VERBOSE) \ - --logtostderr \ - -i $$(cat $(META_DIR)/$(DEFAULTER_GEN).todo | paste -sd, -) \ +RUN_GEN_DEFAULTER := \ + function run_gen_defaulter() { \ + if [[ -f $(META_DIR)/$(DEFAULTER_GEN).todo ]]; then \ + pkgs=$$(cat $(META_DIR)/$(DEFAULTER_GEN).todo | paste -sd, -); \ + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: running $(DEFAULTER_GEN) for $$pkgs"; \ + fi; \ + ./hack/run-in-gopath.sh $(DEFAULTER_GEN) \ + --v $(KUBE_VERBOSE) \ + --logtostderr \ + -i "$$pkgs" \ --extra-peer-dirs $$(echo $(addprefix $(PRJ_SRC_PATH)/, $(DEFAULTER_DIRS)) | sed 's/ /,/g') \ - -O $(DEFAULTER_BASENAME) \ - "$$@"; \ - fi \ - }; \ + -O $(DEFAULTER_BASENAME) \ + "$$@"; \ + fi \ + }; \ run_gen_defaulter # This rule aggregates the set of files to generate and then generates them all @@ -413,6 +437,10 @@ $(shell rm -f $(META_DIR)/$(DEFAULTER_GEN)*.todo) # it up and trigger the batch from the 'generated_files' target. $(DEFAULTER_FILES): $(DEFAULTER_GEN) mkdir -p $$(dirname $(META_DIR)/$(DEFAULTER_GEN)) + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: defaulter needed $(@D): $?"; \ + ls -lf --full-time $@ $? || true; \ + fi echo $(PRJ_SRC_PATH)/$(@D) >> $(META_DIR)/$(DEFAULTER_GEN).todo # This calculates the dependencies for the generator tool, so we only rebuild @@ -424,7 +452,7 @@ $(META_DIR)/$(DEFAULTER_GEN).mk: (echo -n "$(DEFAULTER_GEN): "; \ ./hack/run-in-gopath.sh go list \ -f '{{.ImportPath}}{{"\n"}}{{range .Deps}}{{.}}{{"\n"}}{{end}}' \ - ./vendor/k8s.io/code-generator/cmd/defaulter-gen \ + ./vendor/k8s.io/code-generator/cmd/defaulter-gen \ | grep --color=never "^$(PRJ_SRC_PATH)/" \ | xargs ./hack/run-in-gopath.sh go list \ -f '{{$$d := .Dir}}{{$$d}}{{"\n"}}{{range .GoFiles}}{{$$d}}/{{.}}{{"\n"}}{{end}}' \ @@ -433,7 +461,13 @@ $(META_DIR)/$(DEFAULTER_GEN).mk: | tr '=,' '\n\t' \ | sed "s|$$(pwd -P)/||"; \ ) > $@.tmp; \ - cmp -s $@.tmp $@ || cat $@.tmp > $@ && rm -f $@.tmp + if ! cmp -s $@.tmp $@; then \ + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: $(DEFAULTER_GEN).mk changed"; \ + fi; \ + cat $@.tmp > $@; \ + rm -f $@.tmp; \ + fi # Include dependency info for the generator tool. This will cause the rule of # the same name to be considered and if it is updated, make will restart. @@ -522,7 +556,7 @@ $(META_DIR)/$(OPENAPI_GEN).mk: (echo -n "$(OPENAPI_GEN): "; \ ./hack/run-in-gopath.sh go list \ -f '{{.ImportPath}}{{"\n"}}{{range .Deps}}{{.}}{{"\n"}}{{end}}' \ - ./vendor/k8s.io/code-generator/cmd/openapi-gen \ + ./vendor/k8s.io/code-generator/cmd/openapi-gen \ | grep --color=never "^$(PRJ_SRC_PATH)/" \ | xargs ./hack/run-in-gopath.sh go list \ -f '{{$$d := .Dir}}{{$$d}}{{"\n"}}{{range .GoFiles}}{{$$d}}/{{.}}{{"\n"}}{{end}}' \ @@ -531,7 +565,13 @@ $(META_DIR)/$(OPENAPI_GEN).mk: | tr '=,' '\n\t' \ | sed "s|$$(pwd -P)/||"; \ ) > $@.tmp; \ - cmp -s $@.tmp $@ || cat $@.tmp > $@ && rm -f $@.tmp + if ! cmp -s $@.tmp $@; then \ + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: $(OPENAPI_GEN).mk changed"; \ + fi; \ + cat $@.tmp > $@; \ + rm -f $@.tmp; \ + fi # Include dependency info for the generator tool. This will cause the rule of # the same name to be considered and if it is updated, make will restart. @@ -590,17 +630,21 @@ CONVERSION_DIRS := $(shell \ CONVERSION_FILES := $(addsuffix /$(CONVERSION_FILENAME), $(CONVERSION_DIRS)) # Shell function for reuse in rules. -RUN_GEN_CONVERSION = \ - function run_gen_conversion() { \ - if [[ -f $(META_DIR)/$(CONVERSION_GEN).todo ]]; then \ - ./hack/run-in-gopath.sh $(CONVERSION_GEN) \ - --v $(KUBE_VERBOSE) \ - --logtostderr \ - -i $$(cat $(META_DIR)/$(CONVERSION_GEN).todo | paste -sd, -) \ - -O $(CONVERSION_BASENAME) \ - "$$@"; \ - fi \ - }; \ +RUN_GEN_CONVERSION = \ + function run_gen_conversion() { \ + if [[ -f $(META_DIR)/$(CONVERSION_GEN).todo ]]; then \ + pkgs=$$(cat $(META_DIR)/$(CONVERSION_GEN).todo | paste -sd, -); \ + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: running $(CONVERSION_GEN) for $$pkgs"; \ + fi; \ + ./hack/run-in-gopath.sh $(CONVERSION_GEN) \ + --v $(KUBE_VERBOSE) \ + --logtostderr \ + -i "$$pkgs" \ + -O $(CONVERSION_BASENAME) \ + "$$@"; \ + fi \ + }; \ run_gen_conversion # This rule aggregates the set of files to generate and then generates them all @@ -644,7 +688,12 @@ $(foreach dir, $(CONVERSION_DIRS), \ | sed 's|$(PRJ_SRC_PATH)/||'); \ mkdir -p $(@D); \ echo "conversions__$< := $$(echo $${TAGS})" >$@.tmp; \ - cmp -s $@.tmp $@ || touch $@.stamp; \ + if ! cmp -s $@.tmp $@; then \ + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: conversions changed for $@"; \ + fi; \ + touch $@.stamp; \ + fi; \ mv $@.tmp $@ # Include any deps files as additional Makefile rules. This triggers make to @@ -705,6 +754,10 @@ $(shell rm -f $(META_DIR)/$(CONVERSION_GEN)*.todo) # it up and trigger the batch from the 'generated_files' target. $(CONVERSION_FILES): $(CONVERSION_GEN) mkdir -p $$(dirname $(META_DIR)/$(CONVERSION_GEN)) + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: conversion needed $(@D): $?"; \ + ls -lf --full-time $@ $? || true; \ + fi echo $(PRJ_SRC_PATH)/$(@D) >> $(META_DIR)/$(CONVERSION_GEN).todo # This calculates the dependencies for the generator tool, so we only rebuild @@ -716,7 +769,7 @@ $(META_DIR)/$(CONVERSION_GEN).mk: (echo -n "$(CONVERSION_GEN): "; \ ./hack/run-in-gopath.sh go list \ -f '{{.ImportPath}}{{"\n"}}{{range .Deps}}{{.}}{{"\n"}}{{end}}' \ - ./vendor/k8s.io/code-generator/cmd/conversion-gen \ + ./vendor/k8s.io/code-generator/cmd/conversion-gen \ | grep --color=never "^$(PRJ_SRC_PATH)/" \ | xargs ./hack/run-in-gopath.sh go list \ -f '{{$$d := .Dir}}{{$$d}}{{"\n"}}{{range .GoFiles}}{{$$d}}/{{.}}{{"\n"}}{{end}}' \ @@ -725,7 +778,13 @@ $(META_DIR)/$(CONVERSION_GEN).mk: | tr '=,' '\n\t' \ | sed "s|$$(pwd -P)/||"; \ ) > $@.tmp; \ - cmp -s $@.tmp $@ || cat $@.tmp > $@ && rm -f $@.tmp + if ! cmp -s $@.tmp $@; then \ + if [[ "$(DBG_CODEGEN)" == 1 ]]; then \ + echo "DBG: $(CONVERSION_GEN).mk changed"; \ + fi; \ + cat $@.tmp > $@; \ + rm -f $@.tmp; \ + fi # Include dependency info for the generator tool. This will cause the rule of # the same name to be considered and if it is updated, make will restart. diff --git a/hack/make-rules/verify.sh b/hack/make-rules/verify.sh index 7aa7c53f38..8545d681c0 100755 --- a/hack/make-rules/verify.sh +++ b/hack/make-rules/verify.sh @@ -36,6 +36,7 @@ QUICK_PATTERNS+=( "verify-api-groups.sh" "verify-bazel.sh" "verify-boilerplate.sh" + "verify-generated-files-remake" "verify-godep-licenses.sh" "verify-gofmt.sh" "verify-pkg-names.sh" diff --git a/hack/verify-generated-files-remake.sh b/hack/verify-generated-files-remake.sh new file mode 100644 index 0000000000..c4b43415e4 --- /dev/null +++ b/hack/verify-generated-files-remake.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +set -o errexit +set -o nounset +set -o pipefail + +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/lib/init.sh" + +make generated_files +X=$(make generated_files DBG_CODEGEN=1) +if [[ -n "${X}" ]]; then + echo "Back-to-back 'make' runs are not clean for codegen" + echo "${X}" + exit 1 +fi diff --git a/pkg/api/unversioned/types.go b/pkg/api/unversioned/types.go index dee36ed3f6..61137725a6 100644 --- a/pkg/api/unversioned/types.go +++ b/pkg/api/unversioned/types.go @@ -23,8 +23,6 @@ package unversioned // TypeMeta describes an individual object in an API response or request // with strings representing the type of the object and its API schema version. // Structures that are versioned or persisted should inline TypeMeta. -// -// +k8s:deepcopy-gen=false type TypeMeta struct { // Kind is a string value representing the REST resource this object represents. // Servers may infer this from the endpoint the client submits requests to. diff --git a/pkg/apis/rbac/v1/helpers.go b/pkg/apis/rbac/v1/helpers.go index 0248479690..6bde41408e 100644 --- a/pkg/apis/rbac/v1/helpers.go +++ b/pkg/apis/rbac/v1/helpers.go @@ -24,7 +24,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// +k8s:deepcopy-gen=false // PolicyRuleBuilder let's us attach methods. A no-no for API types. // We use it to construct rules in code. It's more compact than trying to write them // out in a literal and allows us to perform some basic checking during construction @@ -91,7 +90,6 @@ func (r *PolicyRuleBuilder) Rule() (rbacv1.PolicyRule, error) { return r.PolicyRule, nil } -// +k8s:deepcopy-gen=false // ClusterRoleBindingBuilder let's us attach methods. A no-no for API types. // We use it to construct bindings in code. It's more compact than trying to write them // out in a literal. diff --git a/pkg/apis/rbac/v1alpha1/helpers.go b/pkg/apis/rbac/v1alpha1/helpers.go index ad821a6349..7a9e087fb5 100644 --- a/pkg/apis/rbac/v1alpha1/helpers.go +++ b/pkg/apis/rbac/v1alpha1/helpers.go @@ -24,7 +24,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// +k8s:deepcopy-gen=false // PolicyRuleBuilder let's us attach methods. A no-no for API types. // We use it to construct rules in code. It's more compact than trying to write them // out in a literal and allows us to perform some basic checking during construction @@ -91,7 +90,6 @@ func (r *PolicyRuleBuilder) Rule() (rbacv1alpha1.PolicyRule, error) { return r.PolicyRule, nil } -// +k8s:deepcopy-gen=false // ClusterRoleBindingBuilder let's us attach methods. A no-no for API types. // We use it to construct bindings in code. It's more compact than trying to write them // out in a literal. diff --git a/pkg/apis/rbac/v1beta1/helpers.go b/pkg/apis/rbac/v1beta1/helpers.go index 5ad8698976..e80ca84e88 100644 --- a/pkg/apis/rbac/v1beta1/helpers.go +++ b/pkg/apis/rbac/v1beta1/helpers.go @@ -24,7 +24,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// +k8s:deepcopy-gen=false // PolicyRuleBuilder let's us attach methods. A no-no for API types. // We use it to construct rules in code. It's more compact than trying to write them // out in a literal and allows us to perform some basic checking during construction @@ -91,7 +90,6 @@ func (r *PolicyRuleBuilder) Rule() (rbacv1beta1.PolicyRule, error) { return r.PolicyRule, nil } -// +k8s:deepcopy-gen=false // ClusterRoleBindingBuilder let's us attach methods. A no-no for API types. // We use it to construct bindings in code. It's more compact than trying to write them // out in a literal.