2016-12-01 20:04:23 +00:00
# Root directory of the project (absolute path).
ROOTDIR = $( dir $( abspath $( lastword $( MAKEFILE_LIST) ) ) )
# Base path used to install.
DESTDIR = /usr/local
# Used to populate version variable in main package.
VERSION = $( shell git describe --match 'v[0-9]*' --dirty= '.m' --always)
PROJECT_ROOT = github.com/docker/containerd
# Project packages.
PACKAGES = $( shell go list ./... | grep -v /vendor/)
INTEGRATION_PACKAGE = ${ PROJECT_ROOT } /integration
2017-01-25 00:10:48 +00:00
SNAPSHOT_PACKAGES = $( shell go list ./snapshot/...)
2016-12-01 20:04:23 +00:00
# Project binaries.
2017-01-24 04:26:19 +00:00
COMMANDS = ctr containerd containerd-shim protoc-gen-gogoctrd dist
2016-12-01 20:04:23 +00:00
BINARIES = $( addprefix bin/,$( COMMANDS) )
# TODO(stevvooe): This will set version from git tag, but overrides major,
# minor, patch in the actual file. We'll have to resolve this before release
# time.
GO_LDFLAGS = -ldflags " -X `go list`.Version= $( VERSION) "
2017-01-13 04:28:24 +00:00
# Flags passed to `go test`
TESTFLAGS ?= -parallel 8 -race
2017-01-12 19:21:06 +00:00
.PHONY : clean all AUTHORS fmt vet lint build binaries test integration setup generate checkprotos coverage ci check help install uninstall vendor
2016-12-01 20:04:23 +00:00
.DEFAULT : default
2016-12-12 18:32:54 +00:00
all : binaries
2016-12-01 20:04:23 +00:00
check : fmt vet lint ineffassign ## run fmt, vet, lint, ineffassign
ci : check binaries checkprotos coverage coverage -integration ## to be used by the CI
AUTHORS : .mailmap .git /HEAD
git log --format= '%aN <%aE>' | sort -fu > $@
setup : ## install dependencies
@echo " 🐳 $@ "
# TODO(stevvooe): Install these from the vendor directory
@go get -u github.com/golang/lint/golint
#@go get -u github.com/kisielk/errcheck
@go get -u github.com/gordonklaus/ineffassign
generate : bin /protoc -gen -gogoctrd ## generate protobuf
@echo " 🐳 $@ "
2017-02-09 07:31:26 +00:00
@tools/gen-gen-go.sh
2016-12-01 20:04:23 +00:00
@PATH= ${ ROOTDIR } /bin:${ PATH } go generate -x ${ PACKAGES }
checkprotos : generate ## check if protobufs needs to be generated again
@echo " 🐳 $@ "
@test -z " $$ (git status --short | grep " .pb.go" | tee /dev/stderr)" || \
( ( git diff | cat) && \
( echo "👹 please run 'make generate' when making changes to proto files" && false ) )
# Depends on binaries because vet will silently fail if it can't load compiled
# imports
vet : binaries ## run go vet
@echo " 🐳 $@ "
@test -z " $$ (go vet ${ PACKAGES } 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | egrep -v '(timestamp_test.go|duration_test.go|exit status 1)' | tee /dev/stderr) "
fmt : ## run go fmt
@echo " 🐳 $@ "
@test -z " $$ (gofmt -s -l . | grep -v vendor/ | grep -v " .pb.go$$ " | tee /dev/stderr)" || \
( echo "👹 please format Go code with 'gofmt -s -w'" && false )
@test -z " $$ (find . -path ./vendor -prune -o ! -name timestamp.proto ! -name duration.proto -name '*.proto' -type f -exec grep -Hn -e " ^ " {} \; | tee /dev/stderr)" || \
( echo "👹 please indent proto files with tabs only" && false )
2016-12-01 20:22:05 +00:00
@test -z " $$ (find . -path ./vendor -prune -o -name '*.proto' -type f -exec grep -EHn " [ _ ] id = " {} \; | grep -v gogoproto.customname | tee /dev/stderr)" || \
2016-12-01 20:04:23 +00:00
( echo "👹 id fields in proto files must have a gogoproto.customname set" && false )
@test -z " $$ (find . -path ./vendor -prune -o -name '*.proto' -type f -exec grep -Hn " Meta meta = " {} \; | grep -v '(gogoproto.nullable) = false' | tee /dev/stderr)" || \
( echo "👹 meta fields in proto files must have option (gogoproto.nullable) = false" && false )
lint : ## run go lint
@echo " 🐳 $@ "
2016-12-01 20:11:47 +00:00
@test -z " $$ (golint ./... | grep -v vendor/ | grep -v " .pb.go:" | tee /dev/stderr)"
2016-12-01 20:04:23 +00:00
ineffassign : ## run ineffassign
@echo " 🐳 $@ "
2016-12-01 20:11:47 +00:00
@test -z " $$ (ineffassign . | grep -v vendor/ | grep -v " .pb.go:" | tee /dev/stderr)"
2016-12-01 20:04:23 +00:00
#errcheck: ## run go errcheck
# @echo "🐳 $@"
2016-12-01 20:11:47 +00:00
# @test -z "$$(errcheck ./... | grep -v vendor/ | grep -v ".pb.go:" | tee /dev/stderr)"
2016-12-01 20:04:23 +00:00
build : ## build the go packages
@echo " 🐳 $@ "
2017-01-13 04:28:24 +00:00
@go build -i -v ${ GO_LDFLAGS } ${ GO_GCFLAGS } ${ PACKAGES }
2016-12-01 20:04:23 +00:00
2017-01-25 00:10:48 +00:00
test : ## run tests, except integration tests and tests that require root
2016-12-01 20:04:23 +00:00
@echo " 🐳 $@ "
2017-01-13 04:28:24 +00:00
@go test ${ TESTFLAGS } $( filter-out ${ INTEGRATION_PACKAGE } ,${ PACKAGES } )
2016-12-01 20:04:23 +00:00
2017-01-25 00:10:48 +00:00
root-test : ## run tests, except integration tests
@echo " 🐳 $@ "
@go test ${ TESTFLAGS } ${ SNAPSHOT_PACKAGES } -test.root
2016-12-01 20:04:23 +00:00
integration : ## run integration tests
@echo " 🐳 $@ "
2017-01-13 04:28:24 +00:00
@go test ${ TESTFLAGS } ${ INTEGRATION_PACKAGE }
2016-12-01 20:04:23 +00:00
2017-01-19 01:26:14 +00:00
FORCE :
2016-12-01 20:04:23 +00:00
# Build a binary from a cmd.
2017-01-19 01:26:14 +00:00
bin/% : cmd /% FORCE
2016-12-01 20:04:23 +00:00
@test $$ ( go list) = " ${ PROJECT_ROOT } " || \
2017-01-19 01:26:14 +00:00
( echo " 👹 Please correctly set up your Go build environment. This project must be located at <GOPATH>/src/ ${ PROJECT_ROOT } " && false )
2016-12-01 20:04:23 +00:00
@echo " 🐳 $@ "
2017-01-13 04:28:24 +00:00
@go build -i -o $@ ${ GO_LDFLAGS } ${ GO_GCFLAGS } ./$<
2016-12-01 20:04:23 +00:00
binaries : $( BINARIES ) ## build binaries
@echo " 🐳 $@ "
clean : ## clean up binaries
@echo " 🐳 $@ "
@rm -f $( BINARIES)
2017-01-13 03:53:00 +00:00
install : ## install binaries
@echo " 🐳 $@ $( BINARIES) "
2016-12-01 20:04:23 +00:00
@mkdir -p $( DESTDIR) /bin
@install $( BINARIES) $( DESTDIR) /bin
uninstall :
@echo " 🐳 $@ "
@rm -f $( addprefix $( DESTDIR) /bin/,$( notdir $( BINARIES) ) )
2017-01-25 00:10:48 +00:00
coverage : ## generate coverprofiles from the unit tests, except tests that require root
2016-12-01 20:04:23 +00:00
@echo " 🐳 $@ "
2017-01-11 22:51:06 +00:00
@rm -f coverage.txt
( for pkg in $( filter-out ${ INTEGRATION_PACKAGE } ,${ PACKAGES } ) ; do \
go test -i ${ TESTFLAGS } -test.short -coverprofile= coverage.out -covermode= atomic $$ pkg || exit; \
if [ -f profile.out ] ; then \
cat profile.out >> coverage.txt; \
rm profile.out; \
fi ; \
go test ${ TESTFLAGS } -test.short -coverprofile= coverage.out -covermode= atomic $$ pkg || exit; \
if [ -f profile.out ] ; then \
cat profile.out >> coverage.txt; \
rm profile.out; \
fi ; \
2016-12-01 20:04:23 +00:00
done )
2017-01-25 00:10:48 +00:00
root-coverage : ## generae coverage profiles for the unit tests
@echo " 🐳 $@ "
@( for pkg in ${ SNAPSHOT_PACKAGES } ; do \
go test -i ${ TESTFLAGS } -test.short -coverprofile= " ../../../ $$ pkg/coverage.txt " -covermode= atomic $$ pkg -test.root || exit; \
go test ${ TESTFLAGS } -test.short -coverprofile= " ../../../ $$ pkg/coverage.txt " -covermode= atomic $$ pkg -test.root || exit; \
done )
2016-12-01 20:04:23 +00:00
coverage-integration : ## generate coverprofiles from the integration tests
@echo " 🐳 $@ "
2017-01-13 04:28:24 +00:00
go test ${ TESTFLAGS } -test.short -coverprofile= " ../../../ ${ INTEGRATION_PACKAGE } /coverage.txt " -covermode= atomic ${ INTEGRATION_PACKAGE }
2016-12-01 20:04:23 +00:00
2017-01-12 19:21:06 +00:00
vendor :
@echo " 🐳 $@ "
@vndr
2016-12-01 20:04:23 +00:00
help : ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $( MAKEFILE_LIST) | sort