forked from ligato/sfc-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
195 lines (160 loc) · 5.46 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
VERSION=$(shell git rev-parse HEAD)
DATE=$(shell date +'%Y-%m-%dT%H:%M%:z')
LDFLAGS=-ldflags '-X github.com/ligato/sfc-controller/vendor/github.com/ligato/cn-infra/core.BuildVersion=$(VERSION) -X github.com/ligato/sfc-controller/vendor/github.com/ligato/cn-infra/core.BuildDate=$(DATE)'
PLUGIN_SOURCES="sfc_controller.go"
PLUGIN_BIN="sfc_controller.so"
ETCD_CONFIG_FILE="etcd/etcd.conf"
KAFKA_CONFIG_FILE="kafka/kafka.conf"
SFC_CONFIG_FILE="sfc.conf"
# generate go structures from proto files & binapi json files
define generate_sources
$(if $(shell command -v protoc --gogo_out=. 2> /dev/null),$(info gogo/protobuf is installed),$(error gogo/protobuf missing, please install it with go get github.com/gogo/protobuf))
@echo "# generating sources"
@go generate -v
@cd plugins/vnfdriver && go generate -v
@echo "# done"
endef
# run all tests
define test_only
@echo "# running unit tests"
@go test ./tests/gotests/itest
@echo "# done"
endef
# run all tests with coverage
define test_cover_only
@echo "# running unit tests with coverage analysis"
@go test -covermode=count -coverprofile=${COVER_DIR}coverage_unit1.out ./tests/gotests/itest
@echo "# merging coverage results"
@cd vendor/github.com/wadey/gocovmerge && go install -v
@gocovmerge ${COVER_DIR}coverage_unit1.out > ${COVER_DIR}coverage.out
@echo "# coverage data generated into ${COVER_DIR}coverage.out"
@echo "# done"
endef
# run all tests with coverage and display HTML report
define test_cover_html
$(call test_cover_only)
@go tool cover -html=${COVER_DIR}coverage.out -o ${COVER_DIR}coverage.html
@echo "# coverage report generated into ${COVER_DIR}coverage.html"
@go tool cover -html=${COVER_DIR}coverage.out
endef
# run all tests with coverage and display XML report
define test_cover_xml
$(call test_cover_only)
@gocov convert ${COVER_DIR}coverage.out | gocov-xml > ${COVER_DIR}coverage.xml
@echo "# coverage report generated into ${COVER_DIR}coverage.xml"
endef
# run code analysis
define lint_only
@echo "# running code analysis"
@./scripts/static_analysis.sh golint vet
@echo "# done"
endef
# verify that links in markdown files are valid
# requires npm install -g markdown-link-check
define check_links_only
@echo "# checking links"
@./scripts/check_links.sh
@echo "# done"
endef
# run test examples
define test_examples
@echo "# TODO Testing examples"
endef
# install dependencies according to glide.yaml & glide.lock (in case vendor dir was deleted)
define install_dependencies
$(if $(shell command -v glide install 2> /dev/null),$(info glide dependency manager is ready),$(error glide dependency manager missing, info about installation can be found here https://github.com/Masterminds/glide))
@echo "# installing dependencies, please wait ..."
@glide install --strip-vendor
endef
# clean update dependencies according to glide.yaml (re-downloads all of them)
define update_dependencies
$(if $(shell command -v glide install 2> /dev/null),$(info glide dependency manager is ready),$(error glide dependency manager missing, info about installation can be found here https://github.com/Masterminds/glide))
@echo "# updating dependencies, please wait ..."
@-cd vendor && rm -rf *
@echo "# vendor dir cleared"
@-rm -rf glide.lock
@glide cc
@echo "# glide cache cleared"
@glide install --strip-vendor
endef
# build-only binaries
define build_only
@go version
@echo "# building the sfc controller with plugins"
@go build -i -v ${LDFLAGS}
@echo "# done"
endef
# build-only sfcdump
define build_sfcdump_only
@echo "# building sfcdump"
@cd cmd/sfcdump && go build -v
@echo "# done"
endef
# install-only binaries
define install_only
@echo "# installing sfc controller with plugins"
@go install
@echo "# installing sfcdump"
@cd cmd/sfcdump && go install -v
if test "$(ETCDV3_CONFIG)" != "" ; then \
echo "# Installing '$(ETCD_CONFIG_FILE)' to '$(ETCDV3_CONFIG)''..."; \
cp $(ETCD_CONFIG_FILE) $(ETCDV3_CONFIG); \
fi
if test "$(KAFKA_CONFIG)" != "" ; then \
echo "# Installing '$(KAFKA_CONFIG_FILE)' to '$(KAFKA_CONFIG)''..."; \
cp $(KAFKA_CONFIG_FILE) $(KAFKA_CONFIG); \
fi
if test "$(SFC_CONFIG)" != "" ; then \
echo "# Installing '$(SFC_CONFIG_FILE)' to '$(SFC_CONFIG)''..."; \
cp $(SFC_CONFIG_FILE) $(SFC_CONFIG); \
fi
@echo "# done"
endef
# build binaries
build:
$(call build_only)
# install binaries
install:
$(call install_only)
# install dependencies
install-dep:
$(call install_dependencies)
# update dependencies
update-dep:
$(call update_dependencies)
# generate structures
generate:
$(call generate_sources)
# build & install
all:
$(call build_only)
$(call build_sfcdump_only)
$(call install_only)
# run tests
test:
@cd bin_api && go test -cover
# @cd etcd && go test -cover
# print golint suggestions to stderr
lint:
$(call lint_only)
# report suspicious constructs using go vet tool
govet:
@./scripts/static_analysis.sh vet
# format code using gofmt tool
format:
@./scripts/gofmt.sh
# validate links in markdown files
check_links:
$(call check_links_only)
# clean
clean:
@echo "# cleaning up the plugin binary"
@rm -f ${PLUGIN_BIN}
@echo "# done"
# run smoke tests on examples - TODO
test-examples:
$(call test_examples)
# run tests with coverage report
test-cover:
$(call test_cover_only)
.PHONY: build update-dep install-dep test lint clean