Skip to content

Commit

Permalink
Verify protoc version for batch-generation (googleapis#3676)
Browse files Browse the repository at this point in the history
Fail fast when using utilities/batch_generate_apis.py if the local protoc version doesn't match the protobuf-java version defined in the pom.xml.
  • Loading branch information
andreamlin authored Sep 13, 2018
1 parent 1d7b95f commit ccf68f3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion utilities/batch_generate_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
# $ git clone https://github.com/googleapis/googleapis.git
# $ git clone https://github.com/googleapis/discovery-artifact-manager.git
#
# Run this script:
# Run this script from the top-level google-cloud-java directory:
#
# $ python utilities/batch_generate_apis.py PATH_TO_GOOGLEAPIS PATH_TO_DISCOVERY_ARTIFACT_MANAGER

import argparse
import os
import sys
from subprocess import check_output

import generate_api

Expand Down Expand Up @@ -93,7 +95,27 @@ def generate(artman_yaml):
generate('gapic/google/compute/artman_compute.yaml')


def verify_protoc_version():
protobuf_version_node = check_output(
['grep', '-zohr', '--include=pom.xml',
'<protobuf.version>.*</protobuf.version>'])
version_start_index = protobuf_version_node.find('>') + 1
version_end_index = protobuf_version_node.rfind('<')
protobuf_version = protobuf_version_node[version_start_index : version_end_index].strip()

# This will be something like 'libprotoc 3.6.0'
protoc_version_str = check_output(['protoc', '--version'])

if not (protobuf_version in protoc_version_str):
sys.exit("ERROR: Local version of protoc is %s"
" (see output of `which protoc`)."
" Please use protoc version %s"
" to match the version of protobuf-java used in this repo."
% (protoc_version_str, protobuf_version))


def main():
verify_protoc_version()
# TODO Make the docker image the default, add --local option
parser = argparse.ArgumentParser(description='Batch generate all APIs.')
parser.add_argument('googleapis', help='The path to the googleapis repo')
Expand Down

0 comments on commit ccf68f3

Please sign in to comment.