forked from QMSTR/qmstr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
146 lines (108 loc) · 4.33 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
include versions.env
# Common variables
OUTDIR := out/
CHECKCMDS = $(foreach cmd,$(1),$(if $(shell which $(cmd)),$(shell which $(cmd)),$(error "Command [$(cmd)] not available. Please install it first.")))
PROTO_FILES := $(shell ls ./proto/*.proto)
ALL_PYTHON_FILES := $(shell find . -path ./venv -prune -o -name *.py -print)
PROTO_PYTHON_FILES := $(patsubst ./proto/%,./lib/pyqmstr/qmstr/service/%,$(PROTO_FILES:.proto=_pb2.py)) $(patsubst ./proto/%,./lib/pyqmstr/qmstr/service/%,$(PROTO_FILES:.proto=_pb2_grpc.py))
PYTHON_FILES := $(filter-out $(PROTO_PYTHON_FILES), $(ALL_PYTHON_FILES))
# The installation prefix defaults to /usr/local. It can be overwritten
# by specifying the PREFIX variable on the command line:
# make PREFIX=/opt/qmstr
prefix = /usr/local
ifdef PREFIX
prefix=$(PREFIX)
endif
GO := $(call CHECKCMDS,go)
# those are intended to be a recursively expanded variables
GO_SRCS = $(shell find . -name '*.go')
FILTER = $(foreach v,$(2),$(if $(findstring $(1),$(v)),$(v),))
GO_MODULE_SRCS = $(call FILTER,module,$(GO_SRCS))
GO_MODULE_PKGS := $(shell $(GO) list ./... | grep /module | grep -v /vendor)
GO_PKGS := $(shell $(GO) list ./... | grep -v /module | grep -v /vendor)
GO_PATH := $(shell $(GO) env GOPATH)
GO_BIN := $(GO_PATH)/bin
PROTOC_GEN_GO := $(GO_BIN)/protoc-gen-go
GOLINT := $(GO_BIN)/golint
GO_DEPS := $(PROTOC_GEN_GO) $(GO_SRCS)
QMSTR_ANALYZERS := $(foreach ana, $(shell ls modules/analyzers), $(OUTDIR)analyzers/$(ana))
QMSTR_REPORTERS := $(foreach rep, $(shell ls modules/reporters), $(OUTDIR)reporters/$(rep))
EXCLUDE_BUILDERS := out/builders/qmstr-gradle-plugin out/builders/qmstr-maven-plugin out/builders/qmstr-py-builder
QMSTR_BUILDERS := $(filter-out $(EXCLUDE_BUILDERS), $(foreach builder, $(shell ls modules/builders), $(OUTDIR)builders/$(builder)))
QMSTR_MASTER := $(foreach bin, qmstr-master, ${OUTDIR}$(bin))
QMSTR_SERVER_BINARIES := $(QMSTR_MASTER) $(QMSTR_REPORTERS) $(QMSTR_ANALYZERS) $(QMSTR_BUILDERS)
QMSTR_CLIENT_BINARIES := $(foreach cli, qmstrctl qmstr, ${OUTDIR}$(cli)) $(QMSTR_BUILDERS)
CONTAINER_TAG_DEV := qmstr/dev
CONTAINER_TAG_MASTER := qmstr/master
CONTAINER_TAG_RUNTIME := qmstr/runtime
CONTAINER_TAG_BUILDER := qmstr/master_build
.PHONY: all clients install
all: checkdocker clients master
# Clean-up targets:
.PHONY: clean
clean:
git clean -fxd
squeakyclean:
git clean -ffxd
.PHONY: cleanall
cleanall: clean
@docker rmi ${CONTAINER_TAG_DEV} ${CONTAINER_TAG_MASTER} ${CONTAINER_TAG_RUNTIME} || true
@docker image prune --all --force --filter=label=org.qmstr.image
# Tests and code quality checks
.go_module_test: $(GO_MODULE_SRCS)
$(GO) test -race $(GO_MODULE_PKGS)
@touch .go_module_test
.go_qmstr_test: $(GO_SRCS)
$(GO) test -race $(GO_PKGS)
@touch .go_qmstr_test
.PHONY: gofmt
gofmt: $(GO) $(GO_SRCS)
$(GO) fmt $(GO_PKGS) $(GO_MODULE_PKGS)
.PHONY: gotest
gotest: $(GO_DEPS) .go_qmstr_test .go_module_test
.PHONY: govet
govet: $(GO_SRCS) $(GO) gofmt
$(GO) vet ./clients/... ./lib/go-qmstr/...
.PHONY: golint
golint: govet $(GOLINT)
$(GOLINT) ./clients/... ./lib/go-qmstr/...
$(GOLINT): $(GO)
$(GO) get -u golang.org/x/lint/golint
$(PROTOC_GEN_GO): $(GO)
$(GO) install github.com/golang/protobuf/protoc-gen-go
# Client build target
clients: $(QMSTR_CLIENT_BINARIES)
# Installation/uninstallation targets
install: install_qmstr_client
# Installation targets
install_qmstr_server: $(QMSTR_SERVER_BINARIES)
install $^ $(prefix)/bin
install_qmstr_client: $(QMSTR_CLIENT_BINARIES)
install $^ $(prefix)/bin
install_qmstr_all: install_qmstr_client install_qmstr_server
# Python related targets
checkpython:
@echo $(call CHECKCMDS,python3)
checkvirtualenv: checkpython
@echo $(call CHECKCMDS,virtualenv)
venv: venv/bin/activate
venv/bin/activate: requirements.txt checkvirtualenv
test -d venv || virtualenv -p python3 venv
venv/bin/pip install -Ur requirements.txt
touch venv/bin/activate
requirements.txt:
@echo grpcio==$(GRPCIO_VERSION) >> requirements.txt
@echo grpcio-tools==$(GRPCIO_VERSION) >> requirements.txt
venv/bin/pip: venv
venv/bin/pex: venv
@venv/bin/pip install pex
venv/bin/autopep8: venv
@venv/bin/pip install autopep8
.PHONY: checkpep8
checkpep8: $(PYTHON_FILES) venv
venv/bin/autopep8 --diff $(filter-out venv, $^)
.PHONY: autopep8
autopep8: $(PYTHON_FILES) venv/bin/autopep8
venv/bin/autopep8 -i $(filter-out venv, $^)
# include all makefiles
include $(shell find . -name "Makefile.common")