Kotlin / binary-compatibility-validator

Public API management tool
Apache License 2.0
821 stars 59 forks source link

BCV checks KLib ABIs under `build` dirs #261

Open Goooler opened 3 months ago

Goooler commented 3 months ago

Enable KLib ABI validation with the version 0.16.2 and dump KLib ABIs, apiCheck works on my local device but CI:

* What went wrong:
Execution failed for task ':compose-multiplatform:library:klibApiCheck'.
> API check failed for project library.

  --- /home/runner/work/Calendar/Calendar/compose-multiplatform/library/build/api/klib-all/extracted/library.klib.api
  +++ /home/runner/work/Calendar/Calendar/compose-multiplatform/library/build/api/klib/library.klib.api
  @@ -5,7 +5,7 @@
   // - Show manifest properties: true
   // - Show declarations: true

  -// Library unique name: <kizitonwose-calendar.compose-multiplatform:library>
  +// Library unique name: <Calendar.compose-multiplatform:library>
   final enum class com.kizitonwose.calendar.compose.heatmapcalendar/HeatMapWeekHeaderPosition : kotlin/Enum<com.kizitonwose.calendar.compose.heatmapcalendar/HeatMapWeekHeaderPosition> { // com.kizitonwose.calendar.compose.heatmapcalendar/HeatMapWeekHeaderPosition|null[0]
       enum entry End // com.kizitonwose.calendar.compose.heatmapcalendar/HeatMapWeekHeaderPosition.End|null[0]
       enum entry Start // com.kizitonwose.calendar.compose.heatmapcalendar/HeatMapWeekHeaderPosition.Start|null[0]
  @@ -364,6 +364,12 @@
       final fun toString(): kotlin/String // com.kizitonwose.calendar.data/WeekDateRange.toString|toString(){}[0]
   }

You can repro this issue at https://github.com/kizitonwose/Calendar/pull/566.

fzhinkin commented 3 months ago

@Goooler, the current klib-abi-validation pipeline extracts an ABI for supported targets from a file stored within the source's api-dir and writes a resulting file into build/api/klib-all/extracted/....

In your example, the first file is a file created by filtering out unsupported targets from an ABI file stored within project sources, and the second file is an ABI generated for the current revision:

  --- /home/runner/work/Calendar/Calendar/compose-multiplatform/library/build/api/klib-all/extracted/library.klib.api
  +++ /home/runner/work/Calendar/Calendar/compose-multiplatform/library/build/api/klib/library.klib.api

So there's nothing wrong in both files being stored in build dir.

The problem with the validation failing in CI seems to be caused by the rootProject.name property not being set in the kizitonwose/Calendar project. Unless the property set, Gradle will use the root directory name as a project name.

Goooler commented 3 months ago

Thanks! It works now.

Is this related to #257?

fzhinkin commented 3 months ago

Not sure, it should be just kizitonwose/Calendar’s misconfiguration. While #257 is a bug on BCV side

Goooler commented 3 months ago

rootProject.name is not necessary for every project, it's possible to cause this issue when we miss that.

fzhinkin commented 3 months ago

It's recommended to set rootProject.name as a name inferred from a directory name could be unstable (and the CI issue from the issue's summary is one example how lack of stability shows itself).

Goooler commented 3 months ago

Should we note this point in README?

Goooler commented 3 months ago

The failed tests from https://github.com/Kotlin/binary-compatibility-validator/pull/262#issuecomment-2247592185, they ref to the settings.gradle.kts already declare rootProject. See

https://github.com/Kotlin/binary-compatibility-validator/blob/18cd0df801cde896675b0a4b6fdf082e3eef33f7/src/functionalTest/resources/examples/gradle/settings/settings-name-testproject.gradle.kts#L1

fzhinkin commented 2 months ago

Should we note this point in README?

Yes, it definitely won't harm.

ShreyashKore commented 1 month ago

I'm facing same issue, and even adding rootProject.name didn't help. Can it be because my project's name and inner module's name is same?

* What went wrong:
Execution failed for task ':inspektor:jvmApiCheck'.
> API check failed for project inspektor.
  --- /Users/runner/work/inspektor/inspektor/inspektor/api/jvm/inspektor.api
  +++ /Users/runner/work/inspektor/inspektor/inspektor/build/api/jvm/inspektor.api

Failing Run: https://github.com/ShreyashKore/inspektor/actions/runs/11087059708/job/30805337163 Project: https://github.com/ShreyashKore/inspektor