GOCC implementation & fix in make & build scripts
The usage of a native 'go' command has been replaced with a make & environment variable $GOCC. This enables building with multiple go versions on a single machine as documented: * https://golang.org/doc/install#extra_versions This enables the usage of: ```bash $ make install $ # OR $ GOCC=go1.12.3 make install $ # OR $ GOCC=go1.12.4 make install ``` And the build and test tools now pick up on this change On branch go-version-check Changes to be committed: modified: Rules.mk modified: bin/check_go_version modified: bin/dist_get modified: bin/maketarball.sh modified: coverage/Rules.mk modified: mk/golang.mk modified: mk/tarball.mk License: MIT Signed-off-by: Chris Buesser <christopher.buesser@gmail.com>
Christopher Buesser committed
Apr 30, 2019 at 21:22 UTC
f31dd2aae64719c53cf831ee8c4be898f495b025
7 files changed
+22
-12
Rules.mk
+2
-1
@@ -4,6 +4,7 @@ COVERAGE :=
4
DISTCLEAN :=
5
TEST :=
6
TEST_SHORT :=
7
+GOCC ?= go
8
9
all: help # all has to be first defined target
10
.PHONY: all
@@ -104,7 +105,7 @@ install_unsupported: install
105
.PHONY: install_unsupported
106
107
uninstall:
107
- go clean -i ./cmd/ipfs
108
+ $(GOCC) clean -i ./cmd/ipfs
109
.PHONY: uninstall
110
111
help:
bin/check_go_version
+5
-3
@@ -31,12 +31,14 @@ PREFIX=$(expr "$0" : "\(.*\/\)") || PREFIX='./'
31
32
# Check that the go binary exist and is in the path
33
34
-type go >/dev/null 2>&1 || die_upgrade "go is not installed or not in the PATH!"
34
+GOCC=${GOCC="go"}
35
+
36
+type ${GOCC} >/dev/null 2>&1 || die_upgrade "go is not installed or not in the PATH!"
37
38
# Check the go binary version
39
38
-VERS_STR=$(go version 2>&1) || die "'go version' failed with output: $VERS_STR"
40
+VERS_STR=$(${GOCC} version 2>&1) || die "'go version' failed with output: $VERS_STR"
41
42
GO_CUR_VERSION=$(expr "$VERS_STR" : ".*go version go\([^ ]*\) .*") || die "Invalid 'go version' output: $VERS_STR"
43
42
-check_at_least_version "$GO_MIN_VERSION" "$GO_CUR_VERSION" "go"
44
+check_at_least_version "$GO_MIN_VERSION" "$GO_CUR_VERSION" "${GOCC}"
bin/dist_get
+3
-1
@@ -1,5 +1,7 @@
1
#!/bin/sh
2
3
+GOCC=${GOCC=go}
4
+
5
die() {
6
echo "$@" >&2
7
exit 1
@@ -99,7 +101,7 @@ get_go_vars() {
101
if [ ! -z "$GOOS" ] && [ ! -z "$GOARCH" ]; then
102
printf "%s-%s" "$GOOS" "$GOARCH"
103
elif have_binary go; then
102
- printf "%s-%s" "$(go env GOOS)" "$(go env GOARCH)"
104
+ printf "%s-%s" "$($GOCC env GOOS)" "$($GOCC env GOARCH)"
105
else
106
die "no way of determining system GOOS and GOARCH\nPlease manually set GOOS and GOARCH then retry."
107
fi
bin/maketarball.sh
+3
-1
@@ -11,11 +11,13 @@ if ! [[ "$OUTPUT" = /* ]]; then
11
OUTPUT="$PWD/$OUTPUT"
12
fi
13
14
+GOCC=${GOCC=go}
15
+
16
TMPDIR="$(mktemp -d)"
17
cp -r . "$TMPDIR"
18
( cd "$TMPDIR" &&
19
echo $PWD &&
18
- go mod vendor &&
20
+ $GOCC mod vendor &&
21
(git describe --always --match=NeVeRmAtCh --dirty 2>/dev/null || true) > .tarball &&
22
chmod -R u=rwX,go=rX "$TMPDIR" # normalize permissions
23
tar -czf "$OUTPUT" --exclude="./.git" .
coverage/Rules.mk
+6
-4
@@ -1,5 +1,7 @@
1
include mk/header.mk
2
3
+GOCC ?= go
4
+
5
$(d)/coverage_deps: $$(DEPS_GO)
6
rm -rf $(@D)/unitcover && mkdir $(@D)/unitcover
7
rm -rf $(@D)/sharnesscover && mkdir $(@D)/sharnesscover
@@ -11,16 +13,16 @@ endif
13
.PHONY: $(d)/coverage_deps
14
15
# unit tests coverage
14
-UTESTS_$(d) := $(shell go list -f '{{if (len .TestGoFiles)}}{{.ImportPath}}{{end}}' $(go-flags-with-tags) ./...)
15
-UTESTS_$(d) += $(shell go list -f '{{if (len .XTestGoFiles)}}{{.ImportPath}}{{end}}' $(go-flags-with-tags) ./... | grep -v go-ipfs/vendor | grep -v go-ipfs/Godeps)
16
+UTESTS_$(d) := $(shell $(GOCC) list -f '{{if (len .TestGoFiles)}}{{.ImportPath}}{{end}}' $(go-flags-with-tags) ./...)
17
+UTESTS_$(d) += $(shell $(GOCC) list -f '{{if (len .XTestGoFiles)}}{{.ImportPath}}{{end}}' $(go-flags-with-tags) ./... | grep -v go-ipfs/vendor | grep -v go-ipfs/Godeps)
18
19
UCOVER_$(d) := $(addsuffix .coverprofile,$(addprefix $(d)/unitcover/, $(subst /,_,$(UTESTS_$(d)))))
20
21
$(UCOVER_$(d)): $(d)/coverage_deps ALWAYS
22
$(eval TMP_PKG := $(subst _,/,$(basename $(@F))))
21
- $(eval TMP_DEPS := $(shell go list -f '{{range .Deps}}{{.}} {{end}}' $(go-flags-with-tags) $(TMP_PKG) | sed 's/ /\n/g' | grep ipfs/go-ipfs) $(TMP_PKG))
23
+ $(eval TMP_DEPS := $(shell $(GOCC) list -f '{{range .Deps}}{{.}} {{end}}' $(go-flags-with-tags) $(TMP_PKG) | sed 's/ /\n/g' | grep ipfs/go-ipfs) $(TMP_PKG))
24
$(eval TMP_DEPS_LIST := $(call join-with,$(comma),$(TMP_DEPS)))
23
- go test $(go-flags-with-tags) $(GOTFLAGS) -v -covermode=atomic -json -coverpkg=$(TMP_DEPS_LIST) -coverprofile=$@ $(TMP_PKG) | tee -a test/unit/gotest.json
25
+ $(GOCC) test $(go-flags-with-tags) $(GOTFLAGS) -v -covermode=atomic -json -coverpkg=$(TMP_DEPS_LIST) -coverprofile=$@ $(TMP_PKG) | tee -a test/unit/gotest.json
26
27
28
$(d)/unit_tests.coverprofile: $(UCOVER_$(d))
mk/golang.mk
+1
-1
@@ -73,7 +73,7 @@ test_go_megacheck:
73
test_go: $(TEST_GO)
74
75
check_go_version:
76
- @go version
76
+ @$(GOCC) version
77
bin/check_go_version $(GO_MIN_VERSION)
78
.PHONY: check_go_version
79
DEPS_GO += check_go_version
mk/tarball.mk
+2
-1
@@ -8,6 +8,7 @@ tarball-is:=1
8
git-hash:=$(shell cat .tarball)
9
endif
10
11
+GOCC ?= go
12
13
go-ipfs-source.tar.gz: distclean
13
- bin/maketarball.sh $@
14
+ GOCC=$(GOCC) bin/maketarball.sh $@