-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (104 loc) · 4.21 KB
/
Copy pathMakefile
File metadata and controls
124 lines (104 loc) · 4.21 KB
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
# 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 the Go artifacts (defaults, deep copies, OpenAPI definitions, and
# the clientset/listers/informers). The logic lives in build/codegen.sh so it
# can be shared with the calico monorepo, which mirrors build/ into this repo
# but keeps its own Makefile.
$(DOCKER_RUN) -e PACKAGE_NAME=$(PACKAGE_NAME) $(CALICO_BUILD) sh -c '$(GIT_CONFIG_SSH) $(BUILD_DIR)/codegen.sh'
touch .generate_files
$(MAKE) fix
# Would be nice to use the monorepo's more-thorough fix target here but,
# once the API package is exported to its own repo, the monorepo'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/client/applyconfiguration_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