From 1a9b163561d89a45845bc2ca9b1cd4f1a5e8700c Mon Sep 17 00:00:00 2001 From: Stanislav Bogatyrev Date: Fri, 18 Sep 2020 11:25:11 +0300 Subject: [PATCH] Simplify Makefile Signed-off-by: Stanislav Bogatyrev --- .gitattributes | 3 +- .gitignore | 1 + Makefile | 79 ++++++++++++++++++++++---------------------------- 3 files changed, 37 insertions(+), 46 deletions(-) diff --git a/.gitattributes b/.gitattributes index b002a5dd..c7a3f7a8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -/**/*.pb.go -diff binary +/**/*.pb.go -diff -merge +/**/*.pb.go linguist-generated=true diff --git a/.gitignore b/.gitignore index 22e0c656..354a562c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea bin temp /vendor/ diff --git a/Makefile b/Makefile index f4a54c4c..cd9e5356 100644 --- a/Makefile +++ b/Makefile @@ -1,61 +1,50 @@ -PROTO_VERSION=v1.2.0 -PROTO_URL=https://github.com/nspcc-dev/neofs-api/archive/$(PROTO_VERSION).tar.gz +#!/usr/bin/make -f +SHELL = bash -B=\033[0;1m -G=\033[0;92m -R=\033[0m +.PHONY: dep fmts fmt imports protoc -.PHONY: deps format docgen protoc +# Pull go dependencies +dep: + @printf "⇒ Tidy requirements : " + CGO_ENABLED=0 \ + GO111MODULE=on \ + go mod tidy -v && echo OK + @printf "⇒ Download requirements: " + CGO_ENABLED=0 \ + GO111MODULE=on \ + go mod download && echo OK + @printf "⇒ Install test requirements: " + CGO_ENABLED=0 \ + GO111MODULE=on \ + go test -i ./... && echo OK -# Dependencies -deps: - @echo "${B}${G}⇒ Golang modules ${R}" - @go mod tidy -v - @go mod vendor - - @echo "${B}${G}⇒ Cleanup old files ${R}" - @find . -type f -name '*.proto' -not -path './vendor/*' -not -name '*_test.proto' -exec rm {} \; - - @echo "${B}${G}⇒ NeoFS Proto files ${R}" - @mkdir -p ./vendor/proto - @curl -sL -o ./vendor/proto.tar.gz $(PROTO_URL) - @tar -xzf ./vendor/proto.tar.gz --strip-components 1 -C ./vendor/proto - @for f in `find ./vendor/proto -type f -name '*.proto' -exec dirname {} \; | sort -u `; do \ - cp $$f/*.proto ./$$(basename $$f); \ - done - - @echo "${B}${G}⇒ Cleanup ${R}" - @rm -rf ./vendor/proto - @rm -rf ./vendor/proto.tar.gz +# Run all code formaters +fmts: fmt imports # Reformat code -format: - @[ ! -z `which goimports` ] || (echo "install goimports" && exit 2) +fmt: + @echo "⇒ Processing gofmt check" @for f in `find . -type f -name '*.go' -not -path './vendor/*' -not -name '*.pb.go' -prune`; do \ - echo "${B}${G}⇒ Processing $$f ${R}"; \ - goimports -w $$f; \ + GO111MODULE=on gofmt -s -w $$f; \ done -# Regenerate documentation for protot files: -docgen: deps - @for f in `find . -type f -name '*.proto' -not -path './vendor/*' -exec dirname {} \; | sort -u `; do \ - echo "${B}${G}⇒ Documentation for $$(basename $$f) ${R}"; \ - protoc \ - --doc_opt=.github/markdown.tmpl,$${f}.md \ - --proto_path=.:./vendor:/usr/local/include \ - --doc_out=docs/ $${f}/*.proto; \ +# Reformat imports +imports: + @echo "⇒ Processing goimports check" + @for f in `find . -type f -name '*.go' -not -path './vendor/*' -not -name '*.pb.go' -prune`; do \ + GO111MODULE=on goimports -w $$f; \ done # Regenerate proto files: protoc: - @echo "${B}${G}⇒ Cleanup old files ${R}" - @find . -type f -name '*.pb.go' -not -path './vendor/*' -exec rm {} \; - @echo "${B}${G}⇒ Protoc generate ${R}" + @GOPRIVATE=github.com/nspcc-dev go mod vendor + # Install specific version for protobuf lib + @go list -f '{{.Path}}/...@{{.Version}}' -m github.com/golang/protobuf | xargs go get -v + # Protoc generate @for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \ - echo "${B}${G}⇒ Processing $$f ${R}"; \ + echo "⇒ Processing $$f "; \ protoc \ - --proto_path=.:./vendor:/usr/local/include \ + --proto_path=.:./vendor:./vendor/github.com/nspcc-dev/neofs-api:/usr/local/include \ --gofast_out=plugins=grpc,paths=source_relative:. $$f; \ done - -update: docgen protoc + rm -rf vendor