Kotlin / binary-compatibility-validator

Public API management tool
Apache License 2.0
829 stars 60 forks source link

Support meta annotations for nonPublicMarkers #280

Open fsladkey opened 2 weeks ago

fsladkey commented 2 weeks ago

In AndroidX we exclude experimental APIs from our compatibility tracking. The way we do this is by ignoring anything which is annotated by an annotation which itself is annotated with RequiresOptin.

Enumerating all the nonPublicMarkers is brittle (see here) so it would bee great if we could add meta annotations which should not be tracked. e.g. do not track anything annotated with an annotation which itself is annotated with @RequiresOptin.

I took a quick look into implementing it and it seems doable for JVM, however for klibs an AbiReadingFilter doesn't seem to have access to the necessary information to do such a check. Specifically, the list of annotations on a declaration and the associated classes with their annotations.

configure<kotlinx.validation.ApiValidationExtension> {
    nonPublicMetaMarkers.add("annotations.MetaHide")
}
@Target(AnnotationTarget.ANNOTATION_CLASS)
annotation class MetaHide

@MetaHide
@Target(AnnotationTarget.CLASS)
annotation class MyExperimentalApi

@MetaHide
@Target(AnnotationTarget.CLASS)
annotation class AnotherExperimentalAPi

@MyExperimentalApi
class A {} // should be hidden

@AnotherExperimentalApi
class B {} // so should this
fzhinkin commented 22 hours ago

For the record: