Skip to content

Commit

Permalink
update golang.mk
Browse files Browse the repository at this point in the history
  • Loading branch information
rgarcia committed Jan 8, 2016
1 parent 5d688e9 commit 9287696
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
include golang.mk
.DEFAULT_GOAL :=
.DEFAULT_GOAL :=
PKGS := $(shell go list ./... | grep -v /vendor)
EXECUTABLEPKG := github.com/rgarcia/reposync
EXECUTABLE := reposync
VERSION := $(shell cat VERSION)

.PHONY: all build clean test vendor $(PKGS)

$(eval $(call golang-version-check,1.5))

all: test build

build:
Expand Down Expand Up @@ -46,7 +48,7 @@ release: $(RELEASE_ARTIFACTS)
$(GOPATH)/bin/github-release:
# assumes linux dev env
wget https://github.com/aktau/github-release/releases/download/v0.6.2/linux-amd64-github-release.tar.bz2
tar xjf linux-amd64-github-release.tar.bz2
tar xjf linux-amd64-github-release.tar.bz2
mv bin/linux/amd64/github-release $(GOPATH)/bin/github-release
rm -rf linux-amd64-github-release.tar.bz2 bin/linux

Expand Down
66 changes: 51 additions & 15 deletions golang.mk
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# This is the default Clever Golang Makefile.
# Please do not alter this file directly.
SHELL ?= /bin/bash
.PHONY: golang-godep-vendor golang-test-deps $(FGT) $(GODEP) $(GOLINT)
SHELL := /bin/bash
.PHONY: golang-godep-vendor golang-test-deps $(GODEP)

# This block checks and confirms that the proper Go toolchain version is installed.
# arg1: golang version
define golang-version-check
GOVERSION := $(shell go version | grep $(1))
_ := $(if \
$(shell go version | grep $(1)), \
@echo "", \
$(error "must be running Go version $(1)"))
endef

# This block checks and confirms that the Go toolchain installed is version 1.5
GOVERSION := $(shell go version | grep 1.6)
ifeq "$(GOVERSION)" ""
$(error must be running Go version 1.6)
endif
export GO15VENDOREXPERIMENT=1

# FGT is a utility that exits with 1 whenever any stderr/stdout output is recieved.
FGT := $(GOPATH)/bin/fgt
Expand All @@ -31,6 +37,7 @@ golang-godep-vendor-deps: $(GODEP)
# golang-godep-vendor is a target for saving dependencies with the godep tool
# to the vendor/ directory. All nested vendor/ directories are deleted as they
# are not handled well by the Go toolchain.
# arg1: pkg path
define golang-godep-vendor
$(GODEP) save $(1)
@# remove any nested vendor directories
Expand All @@ -41,6 +48,7 @@ endef
golang-fmt-deps: $(FGT)

# golang-fmt checks that all golang files in the pkg are formatted correctly.
# arg1: pkg path
define golang-fmt
@echo "FORMATTING $(1)..."
@$(FGT) gofmt -l=true $(GOPATH)/src/$(1)/*.go
Expand All @@ -50,36 +58,64 @@ endef
golang-lint-deps: $(GOLINT)

# golang-lint calls golint on all golang files in the pkg.
# arg1: pkg path
define golang-lint
@echo "LINTING $(1)..."
@$(GOLINT) $(GOPATH)/src/$(1)/*.go
endef

# golang-pkg-test-deps is here for consistency
golang-pkg-test-deps:
# golang-lint-deps-strict requires the golint tool for golang linting.
golang-lint-deps-strict: $(GOLINT) $(FGT)

# golang-lint-strict calls golint on all golang files in the pkg and fails if any lint
# errors are found.
# arg1: pkg path
define golang-lint-strict
@echo "LINTING $(1)..."
@$(FGT) $(GOLINT) $(GOPATH)/src/$(1)/*.go
endef

# golang-test-deps is here for consistency
golang-test-deps:

# golang-pkg-test uses the Go toolchain to run all tests in the pkg.
define golang-pkg-test
# golang-test uses the Go toolchain to run all tests in the pkg.
# arg1: pkg path
define golang-test
@echo "TESTING $(1)..."
@go test -v $(1)
endef

# golang-vet-deps is here for consistency
golang-vet-deps:

# golang-pkg-test uses the Go toolchain to vet all the pkg for common mistakes.
# golang-vet uses the Go toolchain to vet all the pkg for common mistakes.
# arg1: pkg path
define golang-vet
@echo "VETTING $(1)..."
@go vet $(GOPATH)/src/$(1)/*.go
endef

# golang-test-deps installs all dependencies needed for different test cases.
golang-test-all-deps: golang-fmt-deps golang-lint-deps golang-pkg-test-deps golang-vet-deps
# golang-test-all-deps installs all dependencies needed for different test cases.
golang-test-all-deps: golang-fmt-deps golang-lint-deps golang-test-deps golang-vet-deps

# golang-test-all calls fmt, lint, vet and test on the specified pkg.
# arg1: pkg path
define golang-test-all
$(call golang-fmt,$(1))
$(call golang-lint,$(1))
$(call golang-vet,$(1))
$(call golang-pkg-test,$(1))
$(call golang-test,$(1))
endef

# golang-test-all-deps-strict: installs all dependencies needed for different test cases.
golang-test-all-deps-strict: golang-fmt-deps golang-lint-deps-strict golang-test-deps golang-vet-deps

# golang-test-all-strict calls fmt, lint, vet and test on the specified pkg with strict
# requirements that no errors are thrown while linting.
# arg1: pkg path
define golang-test-all-strict
$(call golang-fmt,$(1))
$(call golang-lint-strict,$(1))
$(call golang-vet,$(1))
$(call golang-test,$(1))
endef

0 comments on commit 9287696

Please sign in to comment.