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

[Configuration cache] Filtered FC with mapped elements stored incorrectly #17542

Closed
gavra0 opened this issue Jun 25, 2021 · 2 comments · Fixed by #17590
Closed

[Configuration cache] Filtered FC with mapped elements stored incorrectly #17542

gavra0 opened this issue Jun 25, 2021 · 2 comments · Fixed by #17590
Assignees
Milestone

Comments

@gavra0
Copy link
Contributor

gavra0 commented Jun 25, 2021

Using this snippet:

abstract class Producer extends DefaultTask {
    @OutputDirectory
    abstract DirectoryProperty getOutputClasses()

    @TaskAction
    void doStuff() {
        File f = getOutputClasses().get().asFile
        f.mkdirs()

        new File(f, "some.txt") << "some text"
    }
}

TaskProvider<Producer> prod = tasks.register("prod", Producer.class) {
    it.getOutputClasses().set(new File(project.buildDir, "producerOutput"))
}

abstract class MyTask extends DefaultTask {
    @Classpath
    abstract ConfigurableFileCollection getClasses()

    @TaskAction
    void doStuff() {
        println getClasses().files
    }
}

Provider<List<Directory>> getDirectories(FileCollection fc, Directory projectDir) {
    fc.filter { File f ->
        f.isDirectory()
    }.elements.map {
        it.collect { fileSystemLocation ->
            projectDir.dir(fileSystemLocation.asFile.absolutePath)
        }
    }
}

FileCollection myFc = project.files(prod.map { it.getOutputClasses() })

tasks.register("myTask", MyTask.class) {
    it.getClasses().from(
            project.files(
                    getDirectories(myFc, project.layout.buildDirectory.get())
            )
    )
}

and running rm -rf .gradle/configuration-cache build && gw myTask --configuration-cache && gw myTask --configuration-cache shows that in the second run task prints nothing i.e getClasses() returns an empty file collection.

It is interested that if method getDirectories is changed to

Provider<List<Directory>> getDirectories(FileCollection fc, Directory projectDir) {
    fc.elements.map {
        it.findAll { FileSystemLocation fsl ->
            fsl.asFile.isDirectory()
        }.collect { fileSystemLocation ->
            projectDir.dir(fileSystemLocation.asFile.absolutePath)
        }
    }
}

this issue is fixed. However, in AGP something triggers it.findAll to run during configuration cache storing, causing the issue.

@eskatos
Copy link
Member

eskatos commented Jun 25, 2021

Build scan of failing smoke tests with Santa Tracker and upgraded AGP with change revealing the issue
https://ge.gradle.org/s/lsihvi4oh5noi/tests/failed

@eskatos
Copy link
Member

eskatos commented Jul 1, 2021

Fixed in #17578

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants