Kotlin / binary-compatibility-validator

Public API management tool
Apache License 2.0
759 stars 55 forks source link

Klib validation failing on CI but not locally #199

Closed JakeWharton closed 3 months ago

JakeWharton commented 3 months ago
* What went wrong:  
Execution failed for task ':redwood-layout-modifiers:klibApiMerge'. 
> java.io.FileNotFoundException: File does not exist: /Users/runner/work/redwood/redwood/redwood-layout-modifiers/build/api/js/redwood-layout-modifiers.klib.api    

Attempt 1

Attempt 2

Attempt 3

I have not been able to reproduce this locally on my Mac. I tried executing the same command (after a clean) with --max-workers=3 to match the core count of the CI machine but it always succeeds (5 attempts).

I also don't know why it's always this specific module and the JS target that fails. I apply it to ~40 modules in this build, most of which are multiplatform containing JS targets. Very weird.

It's possible the problem can be identified just from looking at the code of the plugin, but I don't have time to do that right now. I can try investigating more later tonight or tomorrow, but figured I'd file the issue first.

fzhinkin commented 3 months ago

@JakeWharton thanks for reporting!

fzhinkin commented 3 months ago

There's nothing specific about JS target in this particular case, it just appears to be the first target to load a dump for merging. For API build tasks, we're skipping a task if there are no sources associated with it (and :redwood-layout-modifiers is indeed "empty"), but all other tasks are not skipped and thus fail.

JakeWharton commented 3 months ago

That module contains only generated sources, which are correctly picked up by the dump: https://github.com/cashapp/redwood/pull/1884/files#diff-01c56a8c31dca2ba8b0d2218624f995999da354e5ac75bc91877b5dbb6abd60c

The sources are produced by adding a Task to the source set here: https://github.com/cashapp/redwood/blob/0b99e1067cc61ee58b3560ac949bb83cba3bb506/redwood-gradle-plugin/src/main/kotlin/app/cash/redwood/gradle/RedwoodGeneratorPlugin.kt#L106-L107. Adding the task directly means Gradle will automatically run the task before anyone can consume the source set. The task's @OutputDirectory has the files which are then included in the source set.

JakeWharton commented 3 months ago

I tried adding the task to the source set as soon as possible (when the multiplatform plugin is applied), but it didn't change the outcome.

lukellmann commented 3 months ago

I get a similar exception on Windows for this project when klib validation is enabled here (by adding klib.enabled = true):

> Task :core:live-tests:klibApiMergeInferred FAILED                                                                                                                                                                                                                                                                           

FAILURE: Build failed with an exception.                                                                                                                                                                                                                                                                                      

* What went wrong:
Execution failed for task ':core:live-tests:klibApiMergeInferred'.
> java.io.FileNotFoundException: File does not exist: C:\...\kord\core\live-tests\build\api\js\live-tests.klib.api 

The relevant parts of the project layout look like this:

kord (root project, BCV plugin not applied)
|
+-- core (public api subproject, BCV plugin applied)
    |
    +-- live-tests (internal subproject, BCV plugin not applied)

It seems like BCV tries to find the .klib.api file for a subproject that won't ever create one because the BCV plugin isn't applied there.

The workaround I found is putting this into kord/core/build.gradle.kts:

apiValidation {
    ignoredProjects += "live-tests"
}