-
Notifications
You must be signed in to change notification settings - Fork 276
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 input and output annotations #351
Conversation
@@ -345,13 +386,12 @@ public class GenerateProtoTask extends DefaultTask { | |||
public void addSourceFiles(FileCollection files) { | |||
checkCanConfig() | |||
sourceFiles.from(files) | |||
// Register the files as input so that Gradle will check their changes for incremental build | |||
inputs.files(files).withPathSensitivity(PathSensitivity.RELATIVE) |
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.
What's the reason for these deletions?
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.
They are now captured by these annotations instead:
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.
To clarify: Gradle queries the annotated getters automatically before running the task to determine up-to-dateness and cache key.
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 changes are a good first step! I added some comments, my main concern is about backwards compatibility of registering files for ProtobufExtract
. If that isn't an issue, then the PR is good as it is.
src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy
Outdated
Show resolved
Hide resolved
public boolean getIsTest() { | ||
Preconditions.checkNotNull(isTest) | ||
return isTest | ||
} | ||
|
||
@InputFiles | ||
@PathSensitive(PathSensitivity.NAME_ONLY) |
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 am not sure about the NAME_ONLY
. Are you should or is RELATIVE
safer?
It seems like the task is copying/extracing from the input files. Maybe it should have a copy-spec instead of plain input files instead?
It also seems like archives can be part of the inputFiles.
For now, using NAME_ONLY
does not change the behavior, since that is what the plugin declared before.
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.
Exactly. Let's not change behavior where we don't have to for 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.
Please add a TODO here to revisit the correctness of PathSensitivity.
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.
Added.
Looking forward to having the protobuf plugin leverage all the new features of Gradle 5+. A good next step will be to make task configuration avoidance work because the plugin in its current form doesn't leverage that at all. |
Thank you for this PR! Will be nice to get the protobuf plugin more aligned with Gradle best practices 👍 |
@wolfs please take another look! |
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.
LGTM!
Hi, can someone from the Protobuf team take a look at this please? |
Also #304 is relevant |
Hi @zhangkun83 , any chance you could look at this PR? also #304 would be nice as we have seen this plugin creating several tasks in configuration phase that might not be needed unless the user intent is to run the proto tasks |
@@ -86,6 +99,7 @@ public class GenerateProtoTask extends DefaultTask { | |||
* | |||
* Default: false | |||
*/ | |||
@Internal |
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.
"Attached to a task property to indicate that the property is not to be taken into account for up-to-date checking."
It probably should be taken into account for up-to-date checking.
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 added a clarifying comment.
@Optional | ||
@Nested | ||
DescriptorSetOptions getDescriptorSetOptions() { | ||
return generateDescriptorSet ? descriptorSetOptions : null |
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.
If generateDescriptorSet == false
and this property is accessed, throwing an exception explaining what went wrong would be more helpful.
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've made this method protected
as well and added a comment.
} | ||
|
||
@Nested | ||
protected Collection<PluginOptions> getPluginsInternal() { |
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 suppose these two getters for exposing the two containers as properties so that they can be validated, since there public equivalents cannot be called after configuration is finished. A comment to explain that would be helpful.
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 added clarifying comments to both the methods and to the @Internal
annotations.
public boolean getIsTest() { | ||
Preconditions.checkNotNull(isTest) | ||
return isTest | ||
} | ||
|
||
@InputFiles | ||
@PathSensitive(PathSensitivity.NAME_ONLY) |
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.
Please add a TODO here to revisit the correctness of PathSensitivity.
@zhangkun83 Do you want me to do anything else before this can be merged? |
*/ | ||
@Optional | ||
@Nested | ||
protected DescriptorSetOptions getDescriptorSetOptions() { |
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.
Why is it not to be called directly? This is the public accessor for DescriptorSetOptions used in the example from README.
It seems that you cannot make it throw when generateDescriptorSet == false
as I requested earlier, because Gradle will query this property unconditionally. This is a bit unfortunate as Gradle doesn't have an annotation for "this is public, but don't use it for up-to-date checks".
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'm not sure what you mean by throw when generateDescriptorSet == false
. I reverted to the origin public property being @Internal
(that's Gradle's annotation for "this is public, but don't use it for up-to-date checks").
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.
If we made accessing descriptorSetOptions
throw when generateDescriptorSet == false
, the user would get more meaningful error message (see getDescriptorPath()
), compared to getting null
for descriptorSetOptions
and then NPE down the road.
I find @Internal
on a public property to be confusing, especially when you add the auxiliary properties like getDescriptorSetOptionsInternal()
that also have "Internal" in the name. Can you rename them to *ForUpToDateCheck()
?
Hi @zhangkun83! The problem I'd like to address here is that the Protobuf plugin in its currently released form does not declare inputs and outputs for the tasks it creates correctly. I don't want to pressure you into any particular way wrt handling errors etc. Yet we seem to be locked in a cycle of you trying to explain to me how you want things to be which I then implement not to your liking. Considering the long round-trip times I feel this is not leading to the desired results. Why don't we change this around, so you could add the annotations in a separate PR, and I can help review it? What matters for me is to wrap this up in a timely manner, so the many Gradle users that currently have issues with the plugin can be helped. I'd like to invite you to the Gradle Community Slack workspace. Given the popularity of your plugin, it would be great if we had a more direct connection. Once we fixed the input/output handling there are other improvements that we'd like to discuss, too. Would you mind sending me your email address to [email protected] so that I can send an invite? I'd also like to offer help face-to-face if that would work for you. I'm in the CET timezone, we can chat on Google Hangout or somesuch if you want. |
With Gradle 6.0 we are starting to enforce annotations on all task getters. Non ad-hoc tasks should use annotations in place of the `Task.getInputs()` and `getOutputs()` APIs. Due to these changes with Gradle 6.0 the applying the Protobuf plugin results in the following deprecation warnings being displayed: ```text > Warning: Type 'GenerateProtoTask': property 'buildType' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'builtins' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'descriptorPath' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'descriptorSetOptions' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'fileResolver' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'flavors' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'generateDescriptorSet' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'isTest' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'isTestVariant' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'outputSourceDirectorySet' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'plugins' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'sourceFiles' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'sourceSet' is not annotated with an input or output annotation. > Warning: Type 'GenerateProtoTask': property 'variant' is not annotated with an input or output annotation. > Warning: Type 'ProtobufExtract': property 'destDir' is not annotated with an input or output annotation. > Warning: Type 'ProtobufExtract': property 'isTest' is not annotated with an input or output annotation. ``` This PR fixes the problems and the warnings are removed. This is based on #351 by @lptr
This has been taken care of via #364. |
With Gradle 6.0 we are starting to enforce annotations on all task getters. Non ad-hoc tasks should use annotations in place of the
Task.getInputs()
andgetOutputs()
APIs. Due to these changes with Gradle 6.0 the applying the Protobuf plugin results in the following deprecation warnings being displayed:This PR fixes the problems and the warnings are removed.
I tried to figure out the role of each property as best I could based on the code alone, but I'm not sure I got everything right.