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

Incremental compilation: getNewFiles inconsistent behavior on Linux vs Mac. #820

Closed
vnermolaev opened this issue Feb 1, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@vnermolaev
Copy link

Hi,

I and my colleagues develop a KSP-based processor that makes use of incremental compilation.
The logic is as follows:

class MyProcessor(
    private val environment: SymbolProcessorEnvironment
) : SymbolProcessor {
    var i = 0
   
    override fun process(resolver: Resolver): List<KSAnnotated> {
        println("[$i] Handling NEW: ${resolver.getNewFiles().joinToString { it.toString() }}")
        println("[$i] Handling ALL: ${resolver.getAllFiles().joinToString { it.toString() }}")
        i++

        resolver.getNewFiles()
            .forEachIndexed { idx, file ->  
                // logic approximately boils down to
                // if i == 0 generate new file with name `NewFile_idx.kt` 
            }
            
        return emptyList()
    }
}

If the snippet is run on Debian/Ubuntu, the following output is generated

[0] Handling NEW: File: MyFile.kt
[0] Handling ALL: File: MyFile.kt
[1] Handling NEW: File: NewFile_0.kt
[1] Handling ALL: File: MyFile.kt, File: NewFile_0.kt
[2] Handling NEW: 
[2] Handling ALL: File: MyFile.kt, File: NewFile_0.kt

If the snippet is run on Mac, the following output is generated

[0] Handling NEW: File: MyFile.kt
[0] Handling ALL: File: MyFile.kt
[1] Handling NEW: File: 
[1] Handling ALL: File: MyFile.kt, File: NewFile_0.kt

which is clearly inconsistent.

Any advices on what can trigger such a behavior?

@vnermolaev vnermolaev changed the title Incremental compilation: getNewFiles skips new files, getAllFiles picks all file correctly. Incremental compilation: getNewFiles inconsistent behavior on Linux vs Mac. Feb 1, 2022
@ting-yuan ting-yuan added the bug Something isn't working label Feb 16, 2022
@ting-yuan
Copy link
Collaborator

@vnermolaev Could you print the filePath of the files?

I suspect that this is a bug related to how KSP computes the set of new files. KSP tracks generated files in File.canonicalPath, but compares to PsiFile.virtualFilePath.

cc @neetopia

@ting-yuan
Copy link
Collaborator

@vnermolaev The possible fix is now available in the just released KSP 1.6.10-1.0.3. Hope that fixes this issue and if not, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants