Skip to content

Commit

Permalink
Don't check in generated deep-copy code
Browse files Browse the repository at this point in the history
This mostly takes the previously checked in files and removes them, and moves
the generation to be on-demand instead of manual.  Manually verified no change
in generated output.
  • Loading branch information
thockin committed Jul 13, 2016
1 parent 881e21c commit 58441e8
Show file tree
Hide file tree
Showing 32 changed files with 89 additions and 13,997 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@ network_closure.sh

# Downloaded kubernetes binary release tar ball
kubernetes.tar.gz

# generated files in any directory
zz_generated.*
92 changes: 84 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# clean: Clean up.

OUT_DIR = _output
BIN_DIR := $(OUT_DIR)/bin
PRJ_SRC_PATH := k8s.io/kubernetes
GENERATED_FILE_PREFIX := zz_generated.

KUBE_GOFLAGS = $(GOFLAGS)
export KUBE_GOFLAGS
Expand All @@ -41,8 +44,7 @@ export KUBE_GOLDFLAGS
# make
# make all
# make all WHAT=cmd/kubelet GOFLAGS=-v
all:
@hack/make-rules/build.sh $(WHAT)
all: gen_deepcopy build
.PHONY: all

# Build ginkgo
Expand All @@ -53,6 +55,11 @@ ginkgo:
hack/make-rules/build.sh vendor/github.com/onsi/ginkgo/ginkgo
.PHONY: ginkgo

# This is a helper to break circular dependencies.
build:
@hack/make-rules/build.sh $(WHAT)
.PHONY: build

# Runs all the presubmission verifications.
#
# Args:
Expand All @@ -78,23 +85,23 @@ verify:
# make check
# make test
# make check WHAT=pkg/kubelet GOFLAGS=-v
check test:
check test: gen_deepcopy
@hack/make-rules/test.sh $(WHAT) $(TESTS)
.PHONY: check test

# Build and run integration tests.
#
# Example:
# make test-integration
test-integration:
test-integration: gen_deepcopy
@hack/make-rules/test-integration.sh
.PHONY: test-integration

# Build and run end-to-end tests.
#
# Example:
# make test-e2e
test-e2e: ginkgo
test-e2e: ginkgo gen_deepcopy
@go run hack/e2e.go -v --build --up --test --down
.PHONY: test-e2e

Expand All @@ -119,7 +126,7 @@ test-e2e: ginkgo
# make test-e2e-node FOCUS=kubelet SKIP=container
# make test-e2e-node REMOTE=true DELETE_INSTANCES=true
# Build and run tests.
test-e2e-node: ginkgo
test-e2e-node: ginkgo gen_deepcopy
@hack/make-rules/test-e2e-node.sh
.PHONY: test-e2e-node

Expand All @@ -138,6 +145,7 @@ test-cmd:
clean:
build/make-clean.sh
rm -rf $(OUT_DIR)
find . -type f -name $(GENERATED_FILE_PREFIX)\* | xargs rm -f
rm -rf Godeps/_workspace # Just until we are sure it is gone
.PHONY: clean

Expand All @@ -159,14 +167,82 @@ vet:
#
# Example:
# make release
release:
release: gen_deepcopy
@build/release.sh
.PHONY: release

# Build a release, but skip tests
#
# Example:
# make release-skip-tests
release-skip-tests quick-release:
release-skip-tests quick-release: gen_deepcopy
@KUBE_RELEASE_RUN_TESTS=n KUBE_FASTBUILD=true build/release.sh
.PHONY: release-skip-tests quick-release

#
# Code-generation logic.
#

# Generate a list of all files that have a `+k8s:` comment-tag. This will be
# used to derive lists of files/dirs for generation tools.
ALL_K8S_TAG_FILES := $(shell \
find . \
-not \( \
\( \
-path ./vendor -o \
-path ./$(OUT_DIR) -o \
-path ./.git \
\) -prune \
\) \
-type f -name \*.go | xargs grep -l '^// \?+k8s:' \
)

#
# Deep-copy generation
#
# Any package that wants deep-copy functions generated must include a
# comment-tag in column 0 of one file of the form:
# // +k8s:deepcopy-gen=<VALUE>
#
# The <VALUE> may be one of:
# generate: generate deep-copy functions into the package
# register: generate deep-copy functions and register them with a
# scheme

# Find all the directories that request deep-copy generation.
DEEP_COPY_DIRS := $(shell \
grep -l '+k8s:deepcopy-gen=' $(ALL_K8S_TAG_FILES) \
| xargs dirname \
| sort -u \
)

# The result file, in each pkg, of deep-copy generation.
DEEP_COPY_BASENAME := $(GENERATED_FILE_PREFIX)deep_copy
DEEP_COPY_FILENAME := $(DEEP_COPY_BASENAME).go

# Unfortunately there's not a good way to use Go's build tools to check
# if a binary needs to be rebuilt. We just have to try it.
gen_deepcopy:
@$(MAKE) -s build WHAT=cmd/libs/go2idl/deepcopy-gen
@$(MAKE) -s $(addsuffix /$(DEEP_COPY_FILENAME), $(DEEP_COPY_DIRS))

# For each dir in DEEP_COPY_DIRS, this generates a statement of the form:
# path/to/dir/$(DEEP_COPY_FILENAME): <all files in dir, except generated ones>
#
# Note that this is a deps-only statement, not a full rule (see below).
# This has to be done in a distinct step because wildcards don't seem to work
# in static pattern rules.
#
# The '$(eval)' is needed because this has a different RHS for each LHS, and
# would otherwise produce results that make can't parse.
$(foreach dir, $(DEEP_COPY_DIRS), \
$(eval $(dir)/$(DEEP_COPY_FILENAME): $(shell ls $(dir)/*.go | grep -v $(GENERATED_FILE_PREFIX))))

# For each dir in DEEP_COPY_DIRS, handle deep-copy generation.
# This has to be done in two steps because wildcards don't seem to work in
# static pattern rules.
$(addsuffix /$(DEEP_COPY_FILENAME), $(DEEP_COPY_DIRS)):
$(BIN_DIR)/deepcopy-gen \
-i $(PRJ_SRC_PATH)/$$(dirname $@) \
--bounding-dirs $(PRJ_SRC_PATH) \
-O $(DEEP_COPY_BASENAME)
4 changes: 1 addition & 3 deletions cmd/libs/go2idl/deepcopy-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ func main() {
arguments.OutputFileBaseName = "deep_copy_generated"

// Custom args.
customArgs := &generators.CustomArgs{
BoundingDirs: []string{"k8s.io/kubernetes"},
}
customArgs := &generators.CustomArgs{}
pflag.CommandLine.StringSliceVar(&customArgs.BoundingDirs, "bounding-dirs", customArgs.BoundingDirs,
"Comma-separated list of import paths which bound the types for which deep-copies will be generated.")
arguments.CustomArgs = customArgs
Expand Down
155 changes: 0 additions & 155 deletions federation/apis/federation/deep_copy_generated.go

This file was deleted.

Loading

0 comments on commit 58441e8

Please sign in to comment.