-
Notifications
You must be signed in to change notification settings - Fork 274
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
Use Relative Sensitivity for GenerateProtoTask, use name only sensitivity for classpath. #293
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ | |
package com.google.protobuf.gradle | ||
|
||
import com.google.common.collect.ImmutableList | ||
|
||
import org.gradle.api.Action | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Plugin | ||
|
@@ -42,6 +41,7 @@ import org.gradle.api.file.SourceDirectorySet | |
import org.gradle.api.internal.file.FileResolver | ||
import org.gradle.api.logging.LogLevel | ||
import org.gradle.api.plugins.AppliedPlugin | ||
import org.gradle.api.tasks.PathSensitivity | ||
import org.gradle.api.tasks.SourceSet | ||
|
||
import javax.inject.Inject | ||
|
@@ -329,7 +329,8 @@ class ProtobufPlugin implements Plugin<Project> { | |
task = project.tasks.create(extractProtosTaskName, ProtobufExtract) { | ||
description = "Extracts proto files/dependencies specified by 'protobuf' configuration" | ||
destDir = getExtractedProtosDir(sourceSetName) as File | ||
inputs.files project.configurations[Utils.getConfigName(sourceSetName, 'protobuf')] | ||
inputs.files(project.configurations[Utils.getConfigName(sourceSetName, 'protobuf')]) | ||
.withPathSensitivity(PathSensitivity.RELATIVE) | ||
isTest = Utils.isTest(sourceSetName) | ||
} | ||
} | ||
|
@@ -359,6 +360,7 @@ class ProtobufPlugin implements Plugin<Project> { | |
destDir = getExtractedIncludeProtosDir(sourceSetOrVariantName) as File | ||
inputs.files (compileClasspathConfiguration | ||
?: project.configurations[Utils.getConfigName(sourceSetOrVariantName, 'compile')]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this still be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was changed a long time ago in #366 |
||
.withPathSensitivity(PathSensitivity.NAME_ONLY) | ||
|
||
// TL; DR: Make protos in 'test' sourceSet able to import protos from the 'main' | ||
// sourceSet. Sub-configurations, e.g., 'testCompile' that extends 'compile', don't | ||
|
@@ -379,7 +381,8 @@ class ProtobufPlugin implements Plugin<Project> { | |
// 'resources' of the output of 'main', in which the source protos are placed. This is | ||
// nicer than the ad-hoc solution that Android has, because it works for any extended | ||
// configuration, not just 'testCompile'. | ||
inputs.files getSourceSets()[sourceSetOrVariantName].compileClasspath | ||
inputs.files (getSourceSets()[sourceSetOrVariantName].compileClasspath) | ||
.withPathSensitivity(PathSensitivity.NAME_ONLY) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this would also be necessary in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's actually a lot more places this could possibly be added in |
||
} | ||
isTest = Utils.isTest(sourceSetOrVariantName) | ||
} | ||
|
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 from configuration and presumably also need to be "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.
Honestly, I'm not too familiar with the
protobuf
configuration. I don't think its a general statement that anything from a "cofiguration" should be name only.The other
NAME_ONLY
in thesetupExtractIncludeProtosTask
was the classpath for the compile dependency which means essentially maven jars. These jars may be located in different local maven caches.On the other hand some configurations may have Kotlin files which require
RELATIVE
sensitivity but Java files requireNAME_ONLY
sensitivity because the java compiler ignores the files path and only looks at the package name.Anyways, I changed this to be
NAME_ONLY
sensitivity. Let me know if there are any other changes I can make.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 don't think I fully understand how the files from dependencies are considered by the cache. Take a jar file from
compile
configuration for example, is the jar as a single file or the individual class files from it considered as the input?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 believe a jar from the compile configuration would be taken as a single file and should be considered
NAME_ONLY
so I guess in this caseNAME_ONLY
is correct.I wasn't sure if the compile configuration also included java/kotlin source files. If it doesn't then this is correct.
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.
Sounds reasonable. Do you know how the Gradle cache check if a directory (just a path, not a file tree) is up-to-date? We currently support such usage for the
protobuf
configuration (#294)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 believe the PathSensitivity works in a similar way whether a FileTree or a Directory are passed to a tasks inputs. The PathSensitivity only applies to the path of the FileTree or the Directory. It doesn't change how the contents of either are cached.
Here is some more information on task relocatability:
https://guides.gradle.org/using-build-cache/#relocatability