VOL-1574

Install binary release of protoc
Clarify version requirements and use upstream installation instructions for protoc-gen-go

Change-Id: I6120b4b2896bc152cb3e552dc44f46e6e80905dd
diff --git a/Makefile b/Makefile
index 45690aa..5b6461f 100644
--- a/Makefile
+++ b/Makefile
@@ -32,16 +32,8 @@
 PROTO_GO_DEST_DIR := go
 PROTO_GO_PB:= $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_GO_DEST_DIR)/$(call go_package_path,$(f))/%.pb.go,$(f)))
 
-PROTOC_PREFIX := /usr/local
-PROTOC_VERSION := "3.7.0"
-PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download"
-PROTOC_DIR := protobuf-$(PROTOC_VERSION)
-PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz
-PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL)
-PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')"
-
-# Force pb file to be regenrated every time.  Otherwise the make process assumes whats there is still ok
-.PHONY: go/voltha.pb
+# Force pb file to be regenrated every time.  Otherwise the make process assumes generated version is still valid
+.PHONY: go/voltha.pb protoc_check
 
 print:
 	@echo "Proto files: $(PROTO_FILES)"
@@ -58,7 +50,7 @@
 clean: python-clean go-clean
 
 # Python targets
-python-protos: $(PROTO_PYTHON_PB2)
+python-protos: protoc_check $(PROTO_PYTHON_PB2)
 
 venv_protos:
 	virtualenv $@;\
@@ -100,17 +92,7 @@
     $(PROTO_PYTHON_PB2_GRPC)
 
 # Go targets
-go-protos: protoc_check_version $(PROTO_GO_PB) go/voltha.pb
-
-protoc_check_version:
-ifeq ("", "$(shell which protoc)")
-	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-	@echo "It looks like you don't have a version of protocol buffer tools."
-	@echo "To install the protocol buffer toolchain, you can run:"
-	@echo "    make install-protoc"
-	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-	exit 1
-endif
+go-protos: protoc_check $(PROTO_GO_PB) go/voltha.pb
 
 go_temp:
 	mkdir -p go_temp
@@ -130,32 +112,50 @@
     --descriptor_set_out=$@ \
     ${PROTO_FILES}
 
-go-test:
-ifneq ("libprotoc 3.7.0", "$(shell protoc --version)")
-	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-	@echo "It looks like you don't have protocol buffer tools ${PROTOC_VERSION} installed."
-	@echo "To install this version, you can run:"
-	@echo "    make install-protoc"
-	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-	exit 1
-endif
+go-test: protoc_check
 	test/test-go-proto-consistency.sh
 
 go-clean:
 	rm -rf go_temp
 
+# Protobuf compiler helper functions
+protoc_check:
+ifeq ("", "$(shell which protoc)")
+	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+	@echo "It looks like you don't have a version of protocol buffer tools."
+	@echo "To install the protocol buffer toolchain on Linux, you can run:"
+	@echo "    make install-protoc"
+	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+	exit 1
+endif
+ifneq ("libprotoc 3.7.0", "$(shell protoc --version)")
+	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+	@echo "You have the wrong version of protoc installed"
+	@echo "Please install version 3.7.0"
+	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+	exit 1
+endif
+
 install-protoc:
-	@echo "Downloading and installing protocol buffer support."
+	@echo "Downloading and installing protocol buffer support (Linux amd64 only)"
+ifneq ("Linux", "$(shell uname -s)")
+	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+	@echo "Automated installation of protoc not supported on $(shell uname -s)"
+	@echo "Please install protoc v3.7.0 from:"
+	@echo "  https://github.com/protocolbuffers/protobuf/releases"
+	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+	exit 1
+endif
 	@echo "Installation will require sudo priviledges"
 	@echo "This will take a few minutes."
-	mkdir -p $(PROTOC_BUILD_TMP_DIR)
-	@echo "We ask for sudo credentials now so we can install at the end"; \
+	@echo "Asking for sudo credentials now so we can install at the end"
 	sudo echo "Thanks"; \
-    cd $(PROTOC_BUILD_TMP_DIR); \
-    wget $(PROTOC_DOWNLOAD_URI); \
-    tar xzvf $(PROTOC_TARBALL); \
-    cd $(PROTOC_DIR); \
-    ./configure --prefix=$(PROTOC_PREFIX); \
-    make; \
-    sudo make install; \
-    sudo ldconfig
+    PROTOC_VERSION="3.7.0" ;\
+    PROTOC_SHA256SUM="a1b8ed22d6dc53c5b8680a6f1760a305b33ef471bece482e92728f00ba2a2969" ;\
+    curl -L -o /tmp/protoc-$${PROTOC_VERSION}-linux-x86_64.zip https://github.com/google/protobuf/releases/download/v$${PROTOC_VERSION}/protoc-$${PROTOC_VERSION}-linux-x86_64.zip ;\
+    echo "$${PROTOC_SHA256SUM}  /tmp/protoc-$${PROTOC_VERSION}-linux-x86_64.zip" | sha256sum -c - ;\
+    unzip /tmp/protoc-$${PROTOC_VERSION}-linux-x86_64.zip -d /tmp/protoc3 ;\
+    sudo mv /tmp/protoc3/bin/* /usr/local/bin/ ;\
+    sudo mv /tmp/protoc3/include/* /usr/local/include/ ;\
+    sudo chmod -R a+rx /usr/local/bin/* ;\
+    sudo chmod -R a+rX /usr/local/include/
diff --git a/README.md b/README.md
index 6bcf0f0..352398e 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,9 @@
 Currently this is used to generate both Golang and Python protobufs and gRPC
 stubs.
 
+The testing process is dependent on specific versions of the protobuf tools, so
+make sure to use the versions of `protoc` and `protoc-gen-go` specified below.
+
 Protobuf definition files are located in `protos/voltha_protos` directory. This
 directory hierarchy and import scheme is required to allow the python code
 generated by the gRPC compiler to [have the correct import
@@ -48,17 +51,16 @@
 Checkout and go install correct version of protoc-gen-go:
 
 ```sh
-cd $GOPATH/src/github.com/opencord/voltha-protos
-go get -d github.com/golang/protobuf/
-cd $GOPATH/src/github.com/golang/protobuf
-git checkout v1.3.1
-make install
+GIT_TAG="v1.3.1"
+go get -d -u github.com/golang/protobuf/protoc-gen-go
+git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
+go install github.com/golang/protobuf/protoc-gen-go
 ```
 
 ## Building locally
 
-Install libprotoc 3.7.0 manually or use the Makefile target install it.  Then
-build the python and golang stubs:
+Install the protobuf compiler (protoc) 3.7.0 either manually or via the
+Makefile target (if on Linux amd64).  Then build the python and golang stubs:
 
 ```sh
 cd $GOPATH/src/github.com/opencord/voltha-protos