Skip to content

Commit

Permalink
Update Hellogopher
Browse files Browse the repository at this point in the history
  • Loading branch information
FiloSottile committed Feb 4, 2017
1 parent 6a0843a commit 513bf21
Showing 1 changed file with 62 additions and 16 deletions.
78 changes: 62 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# The import path is where your repository can be found.
# To import subpackages, always prepend the full import path.
# If you change this, run `make clean`. Read more: https://git.io/vM7zV
IMPORT_PATH := github.com/FiloSottile/b2
V := 1 # print commands and build progress by default
IGNORED_PACKAGES := /vendor/ # space separated patterns

.PHONY: b2
b2: .GOPATH/.ok
V := 1 # When V is set, print commands and build progress.

# Space separated patterns of packages to skip in list, test, format.
IGNORED_PACKAGES := /vendor/

.PHONY: build
build: .GOPATH/.ok
$Q go install $(if $V,-v) $(VERSION_FLAGS) $(IMPORT_PATH)

##### =====> Utility targets <===== #####
Expand All @@ -19,20 +25,23 @@ ifndef CI
$Q go vet $(allpackages)
$Q GODEBUG=cgocheck=2 go test -race $(allpackages)
else
$Q go vet $(allpackages) | tee .GOPATH/test/vet.txt
$Q GODEBUG=cgocheck=2 go test -v -race $(allpackages) | tee .GOPATH/test/output.txt
$Q ( go vet $(allpackages); echo $$? ) | \
tee .GOPATH/test/vet.txt | sed '$$ d'; exit $$(tail -1 .GOPATH/test/vet.txt)
$Q ( GODEBUG=cgocheck=2 go test -v -race $(allpackages); echo $$? ) | \
tee .GOPATH/test/output.txt | sed '$$ d'; exit $$(tail -1 .GOPATH/test/output.txt)
endif

list: .GOPATH/.ok
@echo $(allpackages)

cover: bin/gocovmerge .GOPATH/.ok
@echo "NOTE: make cover does not exit 1 on failure, don't use it to check for tests success!"
$Q rm -f .GOPATH/cover/*.out .GOPATH/cover/all.merged
$(if $V,@echo "-- go test -coverpkg=./... -coverprofile=.GOPATH/cover/... ./...")
$Q for MOD in $(allpackages); do \
@for MOD in $(allpackages); do \
go test -coverpkg=`echo $(allpackages)|tr " " ","` \
-coverprofile=.GOPATH/cover/unit-`echo $$MOD|tr "/" "_"`.out \
$$MOD 2>&1 | grep -v "no packages being tested depend on" || exit 1; \
$$MOD 2>&1 | grep -v "no packages being tested depend on"; \
done
$Q ./bin/gocovmerge .GOPATH/cover/*.out > .GOPATH/cover/all.merged
ifndef CI
Expand All @@ -46,25 +55,36 @@ endif
$Q go tool cover -func .GOPATH/cover/all.merged

format: bin/goimports .GOPATH/.ok
$Q find .GOPATH/src/$(IMPORT_PATH)/ -iname \*.go | grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)) | xargs ./bin/goimports -w
$Q find .GOPATH/src/$(IMPORT_PATH)/ -iname \*.go | grep -v \
-e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)) | xargs ./bin/goimports -w

##### =====> Internals <===== #####

ifdef CI
.DEFAULT_GOAL := test # Travis-CI runs just "make" by default
endif
.PHONY: setup
setup: clean .GOPATH/.ok
@if ! grep "/.GOPATH" .gitignore > /dev/null 2>&1; then \
echo "/.GOPATH" >> .gitignore; \
echo "/bin" >> .gitignore; \
fi
go get -u github.com/FiloSottile/gvt
- ./bin/gvt fetch golang.org/x/tools/cmd/goimports
- ./bin/gvt fetch github.com/wadey/gocovmerge

VERSION := $(shell git describe --tags --always --dirty="-dev")
DATE := $(shell date '+%Y-%m-%d-%H%M UTC')
DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
VERSION_FLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'

# cd into the GOPATH to workaround ./... not following symlinks (lazily computed)
allpackages = $(eval allpackages := $(shell ( cd $(CURDIR)/.GOPATH/src/$(IMPORT_PATH) && \
# cd into the GOPATH to workaround ./... not following symlinks
_allpackages = $(shell ( cd $(CURDIR)/.GOPATH/src/$(IMPORT_PATH) && \
GOPATH=$(CURDIR)/.GOPATH go list ./... 2>&1 1>&3 | \
grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)) 1>&2 ) 3>&1 | \
grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES))))$(allpackages)
grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)))

# memoize allpackages, so that it's executed only once and only if used
allpackages = $(if $(__allpackages),,$(eval __allpackages := $$(_allpackages)))$(__allpackages)

export GOPATH := $(CURDIR)/.GOPATH
unexport GOBIN

Q := $(if $V,,@)

Expand All @@ -78,6 +98,32 @@ Q := $(if $V,,@)

.PHONY: bin/gocovmerge bin/goimports
bin/gocovmerge: .GOPATH/.ok
@test -d ./vendor/github.com/wadey/gocovmerge || \
{ echo "Vendored gocovmerge not found, try running 'make setup'..."; exit 1; }
$Q go install $(IMPORT_PATH)/vendor/github.com/wadey/gocovmerge
bin/goimports: .GOPATH/.ok
@test -d ./vendor/golang.org/x/tools/cmd/goimports || \
{ echo "Vendored goimports not found, try running 'make setup'..."; exit 1; }
$Q go install $(IMPORT_PATH)/vendor/golang.org/x/tools/cmd/goimports

# Based on https://github.com/cloudflare/hellogopher - v1.1 - MIT License
#
# Copyright (c) 2017 Cloudflare
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

0 comments on commit 513bf21

Please sign in to comment.