forked from googleapis/java-bigtable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynth.py
148 lines (121 loc) · 6.53 KB
/
synth.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This script is used to synthesize generated parts of this library."""
import re
import synthtool as s
import synthtool.gcp as gcp
import synthtool.languages.java as java
AUTOSYNTH_MULTIPLE_COMMITS = True
# TODO: try to move the GAPIC surface hiding to the gapic-generator:
# https://github.com/googleapis/gapic-generator/issues/2742
def main():
gapic = gcp.GAPICBazel()
generate_data_api(gapic)
generate_admin_api(gapic)
java.format_code(f'./google-cloud-bigtable/src')
java.common_templates(excludes=[
'.gitignore',
'README.md',
'.kokoro/presubmit/integration.cfg',
'.kokoro/nightly/integration.cfg',
'.kokoro/presubmit/samples.cfg',
'.kokoro/nightly/samples.cfg',
# todo remove once template is updated
'.github/ISSUE_TEMPLATE/bug_report.md',
'CONTRIBUTING.md',
])
def generate_data_api(gapic):
library = gapic.java_library(
service='bigtable',
version='v2',
proto_path=f'google/bigtable/v2',
bazel_target=f'//google/bigtable/v2:google-cloud-bigtable-v2-java',
)
library = library / 'google-cloud-bigtable-v2-java'
# Excludes are relative to source `gapic-google-cloud-bigtable-v2/src`
excludes = [
"build.gradle",
"pom.xml",
"README.md",
"src/main/java/com/google/cloud/bigtable/data/v2/package-info.java",
"src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataClient.java",
"src/main/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataSettings.java",
"src/test/java/com/google/cloud/bigtable/data/v2/BaseBigtableDataClientTest.java",
"src/test/java/com/google/cloud/bigtable/data/v2/MockBigtable.java",
"src/test/java/com/google/cloud/bigtable/data/v2/MockBigtableImpl.java",
]
# Paths are relative to the destination, which is the current working directory
internal_only = [
"google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStub.java",
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableStubSettings.java',
"google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableStub.java",
"google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/GrpcBigtableCallableFactory.java",
]
package_name = f'com.google.bigtable.v2'
java.fix_proto_headers(library / f'proto-google-cloud-bigtable-v2-java')
java.fix_grpc_headers(library / f'grpc-google-cloud-bigtable-v2-java', package_name)
s.copy(library / f'gapic-google-cloud-bigtable-v2-java', 'google-cloud-bigtable/', excludes=excludes)
s.copy(library / f'grpc-google-cloud-bigtable-v2-java/src', f'grpc-google-cloud-bigtable-v2/src')
s.copy(library / f'proto-google-cloud-bigtable-v2-java/src', f'proto-google-cloud-bigtable-v2/src')
make_internal_only(internal_only)
java.format_code(f'./grpc-google-cloud-bigtable-v2/src')
java.format_code(f'./proto-google-cloud-bigtable-v2/src')
def generate_admin_api(gapic):
library = gapic.java_library(
service='bigtable-admin',
version='v2',
bazel_target=f'//google/bigtable/admin/v2:google-cloud-bigtable-admin-v2-java',
proto_path=f'google/bigtable/admin/v2',
)
library = library / 'google-cloud-bigtable-admin-v2-java'
# Excludes are relative to source `gapic-google-cloud-bigtable-v2/src`
excludes = [
"main/java/com/google/cloud/bigtable/admin/v2/package-info.java",
]
# Paths are relative to the destination, which is the current working directory
internal_only = [
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminCallableFactory.java',
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableInstanceAdminStub.java',
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BaseBigtableInstanceAdminSettings.java',
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminCallableFactory.java',
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/GrpcBigtableTableAdminStub.java',
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BaseBigtableTableAdminSettings.java',
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableInstanceAdminStub.java',
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/stub/BigtableTableAdminStub.java',
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BaseBigtableInstanceAdminClient.java',
'google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/BaseBigtableTableAdminClient.java',
]
package_name = f'com.google.cloud.bigtable.admin.v2'
java.fix_proto_headers(library / f'proto-google-cloud-bigtable-admin-v2-java')
java.fix_grpc_headers(library / f'grpc-google-cloud-bigtable-admin-v2-java', package_name)
s.copy(library / f'gapic-google-cloud-bigtable-admin-v2-java/src', 'google-cloud-bigtable/src', excludes=excludes)
s.copy(library / f'grpc-google-cloud-bigtable-admin-v2-java/src', f'grpc-google-cloud-bigtable-admin-v2/src')
s.copy(library / f'proto-google-cloud-bigtable-admin-v2-java/src', f'proto-google-cloud-bigtable-admin-v2/src')
make_internal_only(internal_only)
java.format_code(f'./grpc-google-cloud-bigtable-admin-v2/src')
java.format_code(f'./proto-google-cloud-bigtable-admin-v2/src')
def make_internal_only(sources):
"""Annotates all toplevel classes with `@InternalOnly`"""
# Insert InternalOnly import in the non-static.
s.replace(sources,
before=r'^(import (?!static).*?\n)\n',
after=r'\1import com.google.api.core.InternalApi;\n\n',
flags=re.MULTILINE | re.DOTALL)
# Replace javadoc and annotations before every public class with InternalApi
# javadoc and annotation
s.replace(sources,
before=r'/\*\*.+?\*/\n(?:^@[^\n]*\n)*(?=public [a-zA-B ]*class)',
after='/** For internal use only. */\n@Generated("by gapic-generator")\n@InternalApi\n',
flags=re.MULTILINE | re.DOTALL)
main()