Skip to content

Commit

Permalink
Makefiles: various improvements (cosmos#6101)
Browse files Browse the repository at this point in the history
Don't reinstall proto tools unconditionally every time
one runs make.

On most Linux systems, /usr/local is writable by root only.
Allow users to customise installation directory by passing
PREFIX to make command line, e.g.:

 $ make PREFIX=~/.local
  • Loading branch information
Alessio Treglia committed Apr 30, 2020
1 parent 930802e commit a8a455a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ docs/tutorial
docs/node_modules
dist
tools-stamp
proto-tools-stamp

# Data - ideally these don't exist
baseapp/data/*
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ devdoc-update:
### Protobuf ###
###############################################################################

proto-all: proto-gen proto-lint proto-check-breaking
proto-all: proto-tools proto-gen proto-lint proto-check-breaking

proto-gen:
@./scripts/protocgen.sh
Expand Down
54 changes: 26 additions & 28 deletions contrib/devtools/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.PHONY: all tools tools-clean statik runsim \
protoc buf protoc-gen-buf-check-breaking protoc-gen-buf-check-lint protoc-gen-gocosmos

###
# Find OS and Go environment
# GO contains the Go binary
Expand All @@ -18,8 +15,6 @@ ifeq ($(GO),)
$(error could not find go. Is it in PATH? $(GO))
endif

all: tools

###############################################################################
### Functions ###
###############################################################################
Expand All @@ -41,20 +36,26 @@ mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)
### Tools ###
###############################################################################

BIN ?= /usr/local/bin
PREFIX ?= /usr/local
BIN ?= $(PREFIX)/bin
UNAME_S ?= $(shell uname -s)
UNAME_M ?= $(shell uname -m)

GOPATH ?= $(shell $(GO) env GOPATH)
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com

BUF_VERSION ?= 0.7.0
BUF_VERSION ?= 0.11.0

TOOLS_DESTDIR ?= $(GOPATH)/bin
STATIK = $(TOOLS_DESTDIR)/statik
RUNSIM = $(TOOLS_DESTDIR)/runsim

tools: protoc buf statik runsim
tools: tools-stamp
tools-stamp: proto-tools statik runsim
# Create dummy file to satisfy dependency and avoid
# rebuilding when this Makefile target is hit twice
# in a row.
touch $@

# Install the runsim binary with a temporary workaround of entering an outside
# directory as the "go get" command ignores the -mod option and will polute the
Expand Down Expand Up @@ -84,39 +85,36 @@ ifeq ($(UNAME_S),Darwin)
PROTOC_ZIP ?= protoc-3.11.2-osx-x86_64.zip
endif

protoc:
proto-tools: proto-tools-stamp
proto-tools-stamp:
@echo "Installing protoc compiler..."
@(cd /tmp; \
curl -OL "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}"; \
unzip -o ${PROTOC_ZIP} -d /usr/local bin/protoc; \
unzip -o ${PROTOC_ZIP} -d /usr/local 'include/*'; \
unzip -o ${PROTOC_ZIP} -d $(PREFIX) bin/protoc; \
unzip -o ${PROTOC_ZIP} -d $(PREFIX) 'include/*'; \
rm -f ${PROTOC_ZIP})

protoc-gen-gocosmos:
@echo "Installing protoc-gen-gocosmos..."
@go install github.com/regen-network/cosmos-proto/protoc-gen-gocosmos
@echo "Installing protoc-gen-buf-check-breaking..."
@curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/protoc-gen-buf-check-breaking-${UNAME_S}-${UNAME_M}" \
-o "${BIN}/protoc-gen-buf-check-breaking" && \
chmod +x "${BIN}/protoc-gen-buf-check-breaking"

buf: protoc-gen-buf-check-breaking protoc-gen-buf-check-lint
@echo "Installing buf..."
@curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-${UNAME_S}-${UNAME_M}" \
-o "${BIN}/buf" && \
chmod +x "${BIN}/buf"

protoc-gen-buf-check-breaking:
@echo "Installing protoc-gen-buf-check-breaking..."
@curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/protoc-gen-buf-check-breaking-${UNAME_S}-${UNAME_M}" \
-o "${BIN}/protoc-gen-buf-check-breaking" && \
chmod +x "${BIN}/protoc-gen-buf-check-breaking"
touch $@

protoc-gen-buf-check-lint:
@echo "Installing protoc-gen-buf-check-lint..."
@curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/protoc-gen-buf-check-lint-${UNAME_S}-${UNAME_M}" \
-o "${BIN}/protoc-gen-buf-check-lint" && \
chmod +x "${BIN}/protoc-gen-buf-check-lint"
protoc-gen-gocosmos:
@echo "Installing protoc-gen-gocosmos..."
@go install github.com/regen-network/cosmos-proto/protoc-gen-gocosmos

tools-clean:
rm -f $(STATIK) $(GOLANGCI_LINT) $(RUNSIM)
rm -f tools-stamp
rm -f tools-stamp proto-tools-stamp

.PHONY: tools-clean statik runsim \
protoc-gen-gocosmos

0 comments on commit a8a455a

Please sign in to comment.