Repository navigation
fix(generator): align proto_library_with_info deps with librarian.yaml additional_protos - #4691
jinseopkim0 wants to merge 1 commit into
Conversation
…l additional_protos
There was a problem hiding this comment.
Code Review
This pull request updates the Spring Cloud generator scripts to extract additional_protos from librarian.yaml and use them to align the dependencies of proto_library_with_info in BUILD.bazel files. Specifically, it updates generate-library-list.sh to parse and append additional_protos to the library list, and modifies generate-steps.sh and generate.sh to pass and process these protos, conditionally removing unneeded dependencies like IAM policy and location protos. The review feedback suggests two key improvements: first, adding a fallback in the yq evaluation to safely handle cases where additional_protos is null or missing; second, simplifying the buildozer commands in generate-steps.sh by targeting %proto_library_with_info directly to avoid unnecessary subshells and handle multiple rules robustly.
| fi | ||
|
|
||
| echo "$unique_module_name, $proto_paths_latest, $distribution_name, $monorepo_folder" >> $filename | ||
| additional_protos=$(yq eval '.libraries[] | select(.name == "'$name'") | .apis[] | select(.path == "'$proto_paths_latest'") | .java.additional_protos[].path' ./google-cloud-java/librarian.yaml | paste -sd ";" -) |
There was a problem hiding this comment.
If a library does not define additional_protos in librarian.yaml, yq will attempt to iterate over a null value (via .java.additional_protos[]), which prints Error: Cannot iterate over null to stderr. Since generate-library-list.sh runs with set -ex, this clutters the error logs with noisy error messages for almost every library.
Using the alternative operator // [] ensures that yq safely defaults to an empty array when additional_protos is missing or null.
| additional_protos=$(yq eval '.libraries[] | select(.name == "'$name'") | .apis[] | select(.path == "'$proto_paths_latest'") | .java.additional_protos[].path' ./google-cloud-java/librarian.yaml | paste -sd ";" -) | |
| additional_protos=$(yq eval '.libraries[] | select(.name == "'$name'") | .apis[] | select(.path == "'$proto_paths_latest'") | .java.additional_protos // [] | .[].path' ./google-cloud-java/librarian.yaml | paste -sd ";" -) |
| PROTO_WITH_INFO_NAME="$(buildozer 'print name' ${path_to_build_file}:%proto_library_with_info 2>/dev/null || true)" | ||
| if [[ -n "$PROTO_WITH_INFO_NAME" ]]; then | ||
| if [[ "$additional_protos" != *"google/iam/v1/iam_policy.proto"* ]]; then | ||
| buildozer 'remove deps //google/iam/v1:iam_policy_proto' "${path_to_build_file}:${PROTO_WITH_INFO_NAME}" 2>/dev/null || true | ||
| fi | ||
| if [[ "$additional_protos" != *"google/cloud/location/locations.proto"* ]]; then | ||
| buildozer 'remove deps //google/cloud/location:location_proto' "${path_to_build_file}:${PROTO_WITH_INFO_NAME}" 2>/dev/null || true | ||
| fi | ||
| fi |
There was a problem hiding this comment.
Instead of querying the name of the proto_library_with_info rule first and checking if it exists, you can target %proto_library_with_info directly in the buildozer command.
This is more concise, avoids an extra subshell invocation of buildozer, and is more robust if a BUILD.bazel file contains multiple proto_library_with_info rules (where PROTO_WITH_INFO_NAME would contain newlines and cause the subsequent buildozer commands to fail).
| PROTO_WITH_INFO_NAME="$(buildozer 'print name' ${path_to_build_file}:%proto_library_with_info 2>/dev/null || true)" | |
| if [[ -n "$PROTO_WITH_INFO_NAME" ]]; then | |
| if [[ "$additional_protos" != *"google/iam/v1/iam_policy.proto"* ]]; then | |
| buildozer 'remove deps //google/iam/v1:iam_policy_proto' "${path_to_build_file}:${PROTO_WITH_INFO_NAME}" 2>/dev/null || true | |
| fi | |
| if [[ "$additional_protos" != *"google/cloud/location/locations.proto"* ]]; then | |
| buildozer 'remove deps //google/cloud/location:location_proto' "${path_to_build_file}:${PROTO_WITH_INFO_NAME}" 2>/dev/null || true | |
| fi | |
| fi | |
| if [[ "$additional_protos" != *"google/iam/v1/iam_policy.proto"* ]]; then | |
| buildozer 'remove deps //google/iam/v1:iam_policy_proto' "${path_to_build_file}:%proto_library_with_info" 2>/dev/null || true | |
| fi | |
| if [[ "$additional_protos" != *"google/cloud/location/locations.proto"* ]]; then | |
| buildozer 'remove deps //google/cloud/location:location_proto' "${path_to_build_file}:%proto_library_with_info" 2>/dev/null || true | |
| fi |
Ensure
spring-cloud-generatoronly includesiam_policy.protoandlocations.protoinproto_library_with_infowhen they are configured underadditional_protosingoogle-cloud-java/librarian.yaml, preventing compilation failures in generated starters such asgoogle-cloud-binary-authorization-spring-starter.