Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve buf handling #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
SHELL := /bin/sh
BIN := /usr/local/bin
OS:=$(shell uname -s)

# set BIN path, used to check buf version
ifeq ($(OS),Linux)
BIN := /usr/local/bin
endif
ifeq ($(OS),Darwin) # Assume Mac OS X
BIN := /opt/homebrew/bin
endif

REV := $(shell git rev-parse HEAD)
CHANGES := $(shell test -n "$$(git status --porcelain)" && echo '+CHANGES' || true)
Expand Down Expand Up @@ -32,7 +40,6 @@ BUF_BINARY_NAME := buf

# count processors
NPROCS:=1
OS:=$(shell uname -s)
ifeq ($(OS),Linux)
NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
endif
Expand Down Expand Up @@ -79,14 +86,26 @@ BUF_INSTALLED_VERSION := $(shell if command -v $(BIN)/$(BUF_BINARY_NAME) >/dev/n
VERSION_MATCH := $(findstring ${BUF_INSTALLED_VERSION},$(BUF_VERSION))
## Install buf binary
buf:
ifeq ($(OS),Linux)
@echo "linux detected"
@if [ -x "$(BIN)/$(BUF_BINARY_NAME)" ] && [ -n "$(VERSION_MATCH)" ]; then \
echo "The required version of $(BUF_BINARY_NAME) is already installed: $(BUF_VERSION)"; \
else \
echo "Installing or updating $(BUF_BINARY_NAME)..."; \
curl -sSL "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/${BUF_BINARY_NAME}-$(shell uname -s)-$(shell uname -m)" -o "${BIN}/${BUF_BINARY_NAME}"; \
chmod +x $(BIN)/$(BUF_BINARY_NAME); \
sudo curl -sSL "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/${BUF_BINARY_NAME}-$(shell uname -s)-$(shell uname -m)" -o "${BIN}/${BUF_BINARY_NAME}"; \
sudo chmod +x $(BIN)/$(BUF_BINARY_NAME); \
fi
endif
ifeq ($(OS),Darwin) # Assume Mac OS X
@echo "MacOS detected"
@if [ -x "$(BIN)/$(BUF_BINARY_NAME)" ] && [ -n "$(VERSION_MATCH)" ]; then \
echo "The required version of $(BUF_BINARY_NAME) is already installed: $(BUF_VERSION)"; \
else \
echo "Installing or updating $(BUF_BINARY_NAME)..."; \
brew install buf; \
fi

endif

## Build and debug
debug: build
Expand Down
Loading