Skip to content

Commit

Permalink
Merge pull request #4 from simelo/olemis_t1_protob_init
Browse files Browse the repository at this point in the history
[ci] fixes #1 - Generate protobuffer classes for js, C , and Python
  • Loading branch information
olemis authored Mar 3, 2019
2 parents 6dc81e2 + 706c39e commit 3de9639
Show file tree
Hide file tree
Showing 9 changed files with 5,076 additions and 27 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ install:
fi
script:
- make build-go
# - make build-nanopb
# - make build-py
# - make build-js
- make build-c
- make build-py
- make build-js
- make clean
- git checkout -- js/package-lock.json && git status
- test -z "$(git status --porcelain)"
notifications:
# https://github.com/kvld/travisci-telegram TravisCI Telegram Bot integration
webhooks: https://fathomless-fjord-24024.herokuapp.com/notify
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- Generate protobuffer classes for go lang with `gogofast` plugin for `protoc`
- Generate protobuffer classes for Javascript with `pbjs`
- Generate protobuffer classes for C and Python with `nanopb` and Python plugin for `protoc`

### Fixed

Expand Down
68 changes: 47 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.DEFAULT_GOAL := help
.PHONY: help all
.PHONY: build-go build-js build-nanopb build-py
.PHONY: help all clean
.PHONY: build-go build-js build-c build-py
.PHONY: install-deps-go install-deps-js install-deps-nanopb install-protoc
.PHONY: clean-go clean-js clean-c clean-py

REPO_ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

Expand All @@ -19,19 +20,20 @@ else
endif
endif

PROTOC_VERSION ?= 3.6.1
PROTOC_ZIP ?= protoc-$(PROTOC_VERSION)-$(OS_NAME)-x86_64.zip
PROTOC_URL ?= https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/$(PROTOC_ZIP)
PROTOC_GOGO_URL = github.com/gogo/protobuf
PROTOC_NANOPBGEN_DIR = nanopb/vendor/nanopb/generator

PROTOB_SPEC_DIR = protob
PROTOB_MSG_DIR = $(PROTOB_SPEC_DIR)/messages

PROTOB_GO_DIR = go
PROTOB_JS_DIR = js
PROTOB_PY_DIR = nanopb/py
PROTOB_C_DIR = nanopb/c
PROTOB_REPO_URL = github.com/gogo/protobuf
PROTOB_SRC_DIR = $(GOPATH)/src/$(PROTOB_REPO_URL)

PROTOC_VERSION ?= 3.6.1
PROTOC_ZIP ?= protoc-$(PROTOC_VERSION)-$(OS_NAME)-x86_64.zip
PROTOC_URL ?= https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/$(PROTOC_ZIP)
PROTOB_PY_DIR = py
PROTOB_C_DIR = c
PROTOB_SRC_DIR = $(GOPATH)/src/$(PROTOC_GOGO_URL)

