forked from rexray/gocsi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
240 lines (193 loc) · 7.51 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
all: build
################################################################################
## DEP ##
################################################################################
DEP := ./dep
DEP_VER ?= 0.3.0
DEP_ZIP := dep-$$GOHOSTOS-$$GOHOSTARCH.zip
DEP_URL := https://github.com/golang/dep/releases/download/v$(DEP_VER)/$$DEP_ZIP
$(DEP):
GOVERSION=$$(go version | awk '{print $$4}') && \
GOHOSTOS=$$(echo $$GOVERSION | awk -F/ '{print $$1}') && \
GOHOSTARCH=$$(echo $$GOVERSION | awk -F/ '{print $$2}') && \
DEP_ZIP="$(DEP_ZIP)" && \
DEP_URL="$(DEP_URL)" && \
mkdir -p .dep && \
cd .dep && \
curl -sSLO $$DEP_URL && \
unzip "$$DEP_ZIP" && \
mv $(@F) ../ && \
cd ../ && \
rm -fr .dep
ifneq (./dep,$(DEP))
dep: $(DEP)
endif
dep-ensure: | $(DEP)
$(DEP) ensure -v
########################################################################
## PROTOC ##
########################################################################
# Only set PROTOC_VER if it has an empty value.
ifeq (,$(strip $(PROTOC_VER)))
PROTOC_VER := 3.3.0
endif
PROTOC_OS := $(shell uname -s)
ifeq (Darwin,$(PROTOC_OS))
PROTOC_OS := osx
endif
PROTOC_ARCH := $(shell uname -m)
ifeq (i386,$(PROTOC_ARCH))
PROTOC_ARCH := x86_32
endif
PROTOC := ./protoc
PROTOC_ZIP := protoc-$(PROTOC_VER)-$(PROTOC_OS)-$(PROTOC_ARCH).zip
PROTOC_URL := https://github.com/google/protobuf/releases/download/v$(PROTOC_VER)/$(PROTOC_ZIP)
PROTOC_TMP_DIR := .protoc
PROTOC_TMP_BIN := $(PROTOC_TMP_DIR)/bin/protoc
$(PROTOC):
-mkdir -p "$(PROTOC_TMP_DIR)" && \
curl -L $(PROTOC_URL) -o "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" && \
unzip "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" -d "$(PROTOC_TMP_DIR)" && \
chmod 0755 "$(PROTOC_TMP_BIN)" && \
cp -f "$(PROTOC_TMP_BIN)" "$@"
-rm -fr "$(PROTOC_TMP_DIR)"
stat "$@" > /dev/null 2>&1
########################################################################
## PROTOC-GEN-GO ##
########################################################################
# This is the recipe for getting and installing the go plug-in
# for protoc
PROTOC_GEN_GO_PKG := ./vendor/github.com/golang/protobuf/protoc-gen-go
PROTOC_GEN_GO := protoc-gen-go
$(PROTOC_GEN_GO):
go build -o "$@" $(PROTOC_GEN_GO_PKG)
# Update PATH with the current directory. This enables the protoc
# binary to discover the protoc-gen-go binary, built inside this
# directory.
export PATH := $(shell pwd):$(PATH)
########################################################################
## CSI SPEC ##
########################################################################
# The paths of the CSI spec, protobuf, and Go source file.
CSI_SPEC := vendor/github.com/container-storage-interface/spec/spec.md
CSI_PROTO := csi/csi.proto
CSI_GOSRC := csi/csi.pb.go
# The temporary area and files used to build and compare updated
# file content.
CSI_TMP_DIR := csi/.build
CSI_PROTO_TMP := $(CSI_TMP_DIR)/csi.proto
CSI_GOSRC_TMP := $(CSI_TMP_DIR)/csi.pb.go
# This is the target for building the temporary CSI protobuf file.
#
# The temporary file is not versioned, and thus will always be
# built on Travis-CI.
$(CSI_PROTO_TMP): $(CSI_SPEC)
@mkdir -p "$(@D)"
sed -n -e '/```protobuf$$/,/```$$/ p' "$<" | \
sed -e 's@^```.*$$@////////@g' > "$@"
.PHONY: $(CSI_PROTO_TMP)
# If SKIP_CODEGEN is true then do not define a recipe for
# generating the protobuf.
ifneq (true,$(SKIP_CODEGEN))
# This is the target for building the CSI protobuf file.
#
# This target depends on its temp file, which is not versioned.
# Therefore when built on Travis-CI the temp file will always
# be built and trigger this target. On Travis-CI the temp file
# is compared with the real file, and if they differ the build
# will fail.
#
# Locally the temp file is simply copied over the real file.
$(CSI_PROTO): $(CSI_PROTO_TMP)
ifeq (true,$(TRAVIS))
diff "$@" "$<"
else
diff "$@" "$<" > /dev/null 2>&1 || cp -f "$<" "$@"
endif
endif
# This recipe generates the Go bindings to a temp area.
$(CSI_GOSRC_TMP): $(CSI_PROTO) | $(PROTOC) $(PROTOC_GEN_GO)
@mkdir -p "$(@D)"
$(PROTOC) -I "$(<D)" --go_out=plugins=grpc:"$(@D)" "$<"
# If SKIP_CODEGEN is true then do not define a recipe for
# generating the Go language binding.
ifneq (true,$(SKIP_CODEGEN))
# The temp language bindings are compared to the ones that are
# versioned. If they are different then it means the language
# bindings were not updated prior to being committed.
$(CSI_GOSRC): $(CSI_GOSRC_TMP)
ifeq (true,$(TRAVIS))
diff "$@" "$<"
else
diff "$@" "$<" > /dev/null 2>&1 || cp -f "$<" "$@"
endif
endif
########################################################################
## COMP W CSI SPEC MASTER ##
########################################################################
CSI_SPEC_MASTER := $(CSI_TMP_DIR)/csi.proto.master
CSI_SPEC_MASTER_URI := https://raw.githubusercontent.com/container-storage-interface/spec/master/spec.md
$(CSI_SPEC_MASTER):
@mkdir -p "$(@D)"
curl -sSL $(CSI_SPEC_MASTER_URI) | \
sed -n -e '/```protobuf$$/,/```$$/ p' | \
sed -e 's@^```.*$$@////////@g' > "$@"
# This recipe fetches the "spec.md" file from the "master" branch of the
# CSI spec repo and compares the generated protobuf with one generated
# from the aforementioned spec. If there is a difference between the
# two files this recipe will fail.
#
# Upon failure, aside from the output from the diff command, the last
# line will print the Git commit ID of the spec.md that was used
# in the comparison.
CSI_SPEC_MASTER_GIT := https://github.com/container-storage-interface/spec.git
csi-spec-comp-master: $(CSI_SPEC_MASTER) $(CSI_PROTO)
-diff $^ || \
git ls-remote -h $(CSI_SPEC_MASTER_GIT) | grep master | awk '{print $$1}'
.PHONY: csi-spec-comp-master $(CSI_SPEC_MASTER)
########################################################################
## GOCSI ##
########################################################################
GOCSI_A := gocsi.a
$(GOCSI_A): $(CSI_GOSRC) *.go
@go install .
go build -o "$@" .
MOUNT_A := mount.a
$(MOUNT_A): mount/*.go
@go install ./mount
go build -o "$@" ./mount
########################################################################
## TEST ##
########################################################################
GINKGO := ./ginkgo
GINKGO_PKG := ./vendor/github.com/onsi/ginkgo/ginkgo
$(GINKGO):
go build -o "$@" $(GINKGO_PKG)
# The test recipe executes the Go tests with the Ginkgo test
# runner. This is the reason for the boolean OR condition
# that is part of the test script. The condition allows for
# the test run to exit with a status set to the value Ginkgo
# uses if it detects programmatic involvement. Please see
# https://goo.gl/CKz4La for more information.
ifneq (true,$(TRAVIS))
test: build
endif
test: | $(GINKGO)
$(GINKGO) -v . || test "$$?" -eq "197"
.PHONY: test
########################################################################
## BUILD ##
########################################################################
build: $(GOCSI_A) $(MOUNT_A)
$(MAKE) -C csc $@
$(MAKE) -C mock $@
clean:
go clean -i -v .
rm -f "$(GOCSI_A)" "$(CSI_PROTO)" "$(CSI_GOSRC)"
$(MAKE) -C csc $@
$(MAKE) -C mock $@
clobber: clean
rm -fr "$(CSI_TMP_DIR)"
$(MAKE) -C csc $@
$(MAKE) -C mock $@
.PHONY: build test clean clobber