2018-08-01 22:37:21 +00:00
|
|
|
# Root directory of the project (absolute path).
|
|
|
|
ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
2015-06-10 17:48:33 +00:00
|
|
|
|
2015-01-29 23:32:49 +00:00
|
|
|
# Used to populate version variable in main package.
|
2015-04-01 18:28:34 +00:00
|
|
|
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
|
2018-08-01 22:37:21 +00: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 17:48:33 +00:00
|
|
|
|
|
|
|
# Allow turning off function inlining and variable registerization
|
|
|
|
ifeq (${DISABLE_OPTIMIZATION},true)
|
|
|
|
GO_GCFLAGS=-gcflags "-N -l"
|
|
|
|
VERSION:="$(VERSION)-noopt"
|
|
|
|
endif
|
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
WHALE = "+"
|
2016-03-18 21:07:13 +00:00
|
|
|
|
2016-10-11 00:30:47 +00:00
|
|
|
# Go files
|
2018-08-01 22:37:21 +00:00
|
|
|
#
|
|
|
|
TESTFLAGS_RACE=
|
2016-10-11 00:30:47 +00:00
|
|
|
GOFILES=$(shell find . -type f -name '*.go')
|
2018-08-01 22:37:21 +00: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 00:30:47 +00:00
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
BINARIES=$(addprefix bin/,$(COMMANDS))
|
2016-03-18 21:07:13 +00:00
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
# Flags passed to `go test`
|
|
|
|
TESTFLAGS ?= -v $(TESTFLAGS_RACE)
|
|
|
|
TESTFLAGS_PARALLEL ?= 8
|
2016-03-21 19:08:47 +00:00
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
.PHONY: all build binaries check clean test test-race test-full integration coverage
|
|
|
|
.DEFAULT: all
|
2015-02-16 22:25:17 +00:00
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
all: binaries
|
2015-02-07 01:49:50 +00:00
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
# This only needs to be generated by hand when cutting full releases.
|
|
|
|
version/version.go:
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
./version/version.sh > $@
|
2015-02-06 23:39:11 +00:00
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
check: ## run all linters (TODO: enable "unused", "varcheck", "ineffassign", "unconvert", "staticheck", "goimports", "structcheck")
|
|
|
|
@echo "$(WHALE) $@"
|
2019-10-09 12:02:21 +00:00
|
|
|
golangci-lint run
|
2018-08-01 22:37:21 +00:00
|
|
|
|
|
|
|
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-06 23:39:11 +00:00
|
|
|
|
|
|
|
build:
|
2018-08-01 22:37:21 +00:00
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go build ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${GO_LDFLAGS} ${GO_TAGS} $(PACKAGES)
|
|
|
|
|
|
|
|
clean: ## clean up binaries
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@rm -f $(BINARIES)
|