Skip to content

Commit

Permalink
[BUILD] Use a temp build area for gotools
Browse files Browse the repository at this point in the history
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 <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed Nov 7, 2016
1 parent 22236d1 commit 26d78ea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
20 changes: 8 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions gotools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
1 change: 1 addition & 0 deletions scripts/goUnitTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 | \
Expand Down

0 comments on commit 26d78ea

Please sign in to comment.