/
main.make
147 lines (111 loc) · 4.29 KB
/
main.make
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
# Copyright © 2018 The Things Network Foundation, The Things Industries B.V.
#
# 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.
# default release dir
RELEASE_DIR ?= release#
# default cache dir for intermediate files.
CACHE_DIR ?= .cache
# File where messages are written to.
GO_MESSAGES_FILE ?= $(RELEASE_DIR)/errors.json
# the first entry of the go path
GO_PATH ?= $(shell echo $(GOPATH) | awk -F':' '{ print $$1 }')
# the name of you go package (eg. github.com/foo/bar)
GO_PKG ?= $(shell echo $(PWD) | sed s:$(GO_PATH)/src/::)
# programs
GO = go
GO_FMT= gofmt
GO_MISSPELL= misspell
GO_UNCONVERT= unconvert
GO_METALINTER = gometalinter
GO_LINT_FILES = $(ALL_FILES) | $(only_go_lintable)
# go flags
GO_ENV = CGO_ENABLED=0
LD_FLAGS = -ldflags "-w $(GO_TAGS)"
GO_TAGS ?= -X github.com/TheThingsNetwork/ttn/pkg/version.GitCommit=$(GIT_COMMIT) -X github.com/TheThingsNetwork/ttn/pkg/version.BuildDate=$(BUILD_DATE) -X github.com/TheThingsNetwork/ttn/pkg/version.TTN=$(GIT_TAG) -X github.com/TheThingsNetwork/ttn/pkg/version.GitBranch=$(GIT_BRANCH)
# coverage
GO_COVER_FILE = coverage.out
GO_FILTERED_COVER_FILE = coverage.filtered.out
# go test flags
GO_COVERALLS_FLAGS = -cover -covermode=atomic -coverprofile=$(GO_COVER_FILE)
GO_TEST_FLAGS ?= $(if $(CI),$(GO_COVERALLS_FLAGS),-cover)
# select only go files
only_go = grep '\.go$$'
# select/remove vendored files
no_vendor = grep -v 'vendor'
only_vendor = grep 'vendor'
# select/remove mock files
no_mock = grep -v '_mock\.go'
only_mock = grep '_mock\.go'
# select/remove protobuf generated files
no_pb = grep -Ev '\.pb\.go$$|\.pb\.gw\.go$$|pb_test.go$$'
only_pb = grep -E '\.pb\.go$$|\.pb\.gw\.go$$|pb_test.go$$'
# select/remove test files
no_test = grep -v '_test\.go$$'
only_test = grep '_test\.go$$'
# lintable files
only_go_lintable = $(only_go) | $(no_vendor) | $(no_mock) | $(no_pb)
# filter files to packages
to_packages = sed 's:/[^/]*$$::' | sort | uniq
# make packages local (prefix with ./)
to_local = sed 's:^:\./:' | sed 's:^\./.*\.go$$:.:'
# the govendor file
GO_VENDOR_FILE ?= Gopkg.toml
# all go files
GO_FILES = $(ALL_FILES) | $(only_go)
# local go packages
GO_PACKAGES = $(GO) list -v ./...
# local go packages as absolute paths
GO_PACKAGES_ABSOLUTE = $(GO) list -v -f '{{.Dir}}' ./...
# external go packages (in vendor)
EXTERNAL_PACKAGES = find ./vendor -name "*.go" | $(to_packages) | $(only_vendor)
# staged local packages
STAGED_PACKAGES = $(STAGED_FILES) | $(only_go) | $(no_vendor) | $(to_packages) | xargs $(GO) list -v 2>/dev/null
# staged local packages as absolute paths
STAGED_PACKAGES_ABSOLUTE = $(STAGED_FILES) | $(only_go) | $(no_vendor) | $(to_packages) | xargs $(GO) list -v -f '{{.Dir}}' 2>/dev/null
# packages for testing
TEST_PACKAGES = $(GO_FILES) | $(no_vendor) | $(only_test) | $(to_packages)
# get tools required for development
go.dev-deps:
@$(log) "Installing go dev dependencies"
@$(log) "Getting dep" && $(GO) get -u github.com/golang/dep/cmd/dep
@if [[ ! -z "$(CI)" ]]; then $(log) "Getting goveralls" && $(GO) get -u github.com/mattn/goveralls; fi
@$(log) "Getting gometalinter" && $(GO) get -u github.com/alecthomas/gometalinter
@$(log) "Getting gometalinter linters" && $(GO_METALINTER) -i
DEP_FLAGS ?= $(if $(CI),-vendor-only,)
# install dependencies
go.deps:
@$(log) "Installing go dependencies"
@dep ensure -v $(DEP_FLAGS)
# clean build files
go.clean:
@$(log) "Cleaning release dir" [rm -rf $(RELEASE_DIR)]
@rm -rf $(RELEASE_DIR)
# list all go files
go.list:
@$(GO_FILES) | sort
# list all staged go files
go.list-staged: GO_FILES = $(STAGED_FILES) | $(only_go)
go.list-staged: go.list
# init initializes go
go.init:
@$(log) "Initializing go"
@make go.dev-deps
@make go.deps
# certificates
key.pem: dev-cert
cert.pem: dev-cert
INIT_RULES += go.init
include .make/go/build.make
include .make/go/test.make
include .make/go/quality.make
# vim: ft=make