Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codegen): modify generator scripts after separation of bazel rules #1351

Merged
merged 4 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion generator/download-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -

Expand All @@ -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 -

29 changes: 22 additions & 7 deletions generator/generate-one.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -77,7 +93,6 @@ else

fi


# remove downloaded repos
cd ../generator
if [[ $download_repos -eq 1 ]]; then
Expand Down