forked from hpe-storage/common-host-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
170 lines (144 loc) · 5.4 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
# (c) Copyright 2018 Hewlett Packard Enterprise Development LP
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
GO_VERSION = 1.10
VERSION = $(shell git tag|tail -n1)
ifeq ($(VERSION),)
VERSION = v0.0.0
endif
ifndef BUILD_NUMBER
BUILD_NUMBER = 0
endif
# Where our code lives
PKG_PATH = ./
VEN_PATH = vendor
# This is the commit id of the branch we're building from
COMMIT = $(shell git log -n 1 --pretty=format:"%H")
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
# The version of make for OSX doesn't allow us to export, so
# we add these variables to the env in each invocation.
GOENV = PATH=$$PATH:$(GOPATH)/bin GLIDE_HOME=$(GOPATH)/.glide
# Our target binary is for Linux. To build an exec for your local (non-linux)
# machine, use go build directly.
ifndef GOOS
GOOS = linux
endif
TEST_ENV = GOOS=$(GOOS) GOARCH=amd64
BUILD_ENV = GOOS=$(GOOS) GOARCH=amd64 CGO_ENABLED=0 VERSION=$(VERSION) COMMIT=$(COMMIT)
# Add the version and commit id to the binary in the form of variables.
LD_FLAGS = '-X main.Version=$(VERSION) -X main.Commit=$(COMMIT)'
# gometalinter allows us to have a single target that runs multiple linters in
# the same fashion. This variable controls which linters are used.
LINTER_FLAGS = --vendor --disable-all --enable=vet --enable=vetshadow --enable=golint --enable=ineffassign --enable=goconst --enable=deadcode --enable=dupl --enable=varcheck --enable=gocyclo --enable=misspell -i "simplivity" --deadline=240s
# list of packages
PACKAGE_LIST = $(shell export $(GOENV) && go list ./$(PKG_PATH)...| grep -v vendor)
# prefixes to make things pretty
A1 = $(shell printf "»")
A2 = $(shell printf "»»")
A3 = $(shell printf "»»»")
S0 = 😁
S1 = 😔
.PHONY: help
help:
@echo "Targets:"
@echo " tools - Download and install go tooling required to build."
@echo " vendor - Download dependencies."
@echo " vendup - Download updated dependencies. (glide up)"
@echo " lint - Static analysis of source code. Note that this must pass in order to build."
@echo " test - Run unit tests."
@echo " int - Run integration tests. (Not implemented yet)."
@echo " clean - Remove build artifacts."
@echo " debug - Display make's view of the world."
@echo " all - Build all cmds."
@echo " all_local - Build all cmds for local OS (make sure GOOS is set)."
@echo " packages - Build packages."
.PHONY: debug
debug:
@echo "Debug:"
@echo " Go: `go version`"
@echo " GOPATH: $(GOPATH)"
@echo " Packages: $(PACKAGE_LIST)"
@echo " VERSION: $(VERSION)"
@echo " BRANCH: $(BRANCH)"
@echo " COMMIT: $(COMMIT)"
@echo " BUILD_NUMBER: $(BUILD_NUMBER)"
@echo " LD_FLAGS: $(LD_FLAGS)"
@echo " BUILD_ENV: $(BUILD_ENV)"
@echo " COMMOM_GIT: $(COMMOM_GIT)"
@echo " GOENV: $(GOENV)"
@echo "$(S0)"
.PHONY : all
all : clean lint docker_run
.PHONY : all_local
all_local : clean debug lint packages test
# this is the target called from within the container
.PHONY: container_all
container_all: debug packages test
.PHONY: tools
tools: ; $(info $(A1) gettools)
@echo "$(A2) get gometalinter"
go get -u github.com/alecthomas/gometalinter
@echo "$(A2) install gometalinter"
export $(GOENV) && gometalinter --install
@echo "$(A2) get glide"
go get -u github.com/Masterminds/glide
@echo "$(S0)"
vendup: tools; $(info $(A1) vendup)
@echo "$(A2) glide up -v"
export $(GOENV) && glide up -v
@echo "$(S0)"
vendor: tools; $(info $(A1) vendor)
@echo "$(A2) glide install -v"
export $(GOENV) && glide install -v
@echo "$(S0)"
build: ; $(info $(A1) mkdir build)
@mkdir build
@echo "$(S0)"
.PHONY: lint
lint: vendor; $(info $(A1) lint)
@echo "$(A2) lint $(PKG_PATH)"
export $(GOENV) $(BUILD_ENV) && gometalinter $(LINTER_FLAGS) $(PKG_PATH)... --exclude $(VEN_PATH)...
@echo "$(S0)"
.PHONY: clean
clean: ; $(info $(A1) clean)
@echo "$(A2) remove build"
@rm -rf build
@echo "$(A2) remove src"
@rm -rf src
@echo "$(A2) remove bin"
@rm -rf bin
@echo "$(A2) remove pkg"
@rm -rf pkg
@echo "$(A2) remove vendor"
@rm -rf vendor
@echo "$(S0)"
.PHONY: test
test: packages; $(info $(A1) test)
@echo "$(A2) unit tests"
ifeq ("$(GOOS)","linux")
export $(GOENV) $(TEST_ENV) && ./package_tester.sh $(PACKAGE_LIST)
else
@echo "Skipping tests... only linux is supported!"
endif
@echo "$(S0)"
.PHONY: int
int: ; $(info $(A1) int)
@echo "$(A2) There are no integration tests yet."
@echo "$(S1)"
.PHONY: packages
packages: build ; $(info $(A1) packages)
@echo "$(A2) build packages"
export $(GOENV) $(BUILD_ENV) && ./package_builder.sh $(PACKAGE_LIST)
@echo "$(S0)"
.PHONY: docker_run
docker_run: ; $(info $(A1) docker_run)
@echo "$(A2) using docker image for build"
docker run --env BACKEND --rm -t -v $(GOPATH):/go -w /go golang:$(GO_VERSION) sh -c "cd src/github.com/hpe-storage/common-host-libs && export XDG_CACHE_HOME=/tmp/.cache && make container_all"
@echo "$(A2) leaving container happy $(S0)"