-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
80 lines (60 loc) · 3.36 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
GOLANGCI_LINT_VERSION=v1.60.1
LINTER=./bin/golangci-lint
LINTER_VERSION_FILE=./bin/.golangci-lint-version-$(GOLANGCI_LINT_VERSION)
ALL_SOURCES := $(shell find * -type f -name "*.go")
COVERAGE_PROFILE_RAW=./build/coverage_raw.out
COVERAGE_PROFILE_RAW_HTML=./build/coverage_raw.html
COVERAGE_PROFILE_FILTERED=./build/coverage.out
COVERAGE_PROFILE_FILTERED_HTML=./build/coverage.html
COVERAGE_ENFORCER_FLAGS=-skipcode "// COVERAGE" -packagestats -filestats -showcode
TEST_BINARY=./build/go-sdk-common.test
ALLOCATIONS_LOG=./build/allocations.out
EASYJSON_TAG=launchdarkly_easyjson
.PHONY: all build build-easyjson clean test test-easyjson test-coverage lint benchmarks benchmarks-easyjson benchmark-allocs
all: build build-easyjson
build:
go build ./...
build-easyjson:
go build -tags $(EASYJSON_TAG) ./...
clean:
go clean
test: build
go test -run=not-a-real-test ./... # just ensures that the tests compile
go test -v -race ./...
test-easyjson: build-easyjson
go test -run=not-a-real-test -tags $(EASYJSON_TAG) ./... # just ensures that the tests compile
go test -v -tags $(EASYJSON_TAG) -race ./...
test-coverage: $(COVERAGE_PROFILE_RAW)
go run github.com/launchdarkly-labs/go-coverage-enforcer@latest $(COVERAGE_ENFORCER_FLAGS) -outprofile $(COVERAGE_PROFILE_FILTERED) $(COVERAGE_PROFILE_RAW)
go tool cover -html $(COVERAGE_PROFILE_FILTERED) -o $(COVERAGE_PROFILE_FILTERED_HTML)
go tool cover -html $(COVERAGE_PROFILE_RAW) -o $(COVERAGE_PROFILE_RAW_HTML)
$(COVERAGE_PROFILE_RAW): $(ALL_SOURCES)
@mkdir -p ./build
go test -coverprofile $(COVERAGE_PROFILE_RAW) ./... >/dev/null
benchmarks: build
@mkdir -p ./build
go test -benchmem '-run=^$$' '-bench=.*' ./... | tee build/benchmarks.out
@if grep <build/benchmarks.out 'NoAlloc.*[1-9][0-9]* allocs/op'; then echo "Unexpected heap allocations detected in benchmarks!"; exit 1; fi
benchmarks-easyjson: build
@mkdir -p ./build
go test -tags $(EASYJSON_TAG) -benchmem '-run=^$$' '-bench=.*' ./... | tee build/benchmarks.out
# See CONTRIBUTING.md regarding the use of the benchmark-allocs target. Notes about this implementation:
# 1. We precompile the test code because otherwise the allocation traces will include the actions of the compiler itself.
# 2. "benchtime=3x" means the run count (b.N) is set to 3. Setting it to 1 would produce less redundant output, but the
# benchmark statistics seem to be less reliable if the run count is less than 3 - they will report a higher allocation
# count per run, possibly because the first run
benchmark-allocs:
@if [ -z "$$BENCHMARK" ]; then echo "must specify BENCHMARK=" && exit 1; fi
@if [ -z "$$BENCHMARK_PACKAGE" ]; then echo "must specify BENCHMARK_PACKAGE=" && exit 1; fi
@mkdir -p ./build
@echo Precompiling test code to $(TEST_BINARY)
@go test -c -o $(TEST_BINARY) $(BENCHMARK_PACKAGE) >/dev/null 2>&1
@echo "Generating heap allocation traces in $(ALLOCATIONS_LOG) for benchmark(s): $$BENCHMARK"
@echo "You should see some benchmark result output; if you do not, you may have misspelled the benchmark name/regex"
@GODEBUG=allocfreetrace=1 $(TEST_BINARY) -test.run=none -test.bench=$$BENCHMARK -test.benchmem -test.benchtime=1x 2>$(ALLOCATIONS_LOG)
$(LINTER_VERSION_FILE):
rm -f $(LINTER)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
touch $(LINTER_VERSION_FILE)
lint: $(LINTER_VERSION_FILE)
$(LINTER) run ./...