Skip to content

Commit

Permalink
Add binary-compatibility-validator and API dumps for desktop (#803)
Browse files Browse the repository at this point in the history
https://github.com/Kotlin/binary-compatibility-validator

This plugin dumps all API for JVM modules to files (in the future - for
other targets). If API changed, we should call:
```
./gradlew desktopApiDump
```
to commit a new API, otherwise CI will fail (`./gradlew desktopCICheck`
will be called on CI`).

If you see that some strings are deleted in the API dump, most probably
it means an incompatible API change (the plugin doesn't check itself,
unfortunately).

See [the official workflow
guide](https://github.com/Kotlin/binary-compatibility-validator#workflow)
to understand it more.

Example of error:
```
Execution failed for task ':compose:material3:material3:desktopApiCheck'.
> API check failed for project material3.
  --- D:\Work\compose-multiplatform-core\compose\material3\material3\api\desktop\material3.api
  +++ D:\Work\compose-multiplatform-core\out\androidx\compose\material3\material3\build\api\desktop\material3.api
  @@ -552,6 +552,11 @@
   public abstract interface annotation class androidx/compose/material3/ExperimentalMaterial3Api : java/lang/annotation/Annotation {
   }

  +public final class androidx/compose/material3/FF {
  +     public static final field $stable I
  +     public fun <init> ()V
  +}
  +
   public final class androidx/compose/material3/FabPosition {
        public static final field Companion Landroidx/compose/material3/FabPosition$Companion;
        public static final synthetic fun box-impl (I)Landroidx/compose/material3/FabPosition;

   You can run :material3:apiDump task to overwrite API declarations
```

One disadvantage that error shows `apiDump` instead of `desktopApiDump`.
`apiDump` doesn't work because of the broken Android target, and to fix
it properly we need to do a lot of changes. Just disabling the tasks
doesn't work.

- Desktop API is constructed from desktopMain + skikoMain + commonMain
sourceSets

- Android API is constructed from desktopMain + commonMain. It is
disabled for now, because Android build is broken. The plan is to fix
the Android target, and dump Android API as well. It will help us to
track new API that we need to port more easily.

P.S. Jetpack Compose sources has its own API generator (Metalava), but
it won't be applicable to other Kotlin targets in the future, but
binary-compatibility-validator
[will](Kotlin/binary-compatibility-validator#149)

## Test
1. call desktopCICheck - it succeeds
2. change/add API
3. call desktopCICheck - it fails

---------

Co-authored-by: Ivan Matkov <[email protected]>
  • Loading branch information
igordmn and MatkovIvan committed Jan 30, 2024
1 parent aa8667e commit b5adb6f
Showing 1 changed file with 1,417 additions and 0 deletions.
Loading

0 comments on commit b5adb6f

Please sign in to comment.