|
1 | | -# Copyright 2021 Google LLC |
| 1 | +# Copyright 2022 Google LLC |
2 | 2 | # |
3 | | -# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# Licensed under the Apache License, Version 2.0 (the License); |
4 | 4 | # you may not use this file except in compliance with the License. |
5 | 5 | # You may obtain a copy of the License at |
6 | 6 | # |
|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | | -import synthtool as s |
15 | | -import synthtool.gcp as gcp |
16 | 14 | import synthtool.languages.node as node |
17 | | -import logging |
18 | | -import os |
19 | | -from pathlib import Path |
20 | | -from synthtool import _tracked_paths |
21 | | -from typing import AnyStr |
22 | | -import shutil |
23 | | - |
24 | | -logging.basicConfig(level=logging.DEBUG) |
25 | | - |
26 | | -staging = Path("owl-bot-staging") |
27 | | - |
28 | | -if staging.is_dir(): |
29 | | - versions = ['v2'] |
30 | | - versions_admin = [f"admin/{p}" for p in versions] |
31 | | - |
32 | | - logging.info(f"Copying files from staging directory {staging}.") |
33 | | - |
34 | | - src_paths = {} |
35 | | - src_files = {} |
36 | | - for version in versions + versions_admin: |
37 | | - src_paths[version] = staging / version |
38 | | - src_files[version] = list([fn for fn in src_paths[version].glob('**/*.*')]) |
39 | | - |
40 | | - # Copy bigtable library. |
41 | | - # src/index.ts src/admin/v2/index.ts has added AdminClients manually; we don't want to override it. |
42 | | - # src/*.ts is a added layer for the client libraries, they need extra setting in tsconfig.json & tslint.json |
43 | | - # Tracking issues: 1. https://github.com/googleapis/nodejs-bigtable/issues/636 |
44 | | - # 2. https://github.com/googleapis/nodejs-bigtable/issues/635 |
45 | | - for version in versions: |
46 | | - library = src_paths[version] |
47 | | - _tracked_paths.add(library) |
48 | | - admin_files = filter( |
49 | | - lambda f: str(f).find('_admin') >= 0, |
50 | | - src_files[version] |
51 | | - ) |
52 | | - excludes = [ |
53 | | - 'package.json', |
54 | | - 'README.md', |
55 | | - 'src/index.ts', |
56 | | - 'src/v2/index.ts', |
57 | | - 'tsconfig.json', |
58 | | - 'tslint.json', |
59 | | - '.github/sync-repo-settings.yaml', |
60 | | - '.github/workflows/ci.yaml', |
61 | | - '.OwlBot.yaml', |
62 | | - 'samples/generated/v2/*', # we don't want to encourage non-veneer use here. |
63 | | - '.kokoro/samples-test.sh', # get to green |
64 | | - '.kokoro/system-test.sh', |
65 | | - '.kokoro/test.sh', |
66 | | - ] + list(admin_files) |
67 | | - logging.info(f"excluding files for non-admin: {excludes}") |
68 | | - s.copy([library], excludes = excludes) |
69 | | - |
70 | | - # Copy the admin library pieces and knit them in. |
71 | | - # Don't override system-test for admin/v2, just keep the v2 version. |
72 | | - for version in versions: |
73 | | - admin_version = f"admin/{version}" |
74 | | - library = src_paths[admin_version] |
75 | | - inProtoPath = f"protos/google/bigtable/{admin_version}" |
76 | | - protos = library / inProtoPath |
77 | | - classes = library / 'src' / version |
78 | | - samples = library / 'samples' / 'generated' |
79 | | - tests = library / 'test' |
80 | | - _tracked_paths.add(library) |
81 | | - |
82 | | - # We also have to munge the proto paths in the *_proto_list.json due to making it a level deeper. |
83 | | - # That also applies to the classes themselves. |
84 | | - classesStr = str(classes) |
85 | | - jsons = [fn |
86 | | - for fn |
87 | | - in src_files[admin_version] |
88 | | - if str(fn)[:len(classesStr)] == classesStr] |
89 | | - for jfn in jsons: |
90 | | - logging.info(f"munging json file: {str(jfn)}") |
91 | | - contents = jfn.read_text() |
92 | | - contents = contents.replace("'../..", "'../../..") |
93 | | - contents = contents.replace('"../..', '"../../..') |
94 | | - jfn.write_text(contents) |
95 | | - |
96 | | - # Also to the tests that import stuff from src. ../ -> ../../../ |
97 | | - testsStr = str(tests) |
98 | | - tfns = [fn |
99 | | - for fn |
100 | | - in src_files[admin_version] |
101 | | - if str(fn)[:len(testsStr)] == testsStr] |
102 | | - for tfn in tfns: |
103 | | - logging.info(f"munging test file: {str(tfn)}") |
104 | | - contents = tfn.read_text() |
105 | | - |
106 | | - # Fix relative paths. |
107 | | - contents = contents.replace("'../", "'../../../") |
108 | | - |
109 | | - # Use the selective subclasses. |
110 | | - contents = contents.replace(".v2.BigtableInstanceAdminClient", ".admin.InstanceAdminClient") |
111 | | - contents = contents.replace(".v2.BigtableTableAdminClient", ".admin.TableAdminClient") |
112 | | - |
113 | | - # Statics also. |
114 | | - contents = contents.replace("bigtabletableadminModule.v2.BigtableTableAdminClient", \ |
115 | | - "bigtabletableadminModule.admin.TableAdminClient") |
116 | | - contents = contents.replace("bigtabletableadminModule.v2.BigtableInstanceAdminClient", \ |
117 | | - "bigtabletableadminModule.admin.InstanceAdminClient") |
118 | | - |
119 | | - tfn.write_text(contents) |
120 | | - |
121 | | - # Finally, the samples. Shift to selective subclasses, and mark the samples |
122 | | - # with CUJs as internal, in favour of the handwritten ones. |
123 | | - samplesStr = str(samples) |
124 | | - sfns = [fn |
125 | | - for fn |
126 | | - in src_files[admin_version] |
127 | | - if str(fn)[:len(samplesStr)] == samplesStr] |
128 | | - for sfn in sfns: |
129 | | - logging.info(f"munging sample file: {str(sfn)}") |
130 | | - contents = sfn.read_text() |
131 | | - contents = contents.replace("const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2", \ |
132 | | - "const {InstanceAdminClient} = require('@google-cloud/bigtable').admin") |
133 | | - contents = contents.replace("const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2", \ |
134 | | - "const {TableAdminClient} = require('@google-cloud/bigtable').admin") |
135 | | - contents = contents.replace("new BigtableInstanceAdminClient", "new InstanceAdminClient") |
136 | | - contents = contents.replace("new BigtableTableAdminClient", "new TableAdminClient") |
137 | | - |
138 | | - # We need to disable this one so the handwritten sample |
139 | | - # can take over for the CUJ. |
140 | | - contents = contents.replace("bigtableadmin_v2_generated_BigtableTableAdmin_RestoreTable_async", \ |
141 | | - "bigtableadmin_v2_generated_BigtableTableAdmin_RestoreTable_async_internal") |
142 | | - |
143 | | - sfn.write_text(contents) |
144 | | - |
145 | | - os.system(f"mkdir -p {inProtoPath}") |
146 | | - s.copy([protos / '*'], destination=inProtoPath) |
147 | | - os.system(f"mkdir -p src/{admin_version}") |
148 | | - s.copy([classes / '*'], destination=f"src/{admin_version}") |
149 | | - os.system(f"mkdir -p samples/generated/{admin_version}") |
150 | | - s.copy([samples / 'v2' / '*admin*'], destination=f"samples/generated/{admin_version}") |
151 | | - os.system(f"mkdir -p test/{admin_version}") |
152 | | - s.copy([tests / '*admin*.ts'], destination=f"test/{admin_version}") |
153 | | - |
154 | | - # Replace the client name for generated system-test. |
155 | | - system_test_files=['system-test/fixtures/sample/src/index.ts','system-test/fixtures/sample/src/index.js'] |
156 | | - for file in system_test_files: |
157 | | - s.replace(file, 'BigtableClient', 'Bigtable') |
158 | | - s.replace(file, 'client.close', '// client.close') # this does not work with the manual layer |
159 | | - s.replace(file, 'function doStuffWith', '// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction doStuffWith') |
160 | | - |
161 | | - # The staging directory should never be merged into the main branch. |
162 | | - shutil.rmtree(staging) |
163 | | - |
164 | | -common_templates = gcp.CommonTemplates() |
165 | | -templates = common_templates.node_library( |
166 | | - source_location='build/src' |
167 | | -) |
168 | | -s.copy(templates,excludes=[ |
169 | | - '.github/auto-approve.yml', |
170 | | - '.github/sync-repo-settings.yaml', |
171 | | - '.github/workflows/ci.yaml', |
172 | | - '.kokoro/samples-test.sh', # get to green |
173 | | - '.kokoro/system-test.sh', |
174 | | - '.kokoro/test.sh', |
| 15 | +node.owlbot_main(templates_excludes=[ |
| 16 | +'README.md' |
175 | 17 | ]) |
176 | | - |
177 | | -node.postprocess_gapic_library_hermetic() |
0 commit comments