-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
155 lines (133 loc) · 5.23 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
# If ../metadata.mk exists, we're running this logic from within the calico repository.
# If it does not, then we're in the api repo and we should use the local metadata.mk.
ifneq ("$(wildcard ../metadata.mk)", "")
include ../metadata.mk
else
include ./metadata.mk
endif
PACKAGE_NAME ?= github.com/projectcalico/api
LOCAL_CHECKS = lint-cache-dir check-copyright
BINDIR ?= bin
BUILD_DIR ?= build
TOP_SRC_DIRS = pkg
##############################################################################
# Download and include ../lib.Makefile 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.
##############################################################################
# If ../lib.Makefile exists, we're running this logic from within the calico repository.
# If it does not, then we're in the api repo and should use the local lib.Makefile.
ifneq ("$(wildcard ../lib.Makefile)", "")
include ../lib.Makefile
else
include ./lib.Makefile
endif
# Override DOCKER_RUN from lib.Makefile. We need to trick this particular directory to think
# that its package is github.com/projectcalico/api for easier mirroring.
DOCKER_RUN := mkdir -p ../.go-pkg-cache bin $(GOMOD_CACHE) && \
docker run --rm \
--net=host \
--init \
$(EXTRA_DOCKER_ARGS) \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-e GOCACHE=/go-cache \
$(GOARCH_FLAGS) \
-e GOPATH=/go \
-e OS=$(BUILDOS) \
-e GOOS=$(BUILDOS) \
-e GOFLAGS=$(GOFLAGS) \
-v $(CURDIR):/go/src/$(PACKAGE_NAME):rw \
-v $(CURDIR)/../.go-pkg-cache:/go-cache:rw \
-w /go/src/$(PACKAGE_NAME)
build: gen-files examples
###############################################################################
# This section contains the code generation stuff
###############################################################################
# Regenerate all files if the gen exes changed or any "types.go" files changed
.PHONY: gen-files
gen-files .generate_files: lint-cache-dir clean-generated
# Generate defaults
$(DOCKER_RUN) $(CALICO_BUILD) \
sh -c '$(GIT_CONFIG_SSH) defaulter-gen \
--v 1 --logtostderr \
--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
--extra-peer-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
--output-file zz_generated.defaults.go \
"$(PACKAGE_NAME)/pkg/apis/projectcalico/v3"'
# Generate deep copies
$(DOCKER_RUN) $(CALICO_BUILD) \
sh -c '$(GIT_CONFIG_SSH) deepcopy-gen \
--v 1 --logtostderr \
--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
--bounding-dirs $(PACKAGE_NAME) \
--output-file zz_generated.deepcopy.go \
"$(PACKAGE_NAME)/pkg/apis/projectcalico/v3"'
# 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) openapi-gen \
--v 1 --logtostderr \
--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
--output-dir "/go/src/$(PACKAGE_NAME)/pkg/openapi" \
--output-pkg "$(PACKAGE_NAME)/pkg/openapi" \
"$(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/runtime" \
"k8s.io/apimachinery/pkg/util/intstr" \
"k8s.io/apimachinery/pkg/version" \
"$(PACKAGE_NAME)/pkg/lib/numorstring"'
touch .generate_files
$(MAKE) fix
# Would be nice to use the projectcalico/calico's more-thorough fix target here but,
# once the API package is exported to its own repo, the projectcalico/calico's scripts are
# not available.
fix:
$(DOCKER_RUN) $(CALICO_BUILD) sh -c 'find . -iname "*.go" ! -wholename "./vendor/*" | xargs goimports -w -local github.com/projectcalico/calico/'
.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
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...
$(call build_binary, 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
###############################################################################
# CI
###############################################################################
.PHONY: ci
## Run what CI runs
ci: clean check-generated-files build static-checks ut