Slackbot
01/15/2024, 4:13 PMAdam
01/15/2024, 4:29 PM/full/path/to/my-project
with a subproject
/full/path/to/my-project/subproject-x/
that has a task that creates an output file
/full/path/to/my-project/subproject-x/build/foo/output.txt
then RELATIVE will relativise it to be build/foo/output.txtMartin
01/15/2024, 4:30 PM~/java , 2 builds in 2 different directories won't be able to share their build cache?Martin
01/15/2024, 4:31 PM$HOME/java # <- sources
$HOME/project
$HOME/otherDir/cloneOfProjectMartin
01/15/2024, 4:32 PMconfigurableFileCollection.from("$HOME/java") , I think I'd expect the normalization to work relative to "$HOME/java" , irrespective of my checkout folderAdam
01/15/2024, 4:32 PM~/java and then added that to your CFCAdam
01/15/2024, 4:33 PM~/javaMartin
01/15/2024, 4:33 PMconfigurableFileCollection.from("$HOME/java")
configurableFileCollection.from("$HOME/java/dir/Foo.java")
Is it going to throw?Martin
01/15/2024, 4:34 PMconfigurableFileCollection from multiple FileTree , it'd be quite the limitation otherwiseAdam
01/15/2024, 4:35 PMMartin
01/15/2024, 4:35 PMconfigurableFileCollection.from("$HOME/java")
configurableFileCollection.from("$HOME/java/dir/Foo.java")Adam
01/15/2024, 4:36 PM~/java and the file
(assuming you're setting the home dir manually because I don't think $HOME works in Java)Adam
01/15/2024, 4:37 PMMartin
01/15/2024, 4:38 PMI think your code would add both the dirSo it's going to compile myand the file~/java
Foo.java file twice? Maybe... I can tryAdam
01/15/2024, 4:39 PMMartin
01/15/2024, 4:40 PMMartin
01/15/2024, 4:40 PMFoo.java is now reachable via 2 rootsAdam
01/15/2024, 4:40 PMconfigurableFileCollection.from("$HOME/java") will add Foo.java and then the second operation will 'overwrite' the first with the secondMartin
01/15/2024, 4:40 PMMartin
01/15/2024, 4:40 PMAdam
01/15/2024, 4:41 PMMartin
01/15/2024, 4:42 PMThe property is an input directory.
* The path of the files in the input directory are considered relative to the input directory.
I guess my question is: what if the property is a ConfigurableFileCollectionAdam
01/15/2024, 4:43 PMAdam
01/15/2024, 4:43 PMMartin
01/15/2024, 4:43 PMBut that's unrelated to how files get added into a CFCI don't think it is because I would expect the normalised path to be the relative path inside the CFC.
Martin
01/15/2024, 4:44 PMproject.rootDir but I'd find this quite surprisingAdam
01/15/2024, 4:46 PMMartin
01/15/2024, 4:48 PM@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val files: ConfigurableFileCollectionAdam
01/15/2024, 4:52 PM/full/path/java/
/full/path/java/Z.Java
Then you'll have a CFC that contains some files:
/full/path/java/some/package/X.Java
/full/path/java/some/other/package/Y.Java
/full/path/java/Z.Java
And then when the task run Gradle tries to fingerpint the task inputs. Gradle knows which subproject owns the task, so it knows the project directory. And Gradle can also see the pathsensitivity setting. So it will get all the files in the CFC, and if the path sensitive is RELATIVE then it will be something like this.
../../../java/some/package/X.Java
../../../java/some/other/package/Y.Java
../../../java/Z.Java
Then it will hash the paths (and the file contents) to get the fingerprintAdam
01/15/2024, 4:54 PMMartin
01/15/2024, 4:54 PMif the path sensitive is RELATIVE then it will be something like thisFair assumption. My issue if it works like this is that if I clone my repo in a subdir, the normalized paths will now become (notice the extra
../ )
../../../../java/some/package/X.Java
../../../../java/some/other/package/Y.Java
../../../../java/Z.Java
And my build cache doesn't work any moreAdam
01/15/2024, 4:55 PMMartin
01/15/2024, 4:56 PMAdam
01/15/2024, 5:00 PMobjects.fileTree().apply {
this.setDir("$HOME/java")
}
and add it to the CFC then Gradle will be cleverer - but I suspect it will just treat the FileTree as a list of java.io.Files and you'll have the same problem - the CFC will contain a lot of files (with absolute paths dependent on the project location) that will later be normalized.
Maybe if you have a DirectoryProperty as a task input then Gradle will normalize the files contained in the dir relative to the provided dir? (Similar for a ConfigurableFileTree).
Pure guesses. I have no idea what will actually work. I'm curious what you find!Martin
01/15/2024, 5:12 PMAdam
01/15/2024, 5:14 PMMartin
01/15/2024, 5:16 PMMartin
01/15/2024, 5:16 PMMartin
01/15/2024, 5:17 PMcfc.from("/Users/mbonnin/tmp/sub/b.java")
cfc.from("/Users/mbonnin/tmp2/b.java")
I can also share the build cache so looks like the normalized path is "b.java" for both and Gradle is smart enough to know that order doesn't matterMartin
01/15/2024, 5:17 PMMartin
01/15/2024, 5:22 PMMartin
01/15/2024, 5:36 PMval ft = objects.fileTree().from("/Users/mbonnin/tmp")
cfc.from(ft)
cfc.from("/Users/mbonnin/tmp/sub/b.java")Martin
01/15/2024, 5:37 PMAdam
01/15/2024, 5:55 PM~/java/ anywhere on the filesystem - the relative paths would still all be the same relative to the new location of <...>/java/.Martin
01/25/2024, 1:38 PMFileCollection contains FileTrees and the roots of those FileTrees are used for normalization. Alas I haven't found a way to access those roots using only public API