golang.mk 1.47 KB
Newer Older
1
# golang utilities
Łukasz Magiera's avatar
Łukasz Magiera committed
2
GO_MIN_VERSION = 1.8
3 4 5 6 7 8 9 10 11 12

# pre-definitions
GOTAGS ?=
GOFLAGS ?=
GOTFLAGS ?=

DEPS_GO :=
TEST_GO :=
CHECK_GO :=

13
go-pkg-name=$(shell go list $(go-tags) github.com/ipfs/go-ipfs/$(1))
14 15
go-main-name=$(notdir $(call go-pkg-name,$(1)))$(?exe)
go-curr-pkg-tgt=$(d)/$(call go-main-name,$(d))
16
go-pkgs-novendor=$(shell go list github.com/ipfs/go-ipfs/... | grep -v /Godeps/)
17

Jakub Sztandera's avatar
Jakub Sztandera committed
18
go-tags=$(if $(GOTAGS), -tags="$(call join-with,$(space),$(GOTAGS))")
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
go-flags-with-tags=$(GOFLAGS)$(go-tags)

define go-build
go build -i $(go-flags-with-tags) -o "$@" "$(call go-pkg-name,$<)"
endef

test_go_short: GOTFLAGS += -test.short
test_go_short: test_go_expensive
.PHONY: test_go_short

test_go_race: GOTFLAGS += -race
test_go_race: test_go_expensive
.PHONY: test_go_race

test_go_expensive: $$(DEPS_GO)
	go test $(go-flags-with-tags) $(GOTFLAGS) ./...
.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

43 44 45 46 47
test_go_megacheck:
	@go get honnef.co/go/tools/cmd/megacheck
	@for pkg in $(go-pkgs-novendor); do megacheck "$$pkg"; done
.PHONY: megacheck

48 49 50 51 52
test_go: $(TEST_GO)

check_go_version:
	bin/check_go_version $(GO_MIN_VERSION)
.PHONY: check_go_version
Jakub Sztandera's avatar
Jakub Sztandera committed
53
DEPS_GO += check_go_version
54

55 56 57 58 59
check_go_path:
	bin/check_go_path $(realpath $(shell pwd)) $(realpath $(addsuffix /src/github.com/ipfs/go-ipfs,$(subst $(PATH_SEP),$(space),$(GOPATH))))
.PHONY: check_go_path
DEPS_GO += check_go_path

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