From 26d78ea1d7b3ec941fa77a8daf5dc6eace1dc04b Mon Sep 17 00:00:00 2001 From: Gregory Haskins Date: Fri, 4 Nov 2016 15:12:07 -0400 Subject: [PATCH] [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 --- Makefile | 20 ++++++++------------ gotools/Makefile | 30 ++++++++++++++++++++---------- scripts/goUnitTests.sh | 1 + 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 92e4fc14280..b4d981f6a44 100644 --- a/Makefile +++ b/Makefile @@ -60,10 +60,6 @@ EXECUTABLES = go docker git curl K := $(foreach exec,$(EXECUTABLES),\ $(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH: Check dependencies"))) -# SUBDIRS are components that have their own Makefiles that we can invoke -SUBDIRS = gotools -SUBDIRS:=$(strip $(SUBDIRS)) - GOSHIM_DEPS = $(shell ./scripts/goListFiles.sh $(PKGNAME)/core/chaincode/shim | sort | uniq) JAVASHIM_DEPS = $(shell git ls-files core/chaincode/shim/java) PROJECT_FILES = $(shell git ls-files) @@ -74,9 +70,13 @@ all: peer orderer checks checks: linter unit-test behave -.PHONY: $(SUBDIRS) -$(SUBDIRS): - cd $@ && $(MAKE) +.PHONY: gotools +gotools: + mkdir -p build/bin + cd gotools && $(MAKE) install BINDIR=$(GOPATH)/bin + +gotools-clean: + cd gotools && $(MAKE) clean membersrvc-image: @echo "membersrvc has been removed from this build" @@ -252,12 +252,8 @@ src-image-clean: ccenv-image-clean peer-image-clean orderer-image-clean images-clean: $(patsubst %,%-image-clean, $(IMAGES)) -.PHONY: $(SUBDIRS:=-clean) -$(SUBDIRS:=-clean): - cd $(patsubst %-clean,%,$@) && $(MAKE) clean - .PHONY: clean -clean: images-clean $(filter-out gotools-clean, $(SUBDIRS:=-clean)) +clean: images-clean -@rm -rf build ||: .PHONY: dist-clean diff --git a/gotools/Makefile b/gotools/Makefile index eb3e25dcd80..bccc048571b 100644 --- a/gotools/Makefile +++ b/gotools/Makefile @@ -16,8 +16,14 @@ # under the License. # +BINDIR ?= /usr/local/bin +OBJDIR ?= build + +TMP_GOPATH=$(OBJDIR)/gopath +GOBIN=$(TMP_GOPATH)/bin + GOTOOLS = golint govendor goimports protoc-gen-go ginkgo gocov gocov-xml -GOTOOLS_BIN = $(patsubst %,$(GOPATH)/bin/%, $(GOTOOLS)) +GOTOOLS_BIN = $(patsubst %,$(GOBIN)/%, $(GOTOOLS)) # go tool->path mapping go.fqp.govendor := github.com/kardianos/govendor @@ -29,23 +35,27 @@ go.fqp.gocov-xml := github.com/AlekSi/gocov-xml all: $(GOTOOLS_BIN) +install: $(GOTOOLS_BIN) + @mkdir -p $(BINDIR) + cp $^ $(BINDIR) + # Special override for protoc-gen-go since we want to use the version vendored with the project gotool.protoc-gen-go: - mkdir -p $(GOPATH)/src/github.com/golang/protobuf/ - cp -R $(GOPATH)/src/github.com/hyperledger/fabric/vendor/github.com/golang/protobuf/ $(GOPATH)/src/github.com/golang/ - go install github.com/golang/protobuf/protoc-gen-go - rm -rf $(GOPATH)/src/github.com/golang/protobuf + @echo "Building github.com/golang/protobuf/protoc-gen-go -> protoc-gen-go" + @mkdir -p $(TMP_GOPATH)/src/github.com/golang/protobuf/ + @cp -R $(GOPATH)/src/github.com/hyperledger/fabric/vendor/github.com/golang/protobuf/* $(TMP_GOPATH)/src/github.com/golang/protobuf + @GOPATH=$(abspath $(TMP_GOPATH)) go install github.com/golang/protobuf/protoc-gen-go # Default rule for gotools uses the name->path map for a generic 'go get' style build gotool.%: $(eval TOOL = ${subst gotool.,,${@}}) - @echo "Building $(TOOL)" - go get ${go.fqp.${TOOL}} + @echo "Building ${go.fqp.${TOOL}} -> $(TOOL)" + @GOPATH=$(abspath $(TMP_GOPATH)) go get ${go.fqp.${TOOL}} -$(GOPATH)/bin/%: - $(eval TOOL = ${subst $(GOPATH)/bin/,,${@}}) +$(GOBIN)/%: + $(eval TOOL = ${subst $(GOBIN)/,,${@}}) @$(MAKE) gotool.$(TOOL) .PHONY: clean clean: - -@rm -f $(GOTOOLS_BIN) ||: + -@rm -rf $(OBJDIR) diff --git a/scripts/goUnitTests.sh b/scripts/goUnitTests.sh index 360cae041d0..a0b365e4df5 100755 --- a/scripts/goUnitTests.sh +++ b/scripts/goUnitTests.sh @@ -18,6 +18,7 @@ echo "Running unit tests using $IMAGE" echo -n "Obtaining list of tests to run.." # Some examples don't play nice with `go test` PKGS=`go list github.com/hyperledger/fabric/... | grep -v /vendor/ | \ + grep -v /build/ | \ grep -v /examples/chaincode/chaintool/ | \ grep -v /examples/chaincode/go/asset_management | \ grep -v /examples/chaincode/go/utxo | \