Skip to content

Commit 26d78ea

Browse files
committed
[BUILD] Use a temp build area for gotools
It seems rather sloppy to spray files into the users $GOPATH, so lets clean this up. We still need to store the binaries in $GOPATH/bin for now to accomodate the CI process. We can clean this up later. Change-Id: I06809c35dbbaa7544ae838c7d2154a5b5e0f1bfb Signed-off-by: Greg Haskins <[email protected]>
1 parent 22236d1 commit 26d78ea

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

Makefile

+8-12
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ EXECUTABLES = go docker git curl
6060
K := $(foreach exec,$(EXECUTABLES),\
6161
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH: Check dependencies")))
6262

63-
# SUBDIRS are components that have their own Makefiles that we can invoke
64-
SUBDIRS = gotools
65-
SUBDIRS:=$(strip $(SUBDIRS))
66-
6763
GOSHIM_DEPS = $(shell ./scripts/goListFiles.sh $(PKGNAME)/core/chaincode/shim | sort | uniq)
6864
JAVASHIM_DEPS = $(shell git ls-files core/chaincode/shim/java)
6965
PROJECT_FILES = $(shell git ls-files)
@@ -74,9 +70,13 @@ all: peer orderer checks
7470

7571
checks: linter unit-test behave
7672

77-
.PHONY: $(SUBDIRS)
78-
$(SUBDIRS):
79-
cd $@ && $(MAKE)
73+
.PHONY: gotools
74+
gotools:
75+
mkdir -p build/bin
76+
cd gotools && $(MAKE) install BINDIR=$(GOPATH)/bin
77+
78+
gotools-clean:
79+
cd gotools && $(MAKE) clean
8080

8181
membersrvc-image:
8282
@echo "membersrvc has been removed from this build"
@@ -252,12 +252,8 @@ src-image-clean: ccenv-image-clean peer-image-clean orderer-image-clean
252252

253253
images-clean: $(patsubst %,%-image-clean, $(IMAGES))
254254

255-
.PHONY: $(SUBDIRS:=-clean)
256-
$(SUBDIRS:=-clean):
257-
cd $(patsubst %-clean,%,$@) && $(MAKE) clean
258-
259255
.PHONY: clean
260-
clean: images-clean $(filter-out gotools-clean, $(SUBDIRS:=-clean))
256+
clean: images-clean
261257
-@rm -rf build ||:
262258

263259
.PHONY: dist-clean

gotools/Makefile

+20-10
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@
1616
# under the License.
1717
#
1818

19+
BINDIR ?= /usr/local/bin
20+
OBJDIR ?= build
21+
22+
TMP_GOPATH=$(OBJDIR)/gopath
23+
GOBIN=$(TMP_GOPATH)/bin
24+
1925
GOTOOLS = golint govendor goimports protoc-gen-go ginkgo gocov gocov-xml
20-
GOTOOLS_BIN = $(patsubst %,$(GOPATH)/bin/%, $(GOTOOLS))
26+
GOTOOLS_BIN = $(patsubst %,$(GOBIN)/%, $(GOTOOLS))
2127

2228
# go tool->path mapping
2329
go.fqp.govendor := github.com/kardianos/govendor
@@ -29,23 +35,27 @@ go.fqp.gocov-xml := github.com/AlekSi/gocov-xml
2935

3036
all: $(GOTOOLS_BIN)
3137

38+
install: $(GOTOOLS_BIN)
39+
@mkdir -p $(BINDIR)
40+
cp $^ $(BINDIR)
41+
3242
# Special override for protoc-gen-go since we want to use the version vendored with the project
3343
gotool.protoc-gen-go:
34-
mkdir -p $(GOPATH)/src/github.com/golang/protobuf/
35-
cp -R $(GOPATH)/src/github.com/hyperledger/fabric/vendor/github.com/golang/protobuf/ $(GOPATH)/src/github.com/golang/
36-
go install github.com/golang/protobuf/protoc-gen-go
37-
rm -rf $(GOPATH)/src/github.com/golang/protobuf
44+
@echo "Building github.com/golang/protobuf/protoc-gen-go -> protoc-gen-go"
45+
@mkdir -p $(TMP_GOPATH)/src/github.com/golang/protobuf/
46+
@cp -R $(GOPATH)/src/github.com/hyperledger/fabric/vendor/github.com/golang/protobuf/* $(TMP_GOPATH)/src/github.com/golang/protobuf
47+
@GOPATH=$(abspath $(TMP_GOPATH)) go install github.com/golang/protobuf/protoc-gen-go
3848

3949
# Default rule for gotools uses the name->path map for a generic 'go get' style build
4050
gotool.%:
4151
$(eval TOOL = ${subst gotool.,,${@}})
42-
@echo "Building $(TOOL)"
43-
go get ${go.fqp.${TOOL}}
52+
@echo "Building ${go.fqp.${TOOL}} -> $(TOOL)"
53+
@GOPATH=$(abspath $(TMP_GOPATH)) go get ${go.fqp.${TOOL}}
4454

45-
$(GOPATH)/bin/%:
46-
$(eval TOOL = ${subst $(GOPATH)/bin/,,${@}})
55+
$(GOBIN)/%:
56+
$(eval TOOL = ${subst $(GOBIN)/,,${@}})
4757
@$(MAKE) gotool.$(TOOL)
4858

4959
.PHONY: clean
5060
clean:
51-
-@rm -f $(GOTOOLS_BIN) ||:
61+
-@rm -rf $(OBJDIR)

scripts/goUnitTests.sh

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ echo "Running unit tests using $IMAGE"
1818
echo -n "Obtaining list of tests to run.."
1919
# Some examples don't play nice with `go test`
2020
PKGS=`go list github.com/hyperledger/fabric/... | grep -v /vendor/ | \
21+
grep -v /build/ | \
2122
grep -v /examples/chaincode/chaintool/ | \
2223
grep -v /examples/chaincode/go/asset_management | \
2324
grep -v /examples/chaincode/go/utxo | \

0 commit comments

Comments
 (0)