Skip to content

Commit

Permalink
ci(makefile): add dep option; use timestamp for fake gopath suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
qianbin committed Jun 20, 2018
1 parent b251623 commit 7e436dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -23,4 +23,6 @@ package.json
/node_modules/

/.vscode/
/vendor/
/vendor/

.fake_gopath_suffix
25 changes: 16 additions & 9 deletions Makefile
@@ -1,30 +1,37 @@
PACKAGE = github.com/vechain/thor

GIT_COMMIT = $(shell git --no-pager log --pretty="%h" -n 1)
FAKE_GOPATH = /tmp/thor-build-$(GIT_COMMIT)
FAKE_GOPATH_SUFFIX = $(shell [ -e ".fake_gopath_suffix" ] || date +%s > .fake_gopath_suffix; cat .fake_gopath_suffix)
FAKE_GOPATH = /tmp/thor-build-$(FAKE_GOPATH_SUFFIX)
export GOPATH = $(FAKE_GOPATH)

SRC_BASE = $(FAKE_GOPATH)/src/$(PACKAGE)

GIT_COMMIT = $(shell git --no-pager log --pretty="%h" -n 1)
GIT_TAG = $(shell git tag -l --points-at HEAD)
THOR_VERSION = $(shell cat cmd/thor/VERSION)
DISCO_VERSION = $(shell cat cmd/disco/VERSION)

THOR_VERSION = `cat cmd/thor/VERSION`
THOR_TAG = `git tag -l --points-at HEAD`
DISCO_VERSION = `cat cmd/disco/VERSION`
DISCO_TAG = `git tag -l --points-at HEAD`
PACKAGES = `cd $(SRC_BASE) && go list ./... | grep -v '/vendor/'`
PACKAGES = $(shell cd $(SRC_BASE) && go list ./... | grep -v '/vendor/')

.PHONY: thor disco all clean test

thor: |$(SRC_BASE)
@echo "building $@..."
@cd $(SRC_BASE) && go build -v -i -o $(CURDIR)/bin/$@ -ldflags "-X main.version=$(THOR_VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.gitTag=$(THOR_TAG)" ./cmd/thor
@cd $(SRC_BASE) && go build -v -i -o $(CURDIR)/bin/$@ -ldflags "-X main.version=$(THOR_VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.gitTag=$(GIT_TAG)" ./cmd/thor
@echo "done. executable created at 'bin/$@'"

disco: |$(SRC_BASE)
@echo "building $@..."
@cd $(SRC_BASE) && go build -v -i -o $(CURDIR)/bin/$@ -ldflags "-X main.version=$(DISCO_VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.gitTag=$(DISCO_TAG)" ./cmd/disco
@cd $(SRC_BASE) && go build -v -i -o $(CURDIR)/bin/$@ -ldflags "-X main.version=$(DISCO_VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.gitTag=$(GIT_TAG)" ./cmd/disco
@echo "done. executable created at 'bin/$@'"

dep:
ifeq ($(shell command -v dep 2> /dev/null),)
@git submodule update --init
else
@dep ensure
endif

$(SRC_BASE):
@mkdir -p $(dir $@)
@ln -sf $(CURDIR) $@
Expand Down

0 comments on commit 7e436dd

Please sign in to comment.