-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat: dynamically determine protobuf version in build.gradle #1753
Conversation
Can you add how you tested this in the pull request description? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you check whether the protobuf version line canbe removed?
gax-java/dependencies.properties
Outdated
@@ -23,7 +23,7 @@ version.gax_httpjson=0.114.1-SNAPSHOT | |||
# Versions for dependencies which actual artifacts differ between Bazel and Gradle. | |||
# Gradle build depends on prebuilt maven artifacts, while Bazel build depends on Bazel workspaces | |||
# with the sources. | |||
version.com_google_protobuf=3.23.2 | |||
version.com_google_protobuf=3.21.12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this used now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can't be removed because
_protobuf_version = PROPERTIES["version.com_google_protobuf"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course the next question is the purpose of that line. Who calls com_google_api_gax_java_repositories()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
com_google_api_gax_java_repositories()
is called from googleapis/WORKSPACE and gax-java/WORKSPACE.
The protobuf version can be passed from googleapis when building client libraries. However, when running showcase tests, it will create a cycle in WORKSPACE if this line (version.com_google_protobuf=3.21.12
) is removed.
Please see #1753 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add source code comment. It's used for showcase testing. Not for the generated Gradle file in googleapis project any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
gax-java/repository_rules.bzl
Outdated
# the version of protobuf defined in googleapis is higher than protobuf | ||
# defined in gax-java/dependencies.properties, use this replacement to | ||
# sync the two versions. | ||
props_as_map["version.com_google_protobuf"] = PROTOBUF_JAVA_VERSION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inject a key-value pair here, rather than in rules_java_gapic/java_gapic_pkg.bzl.
By doing this, we can remove protobuf version in gax-java/dependencies.properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a cycle in gax-java/WORKSPACE:
(18:15:51) ERROR: Failed to load Starlark extension '@com_google_protobuf//:protobuf_version.bzl'.
Cycle in the workspace file detected. This indicates that a repository is used prior to being defined.
The following chain of repository dependencies lead to the missing definition.
- @com_google_protobuf
This could either mean you have to add the '@com_google_protobuf' repository with a statement like `http_archive` in your WORKSPACE file (note that transitive dependencies are not added automatically), or move an existing definition earlier in your WORKSPACE file.
Full log: https://github.com/googleapis/sdk-platform-java/actions/runs/5203236910/jobs/9385816289?pr=1753
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting.
This reverts commit 22d3d0c.
rules_java_gapic/java_gapic_pkg.bzl
Outdated
|
||
def _wrapPropertyNamesInBraces(properties): | ||
wrappedProperties = {} | ||
for k, v in properties.items(): | ||
wrappedProperties["{{%s}}" % k] = v | ||
return wrappedProperties | ||
|
||
_PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES) | ||
_PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES | _syncVersionWithGoogleapis()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES | _syncVersionWithGoogleapis()) | |
# Before this replacement, there is a problem (e.g., b/284292352) when ... | |
PROPERTIES["version.com_google_protobuf"] = PROTOBUF_JAVA_VERSION | |
_PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually won't work as it will violate mutability rule.
ERROR: Traceback (most recent call last):
File "/private/var/tmp/_bazel_joewa/b6b64da05090260654456c80e641ce7c/external/gapic_generator_java/rules_java_gapic/java_gapic_pkg.bzl", line 28, column 43, in <toplevel>
PROPERTIES["version.com_google_protobuf"] = PROTOBUF_JAVA_VERSION
Error: trying to mutate a frozen dict value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice learning. Then create a copy or operate on _PROPERTIES. The latter needs to tweak the key with braces.
# the version of protobuf defined in googleapis is higher than protobuf | ||
# defined in gax-java/dependencies.properties, use this replacement to | ||
# sync the two versions. | ||
SYNCED_PROPERTIES = PROPERTIES | {"version.com_google_protobuf": PROTOBUF_JAVA_VERSION} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suztomo is this the idea of "making a copy"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better than what I was thinking with "dict.copy()".
rules_java_gapic/java_gapic_pkg.bzl
Outdated
|
||
def _wrapPropertyNamesInBraces(properties): | ||
wrappedProperties = {} | ||
for k, v in properties.items(): | ||
wrappedProperties["{{%s}}" % k] = v | ||
return wrappedProperties | ||
|
||
_PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES) | ||
# Before this replacement, there is a problem (e.g., b/284292352) when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Before this replacement, there is a problem (e.g., b/284292352) when | |
# Before this replacement, there was a problem (e.g., b/284292352) when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -23,6 +23,8 @@ version.gax_httpjson=0.114.1-SNAPSHOT | |||
# Versions for dependencies which actual artifacts differ between Bazel and Gradle. | |||
# Gradle build depends on prebuilt maven artifacts, while Bazel build depends on Bazel workspaces | |||
# with the sources. | |||
# The protobuf version is only used by showcase tests, not used by gradle files | |||
# in generated, self-service clients (from googleapis project). | |||
version.com_google_protobuf=3.23.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used by showcase? I think the protobuf runtime version in Showcase module extends from gapic-generator-java-parent-pom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong.
Looking at the ci error log, showcase golden tests eventually invoke bazelisk run //showcase:verify_gapic
.
bazelisk run //showcase:verify_gapic
will fail if version.com_google_protobuf=3.23.2
is removed from dependencies.properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I didn't notice that we are making sure showcase modules are compilable right after generation, they are still verified with the generated gradle files though.
gax-java/dependencies.properties
Outdated
# The protobuf version is only used by showcase tests, not used by gradle files | ||
# in generated, self-service clients (from googleapis project). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# The protobuf version is only used by showcase tests, not used by gradle files | |
# in generated, self-service clients (from googleapis project). | |
# The protobuf version is only used for generating gradle files for showcase module, | |
# not for self-service clients (from googleapis project). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed! |
[java_showcase_integration_tests] Kudos, SonarCloud Quality Gate passed! |
[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed! |
Fixes #1757.
Steps to verify this PR:
google-maps-fleetengine
./path/sdkplatform-java
.googleapis
repository, runbazelisk build
to build the client library withgapic-generator-java
andgax-java
replaced with local repository.For example,
bazelisk build //google/maps/fleetengine/v1:google-maps-fleetengine-v1-java --override_repository=gapic_generator_java=/path/sdk-platform-java/ --override_repository=com_google_api_gax_java=/path/sdk-platform-java/gax-java/
googleapis
repository, unzip the generated tar file togoogleapis
root directory.For example,
tar -xf bazel-bin/google/maps/fleetengine/v1/google-maps-fleetengine-v1-java.tar.gz
com.google.protobuf:protobuf-java
inproto-*/build.gradle
and make sure the version is the same as protobuf version defined inWORKSPACE
ingooleapis
.google-maps-fleetengine-v1-java/
), and run./gradlew build
.