Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Jan 13, 2021

Fixes #752

The Android API has an "interesting" pattern where they have an interface with some static constants, and then they inherit that interface in other types to inherit those constants.

Example: https://developer.android.com/reference/android/provider/BaseColumns

public interface BaseColumns {
  public static final String _COUNT = "_count";
  public static final String _ID = "_id";
}

This interface is inherited by ~115 other types, including other interfaces that only have static constant fields, like CalendarContract.CalendarSyncColumns . This made a very messy API when we bound it due the constants being copied into our alternative IBaseColumnsConsts and ICalendarSyncColumnsConsts classes. Therefore we decided to call this pattern "ConstSugar" and we wrote code to remove these interfaces that did not provide value in the managed API.

However this logic is applied to all binding libraries, and there can exist marker interfaces that meet the same criteria as ConstSugar, and they get silently removed from binding libraries.

public interface CanSerialize {
  public static final int VERSION = 1;
}

public interface CanJsonSerialize : CanSerialize {
}

In this example we would not bind CanJsonSerialize. Worse, an interface can go from not being considered ConstSugar to triggering ConstSugar simply by additions to an API. If CanSerialize originally had no fields, both interfaces would be generated. Once VERSION is added, CanJsonSerialize is considered ConstSugar and will get removed.

Since this logic is very specific to Mono.Android, we're going to use CodeGenerationOptions.BuildingCoreAssembly to determine if we're building Mono.Android.dll, and only run ConstSugar logic if true. This will prevent the logic from running on user binding projects and causing unexplained missing API for users.

@jpobst jpobst marked this pull request as ready for review January 14, 2021 15:31
@jonpryor jonpryor merged commit b0d170c into master Jan 15, 2021
@jonpryor jonpryor deleted the const-sugar branch January 15, 2021 23:57
@jpobst jpobst added this to the 11.2 (16.10 / 8.10) milestone Feb 2, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConstSugar logic can remove marker interfaces

3 participants