PROTOB_MSG_FILES = $(shell ls -1 $(PROTOB_MSG_DIR)/*.proto)
PROTOB_MSG_SPECS = $(patsubst %,$(PROTOB_MSG_DIR)/%,$(notdir $(PROTOB_MSG_FILES)))
Expand All @@ -40,7 +42,9 @@ PROTOB_MSG_JS = $(patsubst %,$(PROTOB_JS_DIR)/%,$(notdir $(PROTOB_MSG_FILES:.
PROTOB_MSG_PY = $(patsubst %,$(PROTOB_PY_DIR)/%,$(notdir $(PROTOB_MSG_FILES:.proto=_pb2.py)))
PROTOB_MSG_C = $(patsubst %,$(PROTOB_C_DIR)/%,$(notdir $(PROTOB_MSG_FILES:.proto=.pb.c)))

all: build-go build-js build-nanopb ## Generate protobuf classes for all languages
all: build-go build-js build-c build-py ## Generate protobuf classes for all languages

clean: clean-go clean-js clean-c clean-py ## Delete temporary and output files

install-protoc: /usr/local/bin/protoc

Expand All @@ -57,11 +61,11 @@ install-protoc: /usr/local/bin/protoc

install-deps-go: install-protoc ## Install tools to generate protobuf classes for go lang
@if [ -e $(PROTOB_SRC_DIR) ] ; then \
echo 'Detected $(PROTOB_REPO_URL) on local file system. Checking v1.2.0' ; \
echo 'Detected $(PROTOC_GOGO_URL) on local file system. Checking v1.2.0' ; \
cd $(PROTOB_SRC_DIR) && git checkout v1.2.0 ; \
else \
echo 'Cloning $(PROTOB_REPO_URL)' ; \
git clone --branch v1.2.0 --depth 1 https://$(PROTOB_REPO_URL) $(PROTOB_SRC_DIR) ; \
echo 'Cloning $(PROTOC_GOGO_URL)' ; \
git clone --branch v1.2.0 --depth 1 https://$(PROTOC_GOGO_URL) $(PROTOB_SRC_DIR) ; \
fi
( cd $(PROTOB_SRC_DIR)/protoc-gen-gogofast && go install )

Expand All @@ -70,6 +74,9 @@ build-go: install-deps-go $(PROTOB_MSG_GO) ## Generate protobuf classes for go l
$(PROTOB_GO_DIR)/%.pb.go: $(PROTOB_MSG_DIR)/%.proto
protoc -I protob/messages --gogofast_out=$(PROTOB_GO_DIR) $<

clean-go:
rm $(PROTOB_GO_DIR)/*.pb.go

#----------------
# Javascript
#----------------
Expand All @@ -80,23 +87,35 @@ install-deps-js: ## Install tools to generate protobuf classes for javascript
build-js: install-deps-js ## Generate protobuf classes for javascript
cd $(REPO_ROOT)/js && npm run gen-proto

clean-js:
rm -rf $(PROTOB_JS_DIR)/skycoin.js $(PROTOB_JS_DIR)/node_modules

#----------------
# C with nanopb
#----------------

install-deps-nanopb: ## Install tools to generate protobuf classes for C with nanopb
make -C vendor/nanopb/generator/proto/
make -C $(PROTOC_NANOPBGEN_DIR)/proto/

build-nanopb: install-deps-nanopb $(PROTOB_MSG_C) $(PROTOB_C_DIR)/messages_map.h ## Generate protobuf classes for C with nanopb
build-c: install-deps-nanopb $(PROTOB_MSG_C) $(PROTOB_C_DIR)/messages_map.h ## Generate protobuf classes for C with nanopb

$(PROTOB_C_DIR)/%.pb.c: $(PROTOB_C_DIR)/%.pb $(PROTOB_MSG_DIR)/%.options
$(PYTHON) vendor/nanopb/generator/nanopb_generator.py $< -L '#include "%s"' -T
#c/%.pb.c: c/%.pb $(PROTOB_MSG_DIR)/%.options
$(PYTHON) $(PROTOC_NANOPBGEN_DIR)/nanopb_generator.py $< -L '#include "%s"' -T

$(PROTOB_C_DIR)/%.pb: $(PROTOB_MSG_DIR)/%.proto
protoc -I./vendor/nanopb/generator/proto/ -I. -I./$(PROTOB_MSG_DIR) $< -o $(PROTOB_C_DIR)
protoc -I./$(PROTOC_NANOPBGEN_DIR)/proto/ -I. -I./$(PROTOB_MSG_DIR) $< -o $@

$(PROTOB_C_DIR)/messages_map.h: $(PROTOB_PY_DIR)/messages_map.py $(PROTOB_PY_DIR)/messages_pb2.py $(PROTOB_PY_DIR)/types_pb2.py $(PROTOB_PY_DIR)/descriptor_pb2.py
PYTHONPATH="$$PYTHONPATH:$(REPO_ROOT)/$(PROTOB_PY_DIR)" $(PYTHON) $< > $@

$(PROTOB_C_DIR)/messages_map.h: $(PROTOB_PY_DIR)/messages_map.py $(PROTOB_PY_DIR)/messages_pb2.py $(PROTOB_PY_DIR)/types_pb2.py
$(PYTHON) $< > $@
clean-c:
rm -rf $(PROTOB_C_DIR)/messages_map.h \
$$( find $(PROTOB_C_DIR) -name '*.pb.c' ) \
$$( find $(PROTOB_C_DIR) -name '*.pb.h' ) \
$$( find $(PROTOB_C_DIR) -name '*.i' ) \
$$( find $(PROTOB_C_DIR) -name '*.s' ) \
$$( find $(PROTOB_C_DIR) -name '*.o' )

#----------------
# Python with nanopb
Expand All @@ -105,7 +124,14 @@ $(PROTOB_C_DIR)/messages_map.h: $(PROTOB_PY_DIR)/messages_map.py $(PROTOB_PY_DIR
build-py: install-deps-nanopb $(PROTOB_MSG_PY) ## Generate protobuf classes for Python with nanopb

$(PROTOB_PY_DIR)/%_pb2.py: $(PROTOB_MSG_DIR)/%.proto
protoc -I../vendor/nanopb/generator/proto/ -I. -I./$(PROTOB_MSG_DIR) $< --python_out=$(PROTOB_PY_DIR)
protoc -I./$(PROTOB_MSG_DIR) $< --python_out=$(PROTOB_PY_DIR)

clean-py:
rm -rf $(PROTOB_PY_DIR)/__pycache__/ py/*_pb2.py \
$$( find $(PROTOB_PY_DIR) -name '*_pb2.py' ) \
$$( find $(PROTOB_PY_DIR) -name '*.pyc' ) \
$$( find $(PROTOB_PY_DIR) -name '*.pyd' ) \
$$( find $(PROTOB_PY_DIR) -name '*.pyo' )

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
1 change: 1 addition & 0 deletions ci-scripts/install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ curl -LO "https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSI
mkdir protoc
yes | unzip "protoc-${PROTOBUF_VERSION}-linux-x86_64.zip" -d $HOME
find $HOME/bin -name protoc
rm -f "protoc-${PROTOBUF_VERSION}-linux-x86_64.zip"

# Install gimme
curl -sL -o "$HOME/bin/gimme" https://raw.githubusercontent.com/travis-ci/gimme/master/gimme
Expand Down
Loading

0 comments on commit 3de9639

Please sign in to comment.