golang.mk 1.71 KB
Newer Older
1
# golang utilities
Jakub Sztandera's avatar
Jakub Sztandera committed
2
GO_MIN_VERSION = 1.12
3
export GO111MODULE=on
4

5

6
# pre-definitions
7
GOCC ?= go
8
GOTAGS ?=
Steven Allen's avatar
Steven Allen committed
9
unexport GOFLAGS
10 11 12
GOFLAGS ?=
GOTFLAGS ?=

13 14 15 16
ifeq ($(tarball-is),1)
	GOFLAGS += -mod=vendor
endif

Jakub Sztandera's avatar
Jakub Sztandera committed
17 18 19
# match Go's default GOPATH behaviour
export GOPATH ?= $(shell $(GOCC) env GOPATH)

20 21
DEPS_GO :=
TEST_GO :=
22
TEST_GO_BUILD :=
23 24
CHECK_GO :=

25
go-pkg-name=$(shell $(GOCC) list $(go-tags) github.com/ipfs/go-ipfs/$(1))
26 27
go-main-name=$(notdir $(call go-pkg-name,$(1)))$(?exe)
go-curr-pkg-tgt=$(d)/$(call go-main-name,$(d))
Steven Allen's avatar
Steven Allen committed
28
go-pkgs=$(shell $(GOCC) list github.com/ipfs/go-ipfs/...)
29

Jakub Sztandera's avatar
Jakub Sztandera committed
30
go-tags=$(if $(GOTAGS), -tags="$(call join-with,$(space),$(GOTAGS))")
31 32
go-flags-with-tags=$(GOFLAGS)$(go-tags)

33
define go-build-relative
Łukasz Magiera's avatar
Łukasz Magiera committed
34
$(GOCC) build $(go-flags-with-tags) -o "$@" "$(call go-pkg-name,$<)"
35 36
endef

37 38 39 40
define go-build
$(GOCC) build $(go-flags-with-tags) -o "$@" "$(1)"
endef

41 42 43 44
define go-try-build
$(GOCC) build $(go-flags-with-tags) -o /dev/null "$(call go-pkg-name,$<)"
endef

45 46 47 48
test_go_test: $$(DEPS_GO)
	$(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) ./...
.PHONY: test_go_test

49
test_go_short: GOTFLAGS += -test.short
50
test_go_short: test_go_test
51 52 53
.PHONY: test_go_short

test_go_race: GOTFLAGS += -race
54
test_go_race: test_go_test
55 56
.PHONY: test_go_race

57
test_go_expensive: test_go_test $$(TEST_GO_BUILD)
58 59 60 61 62 63 64 65
.PHONY: test_go_expensive
TEST_GO += test_go_expensive

test_go_fmt:
	bin/test-go-fmt
.PHONY: test_go_fmt
TEST_GO += test_go_fmt

66
test_go_megacheck:
67
	@$(GOCC) get honnef.co/go/tools/cmd/megacheck
Steven Allen's avatar
Steven Allen committed
68
	@for pkg in $(go-pkgs); do megacheck "$$pkg"; done
69 70
.PHONY: megacheck

71 72 73
test_go: $(TEST_GO)

check_go_version:
Jakub Sztandera's avatar
Jakub Sztandera committed
74
	@go version
75 76
	bin/check_go_version $(GO_MIN_VERSION)
.PHONY: check_go_version
Jakub Sztandera's avatar
Jakub Sztandera committed
77
DEPS_GO += check_go_version
78 79 80

TEST += $(TEST_GO)
TEST_SHORT += test_go_fmt test_go_short