Skip to content

Commit

Permalink
Improve buf handling
Browse files Browse the repository at this point in the history
- use sudo on linux
- use homebrew path on macos
  • Loading branch information
issmirnov committed Apr 29, 2024
1 parent 1c438ff commit 2d3d5e8
Showing 1 changed file with 23 additions and 4 deletions.
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

0 comments on commit 2d3d5e8

Please sign in to comment.