diff --git a/generator/download-repos.sh b/generator/download-repos.sh index 15519aa60c..f8e4a62c13 100644 --- a/generator/download-repos.sh +++ b/generator/download-repos.sh @@ -9,7 +9,7 @@ git clone https://github.com/googleapis/googleapis.git git clone https://github.com/googleapis/gapic-generator-java.git # get into gapic and checkout branch to use cd gapic-generator-java -git checkout c51d51bc495ea1284087b66c369dedf741dd4824 +git checkout autoconfig-gen-draft2 # go back to previous folder cd - @@ -29,5 +29,9 @@ perl -0777 -pi -e "s/http_archive\(\n name \= \"gapic_generator_java\"(.*?)\) # replace with googleapis-dep-string.txt which adds spring dependencies perl -0777 -pi -e "s{maven_install\(\n(.*?)artifacts = PROTOBUF_MAVEN_ARTIFACTS(.*?)\)}{$(cat ../googleapis-dep-string.txt)}s" WORKSPACE +# In googleapis/repository_rules.bzl, add switch for new spring rule +JAVA_SPRING_SWITCH=" rules[\\\"java_gapic_spring_library\\\"] = _switch(\n java and grpc and gapic,\n \\\"\@gapic_generator_java\/\/rules_java_gapic:java_gapic_spring.bzl\\\",\n )" +perl -0777 -pi -e "s/(rules\[\"java_gapic_library\"\] \= _switch\((.*?)\))/\$1\n$JAVA_SPRING_SWITCH/s" repository_rules.bzl + cd - diff --git a/generator/generate-one.sh b/generator/generate-one.sh index 80c8f55958..5321c48e6a 100755 --- a/generator/generate-one.sh +++ b/generator/generate-one.sh @@ -5,7 +5,7 @@ # note about space consumption: out-of-space testing on cloud shell instance. # poc with one specified repo - vision -#cmd line:: ./generate-one.sh -c vision -v 3.1.2 -i google-cloud-vision -g com.google.cloud +#cmd line:: ./generate-one.sh -c vision -v 3.1.2 -i google-cloud-vision -g com.google.cloud -d 1 # by default, do not download repos download_repos=0 @@ -39,20 +39,36 @@ if [[ $download_repos -eq 1 ]]; then bash download-repos.sh fi -# call bazel target - todo: separate target in future cd googleapis -bazel build //google/cloud/$client_lib_name/v1:"$client_lib_name"_java_gapic + +# Modify BUILD.bazel file for library +# Additional rule to load +SPRING_RULE_NAME=" \\\"java_gapic_spring_library\\\"," +perl -0777 -pi -e "s/(load\((.*?)\"java_gapic_library\",)/\$1\n$SPRING_RULE_NAME/s" google/cloud/$client_lib_name/v1/BUILD.bazel +# Duplicate java_gapic_library rule definition +perl -0777 -pi -e "s/(java_gapic_library\((.*?)\))/\$1\n\n\$1/s" google/cloud/$client_lib_name/v1/BUILD.bazel +# Update rule name to java_gapic_spring_library +perl -0777 -pi -e "s/(java_gapic_library\()/java_gapic_spring_library\(/s" google/cloud/$client_lib_name/v1/BUILD.bazel +# Update name argument to have _spring appended +perl -0777 -pi -e "s/(java_gapic_spring_library\((.*?)name = \"(.*?)\")/java_gapic_spring_library\(\$2name = \"\$3_spring\"/s" google/cloud/$client_lib_name/v1/BUILD.bazel +# todo: better way to remove the following unused arguments? +perl -0777 -pi -e "s/(java_gapic_spring_library\((.*?)(\n test_deps = \[(.*?)\],))/java_gapic_spring_library\(\$2/s" google/cloud/$client_lib_name/v1/BUILD.bazel +perl -0777 -pi -e "s/(java_gapic_spring_library\((.*?)(\n deps = \[(.*?)\],))/java_gapic_spring_library\(\$2/s" google/cloud/$client_lib_name/v1/BUILD.bazel +perl -0777 -pi -e "s/(java_gapic_spring_library\((.*?)(\n rest_numeric_enums = (.*?),))/java_gapic_spring_library\(\$2/s" google/cloud/$client_lib_name/v1/BUILD.bazel + +# call bazel target +bazel build //google/cloud/$client_lib_name/v1:"$client_lib_name"_java_gapic_spring cd - ## copy spring code to outside mkdir -p ../generated -cp googleapis/bazel-bin/google/cloud/$client_lib_name/v1/"$client_lib_name"_java_gapic_srcjar-spring.srcjar ../generated +cp googleapis/bazel-bin/google/cloud/$client_lib_name/v1/"$client_lib_name"_java_gapic_spring-spring.srcjar ../generated # unzip spring code cd ../generated -unzip -o "$client_lib_name"_java_gapic_srcjar-spring.srcjar -d "$client_lib_name"/ -rm -rf "$client_lib_name"_java_gapic_srcjar-spring.srcjar +unzip -o "$client_lib_name"_java_gapic_spring-spring.srcjar -d "$client_lib_name"/ +rm -rf "$client_lib_name"_java_gapic_spring-spring.srcjar # override versions & names in pom.xml cat "$client_lib_name"/pom.xml @@ -77,7 +93,6 @@ else fi - # remove downloaded repos cd ../generator if [[ $download_repos -eq 1 ]]; then