Skip to content

Commit

Permalink
Fixed make proto (thanos-io#747)
Browse files Browse the repository at this point in the history
* Fixed make proto

Signed-off-by: jojohappy <[email protected]>

* Address review comments

Signed-off-by: jojohappy <[email protected]>

* Change the download destination of protoc package

Signed-off-by: jojohappy <[email protected]>

* Rollback && simplify the code

Signed-off-by: jojohappy <[email protected]>

* Fixed temporary dir doesn't exist

Signed-off-by: jojohappy <[email protected]>

* To install protoc command only suuportting linux or macosx

Signed-off-by: jojohappy <[email protected]>

* Update docs

Signed-off-by: jojohappy <[email protected]>
  • Loading branch information
jojohappy authored and bwplotka committed Jan 24, 2019
1 parent 705d6a2 commit 71f4e25
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ The philosophy of Thanos and our community is borrowing much from UNIX philosoph

Adding large new features and components to Thanos should be done by first creating a [proposal](docs/proposals) document outlining the design decisions of the change, motivations for the change, and any alternatives that might have been considered.

## Prerequisites

* It is strongly recommended that you use OSX or popular Linux distributions systems e.g. Ubuntu, Redhat, or OpenSUSE for development.

## Pull Request Process

1. Read [getting started docs](docs/getting_started.md) and prepare Thanos.
2. Familarize yourself with [Makefile](Makefile) commands like `format`, `build`, `proto` and `test`.
2. Familiarize yourself with [Makefile](Makefile) commands like `format`, `build`, `proto` and `test`.
3. Fork improbable-eng/thanos.git and start development from your own fork. Here are sample steps to setup your development environment:
```console
$ mkdir -p $GOPATH/src/github.com/improbable-eng
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ GOIMPORTS_VERSION ?= 1c3d964395ce8f04f3b03b30aaed0b096c08c3c6
PROMU ?= $(BIN_DIR)/promu-$(PROMU_VERSION)
# v0.2.0
PROMU_VERSION ?= 264dc36af9ea3103255063497636bd5713e3e9c1
PROTOC ?= $(BIN_DIR)/protoc-$(PROTOC_VERSION)
PROTOC_VERSION ?= 3.4.0

# E2e test deps.
# Referenced by github.com/improbable-eng/thanos/blob/master/docs/getting_started.md#prometheus
Expand Down Expand Up @@ -129,9 +131,9 @@ format: $(GOIMPORTS)

# proto generates golang files from Thanos proto files.
.PHONY: proto
proto: deps
proto: deps $(GOIMPORTS) $(PROTOC)
@go install ./vendor/github.com/gogo/protobuf/protoc-gen-gogofast
@./scripts/genproto.sh
@GOIMPORTS_BIN="$(GOIMPORTS)" PROTOC_BIN="$(PROTOC)" scripts/genproto.sh

.PHONY: promu
promu: $(PROMU)
Expand Down Expand Up @@ -200,3 +202,11 @@ $(LICHE):

$(PROMU):
$(call fetch_go_bin_version,github.com/prometheus/promu,$(PROMU_VERSION))

$(PROTOC):
@mkdir -p $(TMP_GOPATH)
@echo ">> fetching protoc@${PROTOC_VERSION}"
@PROTOC_VERSION="$(PROTOC_VERSION)" TMP_GOPATH="$(TMP_GOPATH)" scripts/installprotoc.sh
@echo ">> installing protoc@${PROTOC_VERSION}"
@mv -- "$(TMP_GOPATH)/bin/protoc" "$(BIN_DIR)/protoc-$(PROTOC_VERSION)"
@echo ">> produced $(BIN_DIR)/protoc-$(PROTOC_VERSION)"
9 changes: 6 additions & 3 deletions scripts/genproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
set -e
set -u

PROTOC_BIN=${PROTOC_BIN:-protoc}
GOIMPORTS_BIN=${GOIMPORTS_BIN:-goimports}

if ! [[ "$0" =~ "scripts/genproto.sh" ]]; then
echo "must be run from repository root"
exit 255
fi

if ! [[ $(protoc --version) =~ "3.4.0" ]]; then
if ! [[ $(${PROTOC_BIN} --version) =~ "3.4.0" ]]; then
echo "could not find protoc 3.4.0, is it installed + in PATH?"
exit 255
fi
Expand All @@ -24,14 +27,14 @@ DIRS="pkg/store/storepb pkg/store/prompb"

for dir in ${DIRS}; do
pushd ${dir}
protoc --gogofast_out=plugins=grpc:. -I=. \
${PROTOC_BIN} --gogofast_out=plugins=grpc:. -I=. \
-I="${GOGOPROTO_PATH}" \
-I="${PROM_PATH}" \
*.proto

sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go
sed -i.bak -E 's/import _ \"google\/protobuf\"//g' *.pb.go
rm -f *.bak
goimports -w *.pb.go
${GOIMPORTS_BIN} -w *.pb.go
popd
done
59 changes: 59 additions & 0 deletions scripts/installprotoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
#
# Install the standard protocol buffer implementation - protoc.
set -e
set -u

PROTOC_VERSION=${PROTOC_VERSION:-3.4.0}
TMP_GOPATH=${TMP_GOPATH:-/tmp/thanos-go}
PROTOC_DOWNLOAD_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}"

OS=$(go env GOOS)
ARCH=$(go env GOARCH)
PLATFORM="${OS}/${ARCH}"

is_supported_platform() {
platform=$1
found=1
case "$platform" in
darwin/amd64) found=0 ;;
darwin/i386) found=0 ;;
linux/amd64) found=0 ;;
linux/i386) found=0 ;;
linux/arm64) found=0 ;;
esac
return $found
}

adjust_os() {
case ${OS} in
darwin) OS=osx ;;
esac
true
}

adjust_arch() {
case ${ARCH} in
amd64) ARCH=x86_64 ;;
i386) ARCH=x86_32 ;;
arm64) ARCH=aarch_64 ;;
esac
true
}

mkdir -p ${TMP_GOPATH}

is_supported_platform "$PLATFORM"
if [[ $? -eq 1 ]]; then
echo "platform $PLATFORM is not supported. See https://github.com/protocolbuffers/protobuf/releases for details"
exit 1
fi

adjust_os

adjust_arch

PACKAGE="protoc-${PROTOC_VERSION}-${OS}-${ARCH}.zip"
PACKAGE_DOWNLOAD_URL="${PROTOC_DOWNLOAD_URL}/${PACKAGE}"
curl -LSs ${PACKAGE_DOWNLOAD_URL} -o ${TMP_GOPATH}/${PACKAGE}
unzip -qqj ${TMP_GOPATH}/${PACKAGE} "bin/protoc" -d "${TMP_GOPATH}/bin/"

0 comments on commit 71f4e25

Please sign in to comment.