forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.codegen
88 lines (71 loc) · 3.81 KB
/
Makefile.codegen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
CODE_GEN_BIN_NAME := codegen
CODE_GEN_GO_DEPENDENCIES := $(call rwildcard,cmd/codegen/,*.go)
CODE_GEN_BUILDFLAGS :=
ifdef DEBUG
CODE_GEN_BUILDFLAGS := -gcflags "all=-N -l" $(CODE_GEN_BUILDFLAGS)
endif
PEGOMOCK_VERSION := v2.2.0
CLIENTSET_GENERATOR_VERSION := kubernetes-1.11.3
GEN_APIDOCS_VERSION := 9642bd3f4de5
OPENAPI_GEN_VERSION := 36ebc4887cdc
build-codegen: build/$(CODE_GEN_BIN_NAME) ## Build the code generator
build/$(CODE_GEN_BIN_NAME): $(CODE_GEN_GO_DEPENDENCIES)
CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(CODE_GEN_BUILDFLAGS) -o build/$(CODE_GEN_BIN_NAME) cmd/codegen/codegen.go
test-codegen: ## Test the code geneator
CGO_ENABLED=$(CGO_ENABLED) $(GO) test -v -short ./cmd/codegen/...
# Generate go code using generate directives in files and kubernetes code generation
# Anything generated by this target should be checked in
generate: generate-clean build-codegen install-generate-deps generate-mocks generate-openapi generate-client ## Generate the Go code (crds, mocks, openapi, client)
@$(MAKE) fmt
@echo "Generation complete"
install-generate-deps:
$(GO) get github.com/petergtz/pegomock/...@$(PEGOMOCK_VERSION)
$(GO) get k8s.io/code-generator/cmd/client-gen@$(CLIENTSET_GENERATOR_VERSION)
$(GO) get k8s.io/code-generator/cmd/defaulter-gen@$(CLIENTSET_GENERATOR_VERSION)
$(GO) get k8s.io/code-generator/cmd/lister-gen@$(CLIENTSET_GENERATOR_VERSION)
$(GO) get k8s.io/code-generator/cmd/informer-gen@$(CLIENTSET_GENERATOR_VERSION)
$(GO) get k8s.io/code-generator/cmd/deepcopy-gen@$(CLIENTSET_GENERATOR_VERSION)
$(GO) get github.com/kubernetes-incubator/reference-docs/gen-apidocs@$(GEN_APIDOCS_VERSION)
$(GO) get k8s.io/kube-openapi/cmd/openapi-gen@$(OPENAPI_GEN_VERSION)
generate-mocks: install-generate-deps go-generate fmt ## Generate the mocks
go-generate:
@echo "Generating Mocks using pegomock"
$(GO) generate ./...
generate-client: codegen-clientset fmt ## Generate the client
codegen-clientset: build-codegen ## Generate the k8s types and clients
@echo "Generating Kubernetes Clients for pkg/apis in pkg/client for jenkins.io:v1"
./build/$(CODE_GEN_BIN_NAME) --generator-version $(CLIENTSET_GENERATOR_VERSION) clientset --output-package=pkg/client --input-package=pkg/apis --group-with-version=jenkins.io:v1
# Generated docs are not checked in
generate-docs: build-codegen ## Generate the docs
@echo "Generating HTML docs for Kubernetes Clients"
./build/$(CODE_GEN_BIN_NAME) --generator-version $(GEN_APIDOCS_VERSION) docs
generate-openapi: codegen-openapi fmt
codegen-openapi: build-codegen
@echo "Generating OpenAPI structs for Kubernetes Clients"
./build/$(CODE_GEN_BIN_NAME) --generator-version $(OPENAPI_GEN_VERSION) openapi --output-package=pkg/client --input-package=github.com/jenkins-x/jx/pkg/apis --group-with-version=jenkins.io:v1
generate-clean: clean ## Delete code generation tools
@echo "Cleaning code generation tools"
@rm -f $(GOPATH)/bin/client-gen
@rm -f $(GOPATH)/bin/deepcopy-gen
@rm -f $(GOPATH)/bin/defaulter-gen
@rm -f $(GOPATH)/bin/informer-gen
@rm -f $(GOPATH)/bin/lister-gen
@rm -f $(GOPATH)/bin/openapi-gen
@rm -f $(GOPATH)/bin/gen-apidocs
@rm -f $(GOPATH)/bin/pegomock
stash:
# Making sure repo has no outstanding changes
git stash
# Verifies that generated code is in sync with implementation
verify-generation-complete: stash generate ## Verify the generated code is up to date
# exclude pkg/client/openapi/k8s_io_apimachinery_intstr_unversioned/openapi_generated.go since it can differs in amount of empty lines in header
$(eval CHANGED = $(shell git ls-files --modified -- . ':(exclude)pkg/client/openapi/k8s_io_apimachinery_intstr_unversioned/openapi_generated.go'))
@if [ "$(CHANGED)" == "" ]; \
then \
echo "All generated files up to date"; \
else \
echo "Code generation is out of date"; \
echo "$(CHANGED)"; \
git diff; \
exit 1; \
fi