Skip to content

Commit ccf68f3

Browse files
authored
Verify protoc version for batch-generation (#3676)
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.
1 parent 1d7b95f commit ccf68f3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

utilities/batch_generate_apis.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
# $ git clone https://github.com/googleapis/googleapis.git
2121
# $ git clone https://github.com/googleapis/discovery-artifact-manager.git
2222
#
23-
# Run this script:
23+
# Run this script from the top-level google-cloud-java directory:
2424
#
2525
# $ python utilities/batch_generate_apis.py PATH_TO_GOOGLEAPIS PATH_TO_DISCOVERY_ARTIFACT_MANAGER
2626

2727
import argparse
2828
import os
29+
import sys
30+
from subprocess import check_output
2931

3032
import generate_api
3133

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

9597

98+
def verify_protoc_version():
99+
protobuf_version_node = check_output(
100+
['grep', '-zohr', '--include=pom.xml',
101+
'<protobuf.version>.*</protobuf.version>'])
102+
version_start_index = protobuf_version_node.find('>') + 1
103+
version_end_index = protobuf_version_node.rfind('<')
104+
protobuf_version = protobuf_version_node[version_start_index : version_end_index].strip()
105+
106+
# This will be something like 'libprotoc 3.6.0'
107+
protoc_version_str = check_output(['protoc', '--version'])
108+
109+
if not (protobuf_version in protoc_version_str):
110+
sys.exit("ERROR: Local version of protoc is %s"
111+
" (see output of `which protoc`)."
112+
" Please use protoc version %s"
113+
" to match the version of protobuf-java used in this repo."
114+
% (protoc_version_str, protobuf_version))
115+
116+
96117
def main():
118+
verify_protoc_version()
97119
# TODO Make the docker image the default, add --local option
98120
parser = argparse.ArgumentParser(description='Batch generate all APIs.')
99121
parser.add_argument('googleapis', help='The path to the googleapis repo')

0 commit comments

Comments
 (0)