Skip to content

Commit 1145a8c

Browse files
authored
doc: howto expand library (#11884)
1 parent 9d4d06b commit 1145a8c

1 file changed

Lines changed: 63 additions & 22 deletions

File tree

doc/contributor/howto-guide-adding-generated-libraries.md

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,30 @@ This document describes the steps required to add a new library to
55
familiar with the existing libraries, the build systems used in those
66
libraries, and which libraries are based on gRPC.
77

8+
## Adding a new library
9+
810
> :warning: For libraries that include multiple services, the scaffold README
911
> files (and any other documentation) will use the **last** service description
1012
> as the description of the library. Adjust the ordering and/or fix the
1113
> documentation after the fact.
1214
13-
## Set your working directory
15+
### Set your working directory
1416

1517
Go to whatever directory holds your clone of the project, for example:
1618

1719
```shell
1820
cd $HOME/google-cloud-cpp
1921
```
2022

21-
## Set some useful variables
23+
### Set some useful variables
2224

2325
```shell
2426
library=... # The name of your new library in the google-cloud-cpp repository
2527
subdir="google/cloud/${library}" # The path in googleapis repo, may not start with google/cloud/
2628
bazel_output_base="$(bazel info output_base)"
2729
```
2830

29-
## Verify the C++ rules exist
31+
### Verify the C++ rules exist
3032

3133
```shell
3234
bazel --batch query --noshow_progress --noshow_loading_progress \
@@ -36,7 +38,7 @@ bazel --batch query --noshow_progress --noshow_loading_progress \
3638
If this fails, send a CL to add the rule. Wait until that is submitted and
3739
exported before proceeding any further.
3840

39-
## Edit the scripts and configuration
41+
### Edit the scripts and configuration
4042

4143
Update the `external/googleapis/update_libraries.sh` script.
4244

@@ -64,7 +66,7 @@ index cdaa0bc9f..b0381d72d 100755
6466

6567
</details>
6668

67-
## Update the Generator Configuration
69+
### Update the Generator Configuration
6870

6971
Determine the retryable status codes by looking in the service config JSON. For
7072
example, [here][retryable-status-codes].
@@ -107,7 +109,7 @@ index ab033dde9..3753287d8 100644
107109

108110
</details>
109111

110-
## Commit these changes
112+
### Commit these changes
111113

112114
Create your first commit with purely hand-crafted changes
113115

@@ -116,13 +118,13 @@ git checkout -b feat-${library}-generate-library
116118
git commit -m"feat(${library}): generate library" external/ generator/
117119
```
118120

119-
## Update the list of proto files and proto dependencies
121+
### Update the list of proto files and proto dependencies
120122

121123
```shell
122124
external/googleapis/update_libraries.sh "${library}"
123125
```
124126

125-
## Run the Scaffold Generator
127+
### Run the Scaffold Generator
126128

127129
Then run the micro-generator to create the scaffold and the C++ sources:
128130

@@ -141,21 +143,21 @@ bazel run \
141143
To generate a library that is initially experimental, add an
142144
`--experimental_scaffold` flag.
143145

144-
## Fix formatting of existing libraries and the generated code
146+
### Fix formatting of existing libraries and the generated code
145147

146148
```shell
147149
git add "google/cloud/${library}"
148150
ci/cloudbuild/build.sh -t checkers-pr
149151
```
150152

151-
## Commit all the generated files
153+
### Commit all the generated files
152154

153155
```shell
154156
git add external ci "google/cloud/${library}"
155157
git commit -m"Run generators and format their outputs"
156158
```
157159

158-
## Create any custom source files
160+
### Create any custom source files
159161

160162
If the `generator/generator_config.textproto` entry for the service does not
161163
enumerate the `retryable_status_codes`, you need to manually create the file as
@@ -165,14 +167,14 @@ Likewise, for services using streaming operations you may need to implement the
165167
streaming `*Updater` function. Use `google/cloud/bigquery/internal/streaming.cc`
166168
or `google/cloud/logging/internal/streaming.cc` for inspiration.
167169

168-
## Potentially fix the bazel build
170+
### Potentially fix the bazel build
169171

170172
The generated `BUILD.bazel` file may require manual editing. The scaffold will
171173
add one dependency from `@com_github_googleapis//${subdir}`, which might not be
172174
correct. You may need to modify that dependency and/or add additional
173175
dependencies for more complex libraries.
174176

175-
## Potentially update the service directories
177+
### Potentially update the service directories
176178

177179
A library may contain services in several subdirectories. The scaffold only
178180
knows about one such subdirectory. You may need to manually update the
@@ -183,15 +185,15 @@ knows about one such subdirectory. You may need to manually update the
183185

184186
[#10237] offers one way to automate this step.
185187

186-
## Update the root files
188+
### Update the root files
187189

188190
Manually edit `cmake/GoogleCloudCppFeatures.cmake` to include the new target.
189191
If you are generating a GA library, add it to `GOOGLE_CLOUD_CPP_GA_LIBRARIES`.
190192
Otherwise, if you are generating an experimental library, add it to
191193
`GOOGLE_CLOUD_CPP_EXPERIMENTAL_LIBRARIES` and note in a comment when the library
192194
was generated.
193195

194-
## Update the quickstart
196+
### Update the quickstart
195197

196198
The generated quickstart will need some editing. Use a simple operation, maybe
197199
an admin operation listing top-level resources, to demonstrate how to use the
@@ -207,7 +209,7 @@ arguments in the CI builds.
207209

208210
- `google/cloud/${library}/CMakeLists.txt`
209211

210-
## Add the API baseline
212+
### Add the API baseline
211213

212214
For new GA libraries you need to create the API baseline. You can leave this
213215
running while you work on tweaks to the quickstart and documentation.
@@ -218,7 +220,7 @@ git add ci/abi-dumps
218220
git commit -m"Add API baseline" ci/abi-dumps/
219221
```
220222

221-
## Update the README files
223+
### Update the README files
222224

223225
The following files probably need some light copy-editing to read less like they
224226
were written by a robot:
@@ -231,24 +233,24 @@ were written by a robot:
231233
The Cloud documentation links (`cloud.google.com/*/docs/*`) in these files are
232234
not always valid. Find the correct urls and update the links.
233235

234-
## Review the metadata file
236+
### Review the metadata file
235237

236238
Newer services provide all the data needed to generate this file correctly,
237239
but with older services we need to edit a few places:
238240

239241
- `google/cloud/${library}/**/.repo-metadata.json`
240242

241-
## Edit the top-level CHANGELOG file
243+
### Edit the top-level CHANGELOG file
242244

243245
Announce the new library in the CHANGELOG for the next release.
244246

245-
## Fix formatting nits
247+
### Fix formatting nits
246248

247249
```shell
248250
ci/cloudbuild/build.sh -t checkers-pr
249251
```
250252

251-
## Verify everything compiles
253+
### Verify everything compiles
252254

253255
```shell
254256
bazel build //google/cloud/${library}/...
@@ -280,11 +282,50 @@ index c4ce00489..1858b48dc 100755
280282

281283
</details>
282284

283-
## Commit these changes
285+
### Commit these changes
284286

285287
```shell
286288
git commit -m"Manually update READMEs, quickstart, and top-level stuff" .
287289
```
288290

291+
## Expanding a library
292+
293+
> This section assumes the developer is familiar with running the generator. For
294+
> more details on any of the steps involved, see the "Adding a new library"
295+
> section.
296+
297+
Sometimes we add services to libraries that already exist. In this case we do
298+
not need to run the scaffold generator. We provide a simple checklist below.
299+
300+
### Manual changes
301+
302+
```sh
303+
library=... # e.g. bigquery
304+
api_name=... # e.g. BigLake API
305+
```
306+
307+
- Update `generator_config.textproto`
308+
- Update and run `external/googleapis/update_libraries.sh ${library}`
309+
- Add the new directory to `service_dirs` in:
310+
- `google/cloud/${library}/CMakeLists.txt`
311+
- `google/cloud/${library}/BUILD.bazel`
312+
- Add the new `*_cc_grpc` dependency to
313+
`//google/cloud/${library}:${library}_client` in
314+
`google/cloud/${library}/BUILD.bazel`
315+
- Announce the new API in the `CHANGELOG.md`
316+
- e.g. `The library has been expanded to include the ${api_name}.`
317+
- Commit the manual changes
318+
- `git commit -am "feat(${library}): add ${api_name}"`
319+
320+
### Generated changes
321+
322+
```shell
323+
ci/cloudbuild/build.sh -t generate-libraries-pr
324+
env GOOGLE_CLOUD_CPP_CHECK_API ${library} ci/cloudbuild/build.sh -t check-api-pr
325+
git add .
326+
ci/cloudbuild/build.sh -t checkers-pr
327+
git commit -am "generated changes"
328+
```
329+
289330
[#10237]: https://github.com/googleapis/google-cloud-cpp/issues/10237
290331
[retryable-status-codes]: https://github.com/googleapis/googleapis/blob/70147caca58ebf4c8cd7b96f5d569a72723e11c1/google/cloud/secretmanager/v1/secretmanager_grpc_service_config.json#L77-L80

0 commit comments

Comments
 (0)