forked from projectcalico/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
176 lines (145 loc) · 6.73 KB
/
Makefile
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
PACKAGE_NAME ?= github.com/projectcalico/api
GO_BUILD_VER ?= v0.53
GOMOD_VENDOR := false
GIT_USE_SSH = true
LOCAL_CHECKS = lint-cache-dir goimports check-copyright
BINDIR ?= bin
BUILD_DIR ?= build
TOP_SRC_DIRS = pkg
ORGANIZATION=projectcalico
SEMAPHORE_PROJECT_ID?=$(SEMAPHORE_API_PROJECT_ID)
# Used so semaphore can trigger the update pin pipelines in projects that have this project as a dependency.
SEMAPHORE_AUTO_PIN_UPDATE_PROJECT_IDS=$(SEMAPHORE_LIBCALICO_GO_PROJECT_ID)
##############################################################################
# Download and include Makefile.common before anything else
# Additions to EXTRA_DOCKER_ARGS need to happen before the include since
# that variable is evaluated when we declare DOCKER_RUN and siblings.
##############################################################################
MAKE_BRANCH?=$(GO_BUILD_VER)
MAKE_REPO?=https://raw.githubusercontent.com/projectcalico/go-build/$(MAKE_BRANCH)
Makefile.common: Makefile.common.$(MAKE_BRANCH)
cp "$<" "$@"
Makefile.common.$(MAKE_BRANCH):
# Clean up any files downloaded from other branches so they don't accumulate.
rm -f Makefile.common.*
curl --fail $(MAKE_REPO)/Makefile.common -o "$@"
include Makefile.common
build: gen-files examples
###############################################################################
# This section contains the code generation stuff
###############################################################################
.generate_execs: lint-cache-dir\
$(BINDIR)/defaulter-gen \
$(BINDIR)/deepcopy-gen \
$(BINDIR)/conversion-gen \
$(BINDIR)/client-gen \
$(BINDIR)/lister-gen \
$(BINDIR)/informer-gen \
$(BINDIR)/openapi-gen
touch $@
$(BINDIR)/deepcopy-gen:
$(DOCKER_GO_BUILD) sh -c "GOBIN=/go/src/$(PACKAGE_NAME)/$(BINDIR) go install k8s.io/code-generator/cmd/deepcopy-gen"
$(BINDIR)/client-gen:
$(DOCKER_GO_BUILD) sh -c "GOBIN=/go/src/$(PACKAGE_NAME)/$(BINDIR) go install k8s.io/code-generator/cmd/client-gen"
$(BINDIR)/lister-gen:
$(DOCKER_GO_BUILD) sh -c "GOBIN=/go/src/$(PACKAGE_NAME)/$(BINDIR) go install k8s.io/code-generator/cmd/lister-gen"
$(BINDIR)/informer-gen:
$(DOCKER_GO_BUILD) sh -c "GOBIN=/go/src/$(PACKAGE_NAME)/$(BINDIR) go install k8s.io/code-generator/cmd/informer-gen"
$(BINDIR)/defaulter-gen:
$(DOCKER_GO_BUILD) sh -c "GOBIN=/go/src/$(PACKAGE_NAME)/$(BINDIR) go install k8s.io/code-generator/cmd/defaulter-gen"
$(BINDIR)/conversion-gen:
$(DOCKER_GO_BUILD) sh -c "GOBIN=/go/src/$(PACKAGE_NAME)/$(BINDIR) go install k8s.io/code-generator/cmd/conversion-gen"
$(BINDIR)/openapi-gen:
$(DOCKER_GO_BUILD) sh -c "GOBIN=/go/src/$(PACKAGE_NAME)/$(BINDIR) go install k8s.io/code-generator/cmd/openapi-gen"
# Regenerate all files if the gen exes changed or any "types.go" files changed
.PHONY: gen-files
gen-files .generate_files: lint-cache-dir .generate_execs clean-generated
# Generate defaults
$(DOCKER_RUN) $(CALICO_BUILD) \
sh -c '$(GIT_CONFIG_SSH) $(BINDIR)/defaulter-gen \
--v 1 --logtostderr \
--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
--input-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
--extra-peer-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
--output-file-base "zz_generated.defaults"'
# Generate deep copies
$(DOCKER_RUN) $(CALICO_BUILD) \
sh -c '$(GIT_CONFIG_SSH) $(BINDIR)/deepcopy-gen \
--v 1 --logtostderr \
--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
--input-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
--bounding-dirs $(PACKAGE_NAME) \
--output-file-base zz_generated.deepcopy'
# generate all pkg/client contents
$(DOCKER_RUN) $(CALICO_BUILD) \
sh -c '$(GIT_CONFIG_SSH) $(BUILD_DIR)/update-client-gen.sh'
# generate openapi
$(DOCKER_RUN) $(CALICO_BUILD) \
sh -c '$(GIT_CONFIG_SSH) $(BINDIR)/openapi-gen \
--v 1 --logtostderr \
--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
--input-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3,k8s.io/api/core/v1,k8s.io/api/networking/v1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/version,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr,$(PACKAGE_NAME)/pkg/lib/numorstring" \
--output-package "$(PACKAGE_NAME)/pkg/openapi"'
$(DOCKER_GO_BUILD) \
sh -c '$(BINDIR)/openapi-gen \
--v 1 --logtostderr \
--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
--input-dirs "$(PACKAGE_NAME)/pkg/lib/numorstring" \
--output-package "$(PACKAGE_NAME)/pkg/lib/numorstring"; \
sed -i "/numorstring /d" ./pkg/lib/numorstring/openapi_generated.go'
# Above 'sed' to workaround a bug in openapi-gen which ends up
# importing "numorstring github.com/.../lib/numorstring" causing eventual build error
touch .generate_files
$(MAKE) fix
.PHONY: lint-cache-dir
lint-cache-dir:
mkdir -p $(CURDIR)/.lint-cache
.PHONY: check-copyright
check-copyright:
@hack/check-copyright.sh
.PHONY: clean
clean: clean-bin
rm -rf .lint-cache Makefile.common*
clean-generated:
rm -f .generate_files
find $(TOP_SRC_DIRS) -name zz_generated* -exec rm {} \;
# rollback changes to the generated clientset directories
# find $(TOP_SRC_DIRS) -type d -name *_generated -exec rm -rf {} \;
rm -rf pkg/client/clientset_generated pkg/client/informers_generated pkg/client/listers_generated pkg/openapi
clean-bin:
rm -rf $(BINDIR) \
.generate_execs \
.PHONY: examples
examples: bin/list-gnp
bin/list-gnp: examples/list-gnp/main.go
@echo Building list-gnp example binary...
mkdir -p bin
$(DOCKER_GO_BUILD) sh -c '$(GIT_CONFIG_SSH) \
go build -v -o $@ -v $(LDFLAGS) "examples/list-gnp/main.go"'
WHAT?=.
GINKGO_FOCUS?=.*
.PHONY:ut
ut:
$(DOCKER_RUN) --privileged $(CALICO_BUILD) \
sh -c 'cd /go/src/$(PACKAGE_NAME) && ginkgo -r -focus="$(GINKGO_FOCUS)" $(WHAT)'
## Check if generated files are out of date
.PHONY: check-generated-files
check-generated-files: .generate_files
if (git describe --tags --dirty | grep -c dirty >/dev/null); then \
echo "Generated files are out of date."; \
false; \
else \
echo "Generated files are up to date."; \
fi
###############################################################################
# Static checks
###############################################################################
## Perform static checks on the code.
# TODO: re-enable these linters !
LINT_ARGS := --disable gosimple,govet,structcheck,errcheck,goimports,unused,ineffassign,staticcheck,deadcode,typecheck --timeout 5m
###############################################################################
# CI
###############################################################################
.PHONY: ci
## Run what CI runs
ci: clean check-generated-files static-checks ut