-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
107 lines (84 loc) · 3.15 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
ALL_SRC := $(shell find . -name '*.go' \
-not -path './internal/tools/*' \
-not -path './gen/*' \
-type f | sort)
# ALL_PKGS is the list of all packages where ALL_SRC files reside.
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))
# All source code and documents. Used in spell check.
ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
# Function to execute a command. Note the empty line before endef to make sure each command
# gets executed separately instead of concatenated with previous one.
# Accepts command to execute as first parameter.
define exec-command
$(1)
endef
GO_ACC=go-acc
GOOS=$(shell go env GOOS)
ADDLICENCESE=addlicense
MISSPELL=misspell -error
MISSPELL_CORRECTION=misspell -w
IMPI=impi
.PHONY: all
all: check
$(MAKE) generate-sapm
$(MAKE) generate-otlp
$(MAKE) test
OTEL_DOCKER_PROTOBUF ?= otel/build-protobuf:0.12.0
SAPM_PROTO_INCLUDES := -I/usr/include/github.com/gogo/protobuf
SAPM_PROTOC := docker run --rm -u ${shell id -u} -v${PWD}:${PWD} -w${PWD} ${OTEL_DOCKER_PROTOBUF} --proto_path=${PWD}
# Target directory to write generated files to.
SAPM_TARGET_GEN_DIR=./gen
.PHONY: generate-sapm
generate-sapm:
git submodule update --init
mkdir -p $(SAPM_TARGET_GEN_DIR)
$(SAPM_PROTOC) $(SAPM_PROTO_INCLUDES) --gogo_out=,Mjaeger-idl/proto/api_v2/model.proto=github.com/jaegertracing/jaeger/model:$(SAPM_TARGET_GEN_DIR) proto/sapm.proto
@echo Move generated code to target directory.
cp -R $(SAPM_TARGET_GEN_DIR)/proto/* $(SAPM_TARGET_GEN_DIR)
rm -fr $(SAPM_TARGET_GEN_DIR)/proto
.PHONY: check
check: addlicense lint misspell
.PHONY: gomoddownload
gomoddownload:
go mod download
.PHONY: test
test:
go test ./...
.PHONY: addlicense
addlicense:
@ADDLICENCESEOUT=`$(ADDLICENCESE) -y 2019 -c 'Splunk, Inc.' $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENCESEOUT" ]; then \
echo "$(ADDLICENCESE) FAILED => add License errors:\n"; \
echo "$$ADDLICENCESEOUT\n"; \
exit 1; \
else \
echo "Add License finished successfully"; \
fi
.PHONY: lint
lint:
$(foreach dir,$(ALL_GO_MOD_DIRS),$(call exec-command,cd $(dir) && golangci-lint run --fix && golangci-lint run))
$(foreach dir,$(ALL_GO_MOD_DIRS),$(call exec-command,cd $(dir) && go mod tidy))
.PHONY: misspell
misspell:
$(MISSPELL) $(ALL_DOCS)
.PHONY: misspell-correction
misspell-correction:
$(MISSPELL_CORRECTION) $(ALL_DOCS)
.PHONY: impi
impi:
@$(IMPI) --local github.com/signalfx/sapm-proto --scheme stdThirdPartyLocal $(ALL_SRC)
.PHONY: test-with-cover
test-with-cover:
$(GO_ACC) $(ALL_PKGS)
go tool cover -html=coverage.txt -o coverage.html
TOOLS_MOD_DIR := ./internal/tools
.PHONY: install-tools
install-tools:
cd $(TOOLS_MOD_DIR) && go install github.com/client9/misspell/cmd/misspell
cd $(TOOLS_MOD_DIR) && go install github.com/golangci/golangci-lint/cmd/golangci-lint
cd $(TOOLS_MOD_DIR) && go install github.com/google/addlicense
cd $(TOOLS_MOD_DIR) && go install github.com/ory/go-acc
cd $(TOOLS_MOD_DIR) && go install github.com/pavius/impi/cmd/impi
benchmark:
go test ./... -run nosuchtest -benchmem -bench .