1+ GRPCIO_VIRTUALENV=$(shell pwd)/grpc_python_venv
12GENERATED_DIR=$(shell pwd)/generated_python
23GENERATED_SUBDIR=_generated_v2
34BIGTABLE_DIR=$(shell pwd)/gcloud/bigtable/$(GENERATED_SUBDIR)
4- GRPC_PLUGIN=grpc_python_plugin
5- PROTOC_CMD=protoc
6- BIGTABLE_CHECKOUT_DIR=$(shell pwd)/cloud-bigtable-client
7- BIGTABLE_PROTOS_DIR=$(BIGTABLE_CHECKOUT_DIR)/bigtable-protos/src/main/proto
5+ PROTOC_CMD=$(GRPCIO_VIRTUALENV)/bin/python -m grpc.tools.protoc
86GOOGLEAPIS_PROTOS_DIR=$(shell pwd)/googleapis-pb
97
108help:
@@ -15,41 +13,39 @@ help:
1513@echo ' make clean Clean generated files '
1614
1715generate:
16+ # Ensure we have a virtualenv w/ up-to-date grpcio/grpcio-tools
17+ [ -d $(GRPCIO_VIRTUALENV) ] || python2.7 -m virtualenv $(GRPCIO_VIRTUALENV)
18+ $(GRPCIO_VIRTUALENV)/bin/pip install --upgrade grpcio grpcio-tools
1819# Retrieve git repos that have our *.proto files.
19- [ -d $(BIGTABLE_CHECKOUT_DIR) ] || git clone https://github.com/GoogleCloudPlatform/cloud-bigtable-client --depth=1
20- cd $(BIGTABLE_CHECKOUT_DIR) && git pull origin master
2120[ -d googleapis-pb ] || git clone https://github.com/google/googleapis googleapis-pb --depth=1
2221cd googleapis-pb && git pull origin master
2322# Make the directory where our *_pb2.py files will go.
2423mkdir -p $(GENERATED_DIR)
2524# Generate all *_pb2.py files that require gRPC.
2625$(PROTOC_CMD) \
27- --proto_path=$(BIGTABLE_PROTOS_DIR ) \
26+ --proto_path=$(GOOGLEAPIS_PROTOS_DIR ) \
2827 --python_out=$(GENERATED_DIR) \
29- --plugin=protoc-gen-grpc=$(GRPC_PLUGIN) \
30- --grpc_out=$(GENERATED_DIR) \
31- $(BIGTABLE_PROTOS_DIR)/google/bigtable/v2/bigtable.proto \
32- $(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/v2/bigtable_instance_admin.proto \
33- $(BIGTABLE_PROTOS_DIR)/google/bigtable/admin/v2/bigtable_table_admin.proto
28+ --grpc_python_out=$(GENERATED_DIR) \
29+ $(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/v2/bigtable.proto \
30+ $(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/admin/v2/bigtable_instance_admin.proto \
31+ $(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/admin/v2/bigtable_table_admin.proto
3432# Generate all *_pb2.py files that do not require gRPC.
3533$(PROTOC_CMD) \
36- --proto_path=$(BIGTABLE_PROTOS_DIR) \
3734 --proto_path=$(GOOGLEAPIS_PROTOS_DIR) \
3835 --python_out=$(GENERATED_DIR) \
39- $(BIGTABLE_PROTOS_DIR )/google/bigtable/v2/data.proto \
40- $(BIGTABLE_PROTOS_DIR )/google/bigtable/admin/v2/common.proto \
41- $(BIGTABLE_PROTOS_DIR )/google/bigtable/admin/v2/instance.proto \
42- $(BIGTABLE_PROTOS_DIR )/google/bigtable/admin/v2/table.proto \
36+ $(GOOGLEAPIS_PROTOS_DIR )/google/bigtable/v2/data.proto \
37+ $(GOOGLEAPIS_PROTOS_DIR )/google/bigtable/admin/v2/common.proto \
38+ $(GOOGLEAPIS_PROTOS_DIR )/google/bigtable/admin/v2/instance.proto \
39+ $(GOOGLEAPIS_PROTOS_DIR )/google/bigtable/admin/v2/table.proto \
4340# Move the newly generated *_pb2.py files into our library.
4441cp $(GENERATED_DIR)/google/bigtable/v2/* $(BIGTABLE_DIR)
4542cp $(GENERATED_DIR)/google/bigtable/admin/v2/* $(BIGTABLE_DIR)
46- cp $(GENERATED_DIR)/google/bigtable/admin/v2/* $(BIGTABLE_DIR)
4743# Remove all existing *.proto files before we replace
4844rm -f $(BIGTABLE_DIR)/*.proto
4945# Copy over the *.proto files into our library.
50- cp $(BIGTABLE_PROTOS_DIR )/google/bigtable/v2/*.proto $(BIGTABLE_DIR)
51- cp $(BIGTABLE_PROTOS_DIR )/google/bigtable/admin/v2/*.proto $(BIGTABLE_DIR)
52- cp $(BIGTABLE_PROTOS_DIR )/google/longrunning/operations.proto $(BIGTABLE_DIR)
46+ cp $(GOOGLEAPIS_PROTOS_DIR )/google/bigtable/v2/*.proto $(BIGTABLE_DIR)
47+ cp $(GOOGLEAPIS_PROTOS_DIR )/google/bigtable/admin/v2/*.proto $(BIGTABLE_DIR)
48+ cp $(GOOGLEAPIS_PROTOS_DIR )/google/longrunning/operations.proto $(BIGTABLE_DIR)
5349# Rename all *.proto files in our library with an
5450# underscore and remove executable bit.
5551cd $(BIGTABLE_DIR) && \
@@ -60,8 +56,8 @@ generate:
6056# Separate the gRPC parts of the operations service from the
6157# non-gRPC parts so that the protos from `googleapis-common-protos`
6258# can be used without gRPC.
63- PROTOC_CMD=$(PROTOC_CMD) GRPC_PLUGIN=$(GRPC_PLUGIN) \
64- GENERATED_SUBDIR=$(GENERATED_SUBDIR) \
59+ GRPCIO_VIRTUALENV="$(GRPCIO_VIRTUALENV)" \
60+ GENERATED_SUBDIR=$(GENERATED_SUBDIR) \
6561python scripts/make_operations_grpc.py
6662# Rewrite the imports in the generated *_pb2.py files.
6763python scripts/rewrite_imports.py $(BIGTABLE_DIR)/*pb2.py
@@ -70,6 +66,6 @@ check_generate:
7066python scripts/check_generate.py
7167
7268clean:
73- rm -fr $(BIGTABLE_CHECKOUT_DIR ) $(GOOGLEAPIS_PROTOS_DIR) $(GENERATED_DIR)
69+ rm -fr $(GRPCIO_VIRTUALENV ) $(GOOGLEAPIS_PROTOS_DIR) $(GENERATED_DIR)
7470
7571.PHONY: generate check_generate clean
0 commit comments