Skip to content

Commit a687c87

Browse files
authored
chore(generator): add env var to reduce scope of generate-libraries build (#10150)
1 parent e17c8fc commit a687c87

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

ci/cloudbuild/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ if [[ "${DOCKER_FLAG}" = "true" ]]; then
346346
# Makes the host's gcloud credentials visible inside the docker container,
347347
# which we need for integration tests.
348348
"--volume=${HOME}/.config/gcloud:/h/.config/gcloud:Z"
349+
# Makes the generate-libraries build ONLY touch golden files in the
350+
# generator dir.
351+
"--env=GENERATE_GOLDEN_ONLY=${GENERATE_GOLDEN_ONLY-}"
349352
)
350353
# All GOOGLE_CLOUD_* env vars will be passed to the docker container.
351354
for e in $(env); do

ci/cloudbuild/builds/generate-libraries.sh

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,39 @@ bazel run --action_env=GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes \
3232
--update_ci=false \
3333
--config_file="${PWD}/generator/integration_tests/golden_config.textproto"
3434

35-
io::log_h2 "Running the generator to update the generated libraries"
36-
bazel run --action_env=GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes \
37-
//generator:google-cloud-cpp-codegen -- \
38-
--protobuf_proto_path="${bazel_output_base}"/external/com_google_protobuf/src \
39-
--googleapis_proto_path="${bazel_output_base}"/external/com_google_googleapis \
40-
--output_path="${PROJECT_ROOT}" \
41-
--config_file="${PROJECT_ROOT}/generator/generator_config.textproto"
42-
43-
# TODO(#5821): The generator should run clang-format on its output files itself
44-
# so we don't need this extra step.
45-
io::log_h2 "Formatting generated code"
46-
git ls-files -z -- '*.h' '*.cc' |
47-
xargs -P "$(nproc)" -n 1 -0 clang-format -i
48-
49-
io::log_h2 "Updating protobuf lists/deps"
50-
external/googleapis/update_libraries.sh
35+
if [ -z "${GENERATE_GOLDEN_ONLY}" ]; then
36+
io::log_h2 "Running the generator to update the generated libraries"
37+
bazel run --action_env=GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes \
38+
//generator:google-cloud-cpp-codegen -- \
39+
--protobuf_proto_path="${bazel_output_base}"/external/com_google_protobuf/src \
40+
--googleapis_proto_path="${bazel_output_base}"/external/com_google_googleapis \
41+
--output_path="${PROJECT_ROOT}" \
42+
--config_file="${PROJECT_ROOT}/generator/generator_config.textproto"
43+
else
44+
io::log_red "Skipping update of generated libraries."
45+
fi
46+
47+
if [ -z "${GENERATE_GOLDEN_ONLY}" ]; then
48+
# TODO(#5821): The generator should run clang-format on its output files itself
49+
# so we don't need this extra step.
50+
io::log_h2 "Formatting generated code"
51+
git ls-files -z -- '*.h' '*.cc' |
52+
xargs -P "$(nproc)" -n 1 -0 clang-format -i
53+
else
54+
io::log_red "Only formatting generated golden code."
55+
git ls-files -z -- 'generator/integration_tests/golden/internal/*.h' \
56+
'generator/integration_tests/golden/*.h' \
57+
'generator/integration_tests/golden/internal/*.cc' \
58+
'generator/integration_tests/golden/*.cc' |
59+
xargs -P "$(nproc)" -n 1 -0 clang-format -i
60+
fi
61+
62+
if [ -z "${GENERATE_GOLDEN_ONLY}" ]; then
63+
io::log_h2 "Updating protobuf lists/deps"
64+
external/googleapis/update_libraries.sh
65+
else
66+
io::log_red "Skipping update of protobuf lists/deps."
67+
fi
5168

5269
# This build should fail if any generated files differ from what was checked
5370
# in. We only look in the google/ directory so that the build doesn't fail if

ci/cloudbuild/cloudbuild.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ options:
2525
'COMMIT_SHA=${COMMIT_SHA}',
2626
'PR_NUMBER=${_PR_NUMBER}',
2727
'TRIGGER_TYPE=${_TRIGGER_TYPE}',
28+
'GENERATE_GOLDEN_ONLY=""',
2829
'CONSOLE_LOG_URL=https://console.cloud.google.com/cloud-build/builds;region=us-east1/${BUILD_ID};tab=detail?project=${PROJECT_ID}',
2930
'RAW_LOG_URL=https://storage.googleapis.com/${_LOGS_BUCKET}/logs/google-cloud-cpp/${_TRIGGER_SOURCE}/${COMMIT_SHA}/${_DISTRO}-${_BUILD_NAME}/log-${BUILD_ID}.txt'
3031
]

0 commit comments

Comments
 (0)