2018-08-02 00:37:21 +02:00
|
|
|
# Root directory of the project (absolute path).
|
|
|
|
ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
2015-06-10 19:48:33 +02:00
|
|
|
|
2015-01-30 00:32:49 +01:00
|
|
|
# Used to populate version variable in main package.
|
2015-04-01 20:28:34 +02:00
|
|
|
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
|
2018-08-02 00:37:21 +02:00
|
|
|
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
|
|
|
|
|
|
|
|
|
|
|
|
PKG=github.com/docker/distribution
|
|
|
|
|
|
|
|
# Project packages.
|
|
|
|
PACKAGES=$(shell go list -tags "${BUILDTAGS}" ./... | grep -v /vendor/)
|
|
|
|
INTEGRATION_PACKAGE=${PKG}
|
|
|
|
COVERAGE_PACKAGES=$(filter-out ${PKG}/registry/storage/driver/%,${PACKAGES})
|
|
|
|
|
|
|
|
|
|
|
|
# Project binaries.
|
|
|
|
COMMANDS=registry digest registry-api-descriptor-template
|
2015-06-10 19:48:33 +02:00
|
|
|
|
|
|
|
# Allow turning off function inlining and variable registerization
|
|
|
|
ifeq (${DISABLE_OPTIMIZATION},true)
|
|
|
|
GO_GCFLAGS=-gcflags "-N -l"
|
|
|
|
VERSION:="$(VERSION)-noopt"
|
|
|
|
endif
|
|
|
|
|
2018-08-02 00:37:21 +02:00
|
|
|
WHALE = "+"
|
2016-03-18 22:07:13 +01:00
|
|
|
|
2016-10-11 02:30:47 +02:00
|
|
|
# Go files
|
2018-08-02 00:37:21 +02:00
|
|
|
#
|
|
|
|
TESTFLAGS_RACE=
|
2016-10-11 02:30:47 +02:00
|
|
|
GOFILES=$(shell find . -type f -name '*.go')
|
2018-08-02 00:37:21 +02:00
|
|
|
GO_TAGS=$(if $(BUILDTAGS),-tags "$(BUILDTAGS)",)
|
|
|
|
GO_LDFLAGS=-ldflags '-s -w -X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) $(EXTRA_LDFLAGS)'
|
2016-10-11 02:30:47 +02:00
|
|
|
|
2018-08-02 00:37:21 +02:00
|
|
|
BINARIES=$(addprefix bin/,$(COMMANDS))
|
2016-03-18 22:07:13 +01:00
|
|
|
|
2018-08-02 00:37:21 +02:00
|
|
|
# Flags passed to `go test`
|
|
|
|
TESTFLAGS ?= -v $(TESTFLAGS_RACE)
|
|
|
|
TESTFLAGS_PARALLEL ?= 8
|
2016-03-21 20:08:47 +01:00
|
|
|
|
2018-08-02 00:37:21 +02:00
|
|
|
.PHONY: all build binaries check clean test test-race test-full integration coverage
|
|
|
|
.DEFAULT: all
|
2015-02-16 23:25:17 +01:00
|
|
|
|
2018-08-02 00:37:21 +02:00
|
|
|
all: binaries
|
2015-02-07 02:49:50 +01:00
|
|
|
|
2018-08-02 00:37:21 +02:00
|
|
|
AUTHORS: .mailmap .git/HEAD
|
|
|
|
git log --format='%aN <%aE>' | sort -fu > $@
|
2015-02-07 00:39:11 +01:00
|
|
|
|
2018-08-02 00:37:21 +02:00
|
|
|
# This only needs to be generated by hand when cutting full releases.
|
|
|
|
version/version.go:
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
./version/version.sh > $@
|
2015-02-07 00:39:11 +01:00
|
|
|
|
2018-08-02 00:37:21 +02:00
|
|
|
check: ## run all linters (TODO: enable "unused", "varcheck", "ineffassign", "unconvert", "staticheck", "goimports", "structcheck")
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
gometalinter --config .gometalinter.json ./...
|
|
|
|
|
|
|
|
test: ## run tests, except integration test with test.short
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go test ${GO_TAGS} -test.short ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES})
|
|
|
|
|
|
|
|
test-race: ## run tests, except integration test with test.short and race
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go test ${GO_TAGS} -race -test.short ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES})
|
|
|
|
|
|
|
|
test-full: ## run tests, except integration tests
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go test ${GO_TAGS} ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES})
|
|
|
|
|
|
|
|
integration: ## run integration tests
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go test ${TESTFLAGS} -parallel ${TESTFLAGS_PARALLEL} ${INTEGRATION_PACKAGE}
|
|
|
|
|
|
|
|
coverage: ## generate coverprofiles from the unit tests
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@rm -f coverage.txt
|
|
|
|
@go test ${GO_TAGS} -i ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${COVERAGE_PACKAGES}) 2> /dev/null
|
|
|
|
@( for pkg in $(filter-out ${INTEGRATION_PACKAGE},${COVERAGE_PACKAGES}); do \
|
|
|
|
go test ${GO_TAGS} ${TESTFLAGS} \
|
|
|
|
-cover \
|
|
|
|
-coverprofile=profile.out \
|
|
|
|
-covermode=atomic $$pkg || exit; \
|
|
|
|
if [ -f profile.out ]; then \
|
|
|
|
cat profile.out >> coverage.txt; \
|
|
|
|
rm profile.out; \
|
|
|
|
fi; \
|
|
|
|
done )
|
|
|
|
|
|
|
|
FORCE:
|
|
|
|
|
|
|
|
# Build a binary from a cmd.
|
|
|
|
bin/%: cmd/% FORCE
|
|
|
|
@echo "$(WHALE) $@${BINARY_SUFFIX}"
|
|
|
|
@go build ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@${BINARY_SUFFIX} ${GO_LDFLAGS} ${GO_TAGS} ./$<
|
|
|
|
|
|
|
|
binaries: $(BINARIES) ## build binaries
|
|
|
|
@echo "$(WHALE) $@"
|
2015-02-07 00:39:11 +01:00
|
|
|
|
|
|
|
build:
|
2018-08-02 00:37:21 +02:00
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go build ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${GO_LDFLAGS} ${GO_TAGS} $(PACKAGES)
|
|
|
|
|
|
|
|
clean: ## clean up binaries
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@rm -f $(BINARIES)
|