github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/direct.mk (about) 1 # Base path used to install. 2 DESTDIR=/usr/local 3 4 # Used to populate version variable in main package. 5 VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always) 6 7 # Race detector is only supported on amd64. 8 RACE := $(shell test $$(go env GOARCH) != "amd64" || (echo "-race")) 9 10 # Project packages. 11 PACKAGES=$(shell go list ./... | grep -v /vendor/) 12 INTEGRATION_PACKAGE=${PROJECT_ROOT}/integration 13 14 # Project binaries. 15 COMMANDS=swarmd swarmctl swarm-bench swarm-rafttool protoc-gen-gogoswarm 16 BINARIES=$(addprefix bin/,$(COMMANDS)) 17 18 VNDR=$(shell which vndr || echo '') 19 20 GO_LDFLAGS=-ldflags "-X `go list ./version`.Version=$(VERSION)" 21 22 23 .DEFAULT_GOAL = all 24 .PHONY: all 25 all: check binaries test integration-tests ## run check, build the binaries and run the tests 26 27 .PHONY: ci 28 ci: check binaries checkprotos coverage coverage-integration ## to be used by the CI 29 30 .PHONY: AUTHORS 31 AUTHORS: .mailmap .git/HEAD 32 git log --format='%aN <%aE>' | sort -fu > $@ 33 34 # This only needs to be generated by hand when cutting full releases. 35 version/version.go: 36 ./version/version.sh > $@ 37 38 .PHONY: setup 39 setup: ## install dependencies 40 @echo "🐳 $@" 41 # TODO(stevvooe): Install these from the vendor directory 42 # install golangci-lint version 1.17.1 to ./bin/golangci-lint 43 @curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.17.1 44 @go get -u github.com/lk4d4/vndr 45 # use GO111MODULE=on to get protobuild with the appropriate versions of its 46 # dependencies 47 @GO111MODULE=on go get github.com/stevvooe/protobuild 48 49 .PHONY: generate 50 generate: protos 51 @echo "🐳 $@" 52 @PATH=${ROOTDIR}/bin:${PATH} go generate -x ${PACKAGES} 53 54 .PHONY: protos 55 protos: bin/protoc-gen-gogoswarm ## generate protobuf 56 @echo "🐳 $@" 57 @PATH=${ROOTDIR}/bin:${PATH} protobuild ${PACKAGES} 58 59 .PHONY: checkprotos 60 checkprotos: generate ## check if protobufs needs to be generated again 61 @echo "🐳 $@" 62 @test -z "$$(git status --short | grep ".pb.go" | tee /dev/stderr)" || \ 63 ((git diff | cat) && \ 64 (echo "👹 please run 'make generate' when making changes to proto files" && false)) 65 66 .PHONY: check 67 check: fmt-proto 68 check: ## Run various source code validation tools 69 @echo "🐳 $@" 70 @./bin/golangci-lint run 71 72 .PHONY: fmt-proto 73 fmt-proto: 74 @test -z "$$(find . -path ./vendor -prune -o ! -name timestamp.proto ! -name duration.proto -name '*.proto' -type f -exec grep -Hn -e "^ " {} \; | tee /dev/stderr)" || \ 75 (echo "👹 please indent proto files with tabs only" && false) 76 @test -z "$$(find . -path ./vendor -prune -o -name '*.proto' -type f -exec grep -Hn "Meta meta = " {} \; | grep -v '(gogoproto.nullable) = false' | tee /dev/stderr)" || \ 77 (echo "👹 meta fields in proto files must have option (gogoproto.nullable) = false" && false) 78 79 .PHONY: build 80 build: ## build the go packages 81 @echo "🐳 $@" 82 @go build -tags "${DOCKER_BUILDTAGS}" -v ${GO_LDFLAGS} ${GO_GCFLAGS} ${PACKAGES} 83 84 .PHONY: test 85 test: ## run tests, except integration tests 86 @echo "🐳 $@" 87 @go test -parallel 8 ${RACE} -tags "${DOCKER_BUILDTAGS}" $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}) 88 89 .PHONY: integration-tests 90 integration-tests: ## run integration tests 91 @echo "🐳 $@" 92 @go test -parallel 8 ${RACE} -tags "${DOCKER_BUILDTAGS}" ${INTEGRATION_PACKAGE} 93 94 # Build a binary from a cmd. 95 bin/%: cmd/% .FORCE 96 @test $$(go list) = "${PROJECT_ROOT}" || \ 97 (echo "👹 Please correctly set up your Go build environment. This project must be located at <GOPATH>/src/${PROJECT_ROOT}" && false) 98 @echo "🐳 $@" 99 @go build -tags "${DOCKER_BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./$< 100 101 .PHONY: .FORCE 102 .FORCE: 103 104 .PHONY: binaries 105 binaries: $(BINARIES) ## build binaries 106 @echo "🐳 $@" 107 108 .PHONY: clean 109 clean: ## clean up binaries 110 @echo "🐳 $@" 111 @rm -f $(BINARIES) 112 113 .PHONY: install 114 install: $(BINARIES) ## install binaries 115 @echo "🐳 $@" 116 @mkdir -p $(DESTDIR)/bin 117 @install $(BINARIES) $(DESTDIR)/bin 118 119 .PHONY: uninstall 120 uninstall: 121 @echo "🐳 $@" 122 @rm -f $(addprefix $(DESTDIR)/bin/,$(notdir $(BINARIES))) 123 124 .PHONY: coverage 125 coverage: ## generate coverprofiles from the unit tests 126 @echo "🐳 $@" 127 @( for pkg in $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}); do \ 128 go test ${RACE} -tags "${DOCKER_BUILDTAGS}" -test.short -coverprofile="../../../$$pkg/coverage.txt" -covermode=atomic $$pkg || exit; \ 129 go test ${RACE} -tags "${DOCKER_BUILDTAGS}" -test.short -coverprofile="../../../$$pkg/coverage.txt" -covermode=atomic $$pkg || exit; \ 130 done ) 131 132 .PHONY: coverage-integration 133 coverage-integration: ## generate coverprofiles from the integration tests 134 @echo "🐳 $@" 135 go test ${RACE} -tags "${DOCKER_BUILDTAGS}" -test.short -coverprofile="../../../${INTEGRATION_PACKAGE}/coverage.txt" -covermode=atomic ${INTEGRATION_PACKAGE} 136 137 .PHONY: help 138 help: ## this help 139 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort 140 141 .PHONY: dep-validate 142 dep-validate: 143 @echo "+ $@" 144 $(if $(VNDR), , \ 145 $(error Please install vndr: go get github.com/lk4d4/vndr)) 146 @rm -Rf .vendor.bak 147 @mv vendor .vendor.bak 148 @$(VNDR) 149 @test -z "$$(diff -r vendor .vendor.bak 2>&1 | tee /dev/stderr)" || \ 150 (echo >&2 "+ inconsistent dependencies! what you have in vendor.conf does not match with what you have in vendor" && false) 151 @rm -Rf vendor 152 @mv .vendor.bak vendor