-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
93 lines (78 loc) · 3.35 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
.DEFAULT_GOAL = test
extension = $(patsubst windows,.exe,$(filter windows,$(1)))
GOOS ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\1/')
GOARCH ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\2/')
ifeq ("$(TARGETVARIANT)","")
ifneq ("$(GOARM)","")
TARGETVARIANT := v$(GOARM)
endif
else
ifeq ("$(GOARM)","")
GOARM ?= $(subst v,,$(TARGETVARIANT))
endif
endif
ifeq ("$(CI)","true")
LINT_PROCS ?= 1
else
LINT_PROCS ?= $(shell nproc)
endif
# test with race detector on supported platforms
# windows/amd64 is supported in theory, but in practice it requires a C compiler
race_platforms := 'linux/amd64' 'darwin/amd64' 'darwin/arm64'
ifeq (,$(findstring '$(GOOS)/$(GOARCH)',$(race_platforms)))
export CGO_ENABLED=0
TEST_ARGS=
else
TEST_ARGS=-race
endif
test:
go test $(TEST_ARGS) -coverprofile=c.out ./...
bin/fscli_%v7$(call extension,$(GOOS)): $(shell find . -type f -name "*.go")
GOOS=$(shell echo $* | cut -f1 -d-) \
GOARCH=$(shell echo $* | cut -f2 -d- ) \
GOARM=7 \
CGO_ENABLED=0 \
go build $(BUILD_ARGS) -o $@ ./examples/fscli
bin/fscli_windows-%.exe: $(shell find . -type f -name "*.go")
GOOS=windows \
GOARCH=$* \
GOARM= \
CGO_ENABLED=0 \
go build $(BUILD_ARGS) -o $@ ./examples/fscli
bin/fscli_%$(TARGETVARIANT)$(call extension,$(GOOS)): $(shell find . -type f -name "*.go")
GOOS=$(shell echo $* | cut -f1 -d-) \
GOARCH=$(shell echo $* | cut -f2 -d- ) \
GOARM=$(GOARM) \
CGO_ENABLED=0 \
go build $(BUILD_ARGS) -o $@ ./examples/fscli
lint:
@golangci-lint run --verbose --max-same-issues=0 --max-issues-per-linter=0
ci-lint:
@golangci-lint run --verbose --max-same-issues=0 --max-issues-per-linter=0 --out-format=github-actions
ifneq ("$(VERSION)","")
release:
git tag -sm "Releasing v$(VERSION)" v$(VERSION) && git push --tags
gh release create v$(VERSION) --draft --generate-notes
endif
# this is a special target for testing a package on Windows from a non-Windows
# host. It builds the Windows test binary, then SCPs it to the Windows host, and
# runs the tests there. This depends on the GO_REMOTE_WINDOWS environment
# variable being set as 'username@host'. The Windows host must have Git Bash
# installed, or maybe MSYS2, so that a number of standard Unix tools are
# available. Git must also be configured with a username and email address. See
# the GitHub workflow config in .github/workflows/build.yml for hints.
# A recent PowerShell is also required, such as version 7.3 or later.
#
# An F: drive is expected to be available, with a tmp directory. This is used
# to make sure we can deal with files on a different volume.
.SECONDEXPANSION:
$(shell go list -f '{{ if not (eq "" (join .TestGoFiles "")) }}testbin/{{.ImportPath}}.test.exe.remote{{end}}' ./...): $$(shell go list -f '{{.Dir}}' $$(subst testbin/,,$$(subst .test.exe.remote,,$$@)))
@echo $<
@GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go test -tags timetzdata -c -o ./testbin/remote-test.exe $<
@scp -q ./testbin/remote-test.exe $(GO_REMOTE_WINDOWS):/$(shell ssh $(GO_REMOTE_WINDOWS) 'echo %TEMP%' | cut -f2 -d= | sed -e 's#\\#/#g')/
@ssh -o 'SetEnv TMP=F:\tmp' $(GO_REMOTE_WINDOWS) '%TEMP%\remote-test.exe'
# test-remote-windows runs the above target for all packages that have tests
test-remote-windows: $(shell go list -f '{{ if not (eq "" (join .TestGoFiles "")) }}testbin/{{.ImportPath}}.test.exe.remote{{end}}' ./...)
.PHONY: test lint ci-lint
.DELETE_ON_ERROR:
.SECONDARY: