1#!/usr/bin/env bash 2# Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================== 16 17set -e 18 19go get -d google.golang.org/protobuf/proto 20go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 21 22if [ -z "${GOPATH}" ] 23then 24 GOPATH=$(go env GOPATH) 25fi 26 27if [ -z "${GOOS}" ] 28then 29 GOOS=$(go env GOOS) 30fi 31 32# convert GOPATH's Windows style to UNIX style 33if [[ $GOOS == "windows" ]]; then 34 # eg: convert "D:\go-14;D:\go-13" to "D\go-14;D\go-13" 35 GOPATH=${GOPATH//:\\/\\} 36 # eg: convert "D\go-14;D\go-13" to "\D\go-14:\D\go-13" 37 GOPATH=\\${GOPATH//;/:\\} 38 # eg: convert "\D\go-14:\D\go-13" to "/D/go-14:/D/go-13" 39 GOPATH=${GOPATH//\\/\/} 40fi 41 42cd $(dirname $0) 43for g in $(echo "${GOPATH//:/ }"); do 44 TF_DIR="${g}/src/github.com/tensorflow/tensorflow" 45 PROTOC="${TF_DIR}/bazel-out/host/bin/external/protobuf/protoc" 46 if [ -x "${PROTOC}" ]; then 47 break 48 fi 49done 50 51if [ ! -x "${PROTOC}" ] 52then 53 set +e 54 PATH_PROTOC=$(which protoc) 55 if [ ! -x "${PATH_PROTOC}" ] 56 then 57 echo "Protocol buffer compiler protoc not found in PATH or in ${PROTOC}" 58 echo "Perhaps build it using:" 59 echo "bazel build --config opt @com_google_protobuf//:protoc" 60 exit 1 61 fi 62 PROTOC=$PATH_PROTOC 63 set -e 64fi 65 66# Ensure that protoc-gen-go is available in $PATH 67# Since ${PROTOC} will require it. 68export PATH=$PATH:${GOPATH}/bin 69for FILE in ${TF_DIR}/tensorflow/core/framework/*.proto \ 70 ${TF_DIR}/tensorflow/core/protobuf/*.proto \ 71 ${TF_DIR}/tensorflow/compiler/xla/pjrt/distributed/*.proto \ 72 ${TF_DIR}/tensorflow/stream_executor/*.proto; do 73 ${PROTOC} \ 74 -I ${TF_DIR} \ 75 --go_out=${GOPATH}/src \ 76 $FILE 77done 78