forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.bigtable_v2
71 lines (66 loc) · 3.3 KB
/
Makefile.bigtable_v2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
GRPCIO_VIRTUALENV=$(shell pwd)/grpc_python_venv
GENERATED_DIR=$(shell pwd)/generated_python
GENERATED_SUBDIR=_generated_v2
BIGTABLE_DIR=$(shell pwd)/gcloud/bigtable/$(GENERATED_SUBDIR)
PROTOC_CMD=$(GRPCIO_VIRTUALENV)/bin/python -m grpc.tools.protoc
GOOGLEAPIS_PROTOS_DIR=$(shell pwd)/googleapis-pb
help:
@echo 'Makefile for gcloud-python Bigtable protos '
@echo ' '
@echo ' make generate Generates the protobuf modules '
@echo ' make check_generate Checks that generate succeeded '
@echo ' make clean Clean generated files '
generate:
# Ensure we have a virtualenv w/ up-to-date grpcio/grpcio-tools
[ -d $(GRPCIO_VIRTUALENV) ] || python2.7 -m virtualenv $(GRPCIO_VIRTUALENV)
$(GRPCIO_VIRTUALENV)/bin/pip install --upgrade grpcio grpcio-tools
# Retrieve git repos that have our *.proto files.
[ -d googleapis-pb ] || git clone https://github.com/google/googleapis googleapis-pb --depth=1
cd googleapis-pb && git pull origin master
# Make the directory where our *_pb2.py files will go.
mkdir -p $(GENERATED_DIR)
# Generate all *_pb2.py files that require gRPC.
$(PROTOC_CMD) \
--proto_path=$(GOOGLEAPIS_PROTOS_DIR) \
--python_out=$(GENERATED_DIR) \
--grpc_python_out=$(GENERATED_DIR) \
$(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/v2/bigtable.proto \
$(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/admin/v2/bigtable_instance_admin.proto \
$(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/admin/v2/bigtable_table_admin.proto
# Generate all *_pb2.py files that do not require gRPC.
$(PROTOC_CMD) \
--proto_path=$(GOOGLEAPIS_PROTOS_DIR) \
--python_out=$(GENERATED_DIR) \
$(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/v2/data.proto \
$(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/admin/v2/common.proto \
$(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/admin/v2/instance.proto \
$(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/admin/v2/table.proto \
# Move the newly generated *_pb2.py files into our library.
cp $(GENERATED_DIR)/google/bigtable/v2/* $(BIGTABLE_DIR)
cp $(GENERATED_DIR)/google/bigtable/admin/v2/* $(BIGTABLE_DIR)
# Remove all existing *.proto files before we replace
rm -f $(BIGTABLE_DIR)/*.proto
# Copy over the *.proto files into our library.
cp $(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/v2/*.proto $(BIGTABLE_DIR)
cp $(GOOGLEAPIS_PROTOS_DIR)/google/bigtable/admin/v2/*.proto $(BIGTABLE_DIR)
cp $(GOOGLEAPIS_PROTOS_DIR)/google/longrunning/operations.proto $(BIGTABLE_DIR)
# Rename all *.proto files in our library with an
# underscore and remove executable bit.
cd $(BIGTABLE_DIR) && \
for filename in *.proto; do \
chmod -x $$filename ; \
mv $$filename _$$filename ; \
done
# Separate the gRPC parts of the operations service from the
# non-gRPC parts so that the protos from `googleapis-common-protos`
# can be used without gRPC.
GRPCIO_VIRTUALENV="$(GRPCIO_VIRTUALENV)" \
GENERATED_SUBDIR=$(GENERATED_SUBDIR) \
python scripts/make_operations_grpc.py
# Rewrite the imports in the generated *_pb2.py files.
python scripts/rewrite_imports.py $(BIGTABLE_DIR)/*pb2.py
check_generate:
python scripts/check_generate.py
clean:
rm -fr $(GRPCIO_VIRTUALENV) $(GOOGLEAPIS_PROTOS_DIR) $(GENERATED_DIR)
.PHONY: generate check_generate clean