@@ -23,7 +23,10 @@ function print_service_textproto() {
2323 service_proto_path=" ${1# protos/ } "
2424 product_path=" ${service_proto_path%/* .proto} "
2525 initial_copyright_year=$( date +" %Y" )
26- cat << _EOF_
26+
27+ (
28+ sed -n ' /# update_discovery_doc.sh additions/q;p' " ${PROJECT_ROOT} /${GENERATOR_CONFIG_RELATIVE_PATH} "
29+ cat << _EOF_
2730 rest_services {
2831 service_proto_path: "${service_proto_path} "
2932 product_path: "${product_path} "
@@ -32,14 +35,17 @@ function print_service_textproto() {
3235 generate_rest_transport: true
3336 generate_grpc_transport: false
3437 }
38+
3539_EOF_
40+ sed -n ' /# update_discovery_doc.sh additions/,$p' " ${PROJECT_ROOT} /${GENERATOR_CONFIG_RELATIVE_PATH} "
41+ ) | sponge " ${PROJECT_ROOT} /${GENERATOR_CONFIG_RELATIVE_PATH} "
3642}
3743
3844function add_service_directory() {
3945 compute_proto_path=" ${1# protos/ google/ cloud/ compute/ } "
4046 service_dir=" ${compute_proto_path%/* .proto} /"
4147 echo " \" ${service_dir} \" "
42- sed -i -f - " ${PROJECT_ROOT} /google/cloud/compute/service_dirs.cmake " << EOT
48+ sed -i -f - " ${PROJECT_ROOT} /${COMPUTE_SERVICE_DIRS_CMAKE_RELATIVE_PATH} " << EOT
4349 /^set(service_dirs$/ {
4450 n # skip "cmake-format: sort" line
4551 a\ "${service_dir} "
5965
6066readonly COMPUTE_DISCOVERY_DOCUMENT_URL=" https://www.googleapis.com/discovery/v1/apis/compute/v1/rest"
6167readonly COMPUTE_DISCOVERY_JSON_RELATIVE_PATH=" generator/discovery/compute_public_google_rest_v1.json"
68+ readonly GENERATOR_CONFIG_RELATIVE_PATH=" generator/generator_config.textproto"
69+ readonly COMPUTE_SERVICE_DIRS_CMAKE_RELATIVE_PATH=" google/cloud/compute/service_dirs.cmake"
70+ readonly COMPUTE_SERVICE_DIRS_BZL_RELATIVE_PATH=" google/cloud/compute/service_dirs.bzl"
6271
6372io::log_h2 " Fetching discovery document from ${COMPUTE_DISCOVERY_DOCUMENT_URL} "
6473curl " ${COMPUTE_DISCOVERY_DOCUMENT_URL} " > " ${PROJECT_ROOT} /${COMPUTE_DISCOVERY_JSON_RELATIVE_PATH} "
@@ -69,24 +78,60 @@ readonly REVISION
6978io::run git checkout -B update_compute_discovery_circa_" ${REVISION} "
7079
7180io::log_h2 " Adding updated Discovery JSON ${COMPUTE_DISCOVERY_JSON_RELATIVE_PATH} "
72- git add " ${PROJECT_ROOT} /${COMPUTE_DISCOVERY_JSON_RELATIVE_PATH} "
81+ git commit -m" chore(compute): update discovery doc circa ${REVISION} " \
82+ " ${PROJECT_ROOT} /${COMPUTE_DISCOVERY_JSON_RELATIVE_PATH} "
7383
7484io::log_h2 " Running generate-libraries with UPDATED_DISCOVERY_DOCUMENT=compute"
7585UPDATED_DISCOVERY_DOCUMENT=compute ci/cloudbuild/build.sh -t generate-libraries-pr
7686
87+ io::log_h2 " Adding new compute internal protos"
88+ git add " ${PROJECT_ROOT} /protos/google/cloud/compute/v1/internal"
89+
7790NEW_FILES=$( git ls-files --others --exclude-standard protos/)
7891if [[ -n " ${NEW_FILES} " ]]; then
92+ git add protos/google/cloud/compute
93+
94+ io::log_h2 " Formatting generated protos"
95+ git ls-files -z -- ' *.proto' |
96+ xargs -P " $( nproc) " -n 50 -0 clang-format -i
97+ git ls-files -z -- ' *.proto' |
98+ xargs -r -P " $( nproc) " -n 50 -0 sed -i ' s/[[:blank:]]\+$//'
99+
79100 io::log_red " New resources defined in Discovery Document created new protos:"
80101 echo " ${NEW_FILES} "
81102 mapfile -t proto_array < <( echo " ${NEW_FILES} " )
82- io::log_red " Add rest_services definitions to the generator_config.textproto and re-run this script ."
103+ io::log_red " Adding rest_services definitions to the generator_config.textproto."
83104 for i in " ${proto_array[@]} " ; do
105+ echo " ${i} "
84106 print_service_textproto " ${i} "
85107 done
86- git add protos
87- io::log_yellow " Adding new directories to google/cloud/compute/service_dirs.cmake"
108+ fi
109+
110+ io::log_h2 " Running generate-libraries with updated generator_config.textproto"
111+ ci/cloudbuild/build.sh -t generate-libraries-pr || true
112+
113+ if [[ -n " ${NEW_FILES} " ]]; then
114+ io::log_h2 " Adding new compute generated service code"
115+ git add google/cloud/compute
116+
117+ io::log_h2 " Formatting generated code"
118+ git ls-files -z -- ' *.h' ' *.cc' |
119+ xargs -P " $( nproc) " -n 50 -0 clang-format -i
120+ git ls-files -z -- ' *.h' ' *.cc' |
121+ xargs -r -P " $( nproc) " -n 50 -0 sed -i ' s/[[:blank:]]\+$//'
122+
123+ io::log_yellow " Adding new directories to ${COMPUTE_SERVICE_DIRS_CMAKE_RELATIVE_PATH} "
88124 for i in " ${proto_array[@]} " ; do
89125 add_service_directory " ${i} "
90126 done
91- exit 1
127+
128+ io::log_yellow " Adding new directories to ${COMPUTE_SERVICE_DIRS_BZL_RELATIVE_PATH} "
129+ cmake -DGOOGLE_CLOUD_CPP_ENABLE=compute -S . -B ./cmake-build-debug
130+
131+ git commit -m" Update generator_config.textproto and service_dirs files" \
132+ " ${PROJECT_ROOT} /${GENERATOR_CONFIG_RELATIVE_PATH} " \
133+ " ${PROJECT_ROOT} /${COMPUTE_SERVICE_DIRS_CMAKE_RELATIVE_PATH} " \
134+ " ${PROJECT_ROOT} /${COMPUTE_SERVICE_DIRS_BZL_RELATIVE_PATH} "
92135fi
136+
137+ git commit -m" Update generated code" .
0 commit comments