Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented May 11, 2020

Today, generator provides the ability to assign versions to each bound member that is exposed in its Register attribute ApiSince field, a la:

[Register ("android/view/inspector/IntFlagMapping", DoNotGenerateAcw=true, ApiSince=29)]

This is populated via the internal apiversions= option, which reads in a Google provided file containing the api version each member for appeared in. Unfortunately we have found that Google's support of this file isn't guaranteed. Sometimes it is missing, other times it changes randomly, causing ApiCompat breakage.

This PR provides an alternate way to set this ApiSince field in the api.xml. The attribute api-since in now honored on package, class/interface, method, and field elements:

<field name='VERSION_CODE' api-since='7' />

This allows it to be set via metadata or any external tooling that modifies api.xml.

Note that members will inherit version from parent types and parent package definitions, but can also override them as necessary. For example a package added in api 7 containing a class added in api 9:

<package name='com.example.test' jni-name='com/example/test' api-since='7'>
  <class name='MyClassFrom7' />
  <class name='MyClassFrom9' api-since='9' />
</package>

Like previously, this feature is probably only useful for Mono.Android.dll purposes, but it is a little more accessible now.

@jpobst jpobst changed the title [generator] Honor 'api-since' element to fill ApiAvailableSince property. [generator] Honor 'api-since' attribute to fill ApiAvailableSince property. May 11, 2020
@jpobst jpobst marked this pull request as ready for review May 11, 2020 20:40
@jonpryor jonpryor merged commit 186174c into master May 11, 2020
@jonpryor jonpryor deleted the api-since branch May 11, 2020 21:35
jonpryor pushed a commit that referenced this pull request May 15, 2020
Context: 005e273

Currently, if `generator --apiversions=FILE` is used, then the
`RegisterAttribute.ApiSince` field will be set to contain the API
version which introduced a method, e.g. when building xamarin-android's
`src/Mono.Android`:

	$ generator.exe --apiversions=$HOME/android-toolchain/sdk/platform-tools/api/api-versions.xml …

and `$HOME/android-toolchain/sdk/platform-tools/api/api-versions.xml`
contains:

	<class name="android/view/inspector/IntFlagMapping" since="29">
	  <extends name="java/lang/Object"/>

then `generator` will emit:

	[Register ("android/view/inspector/IntFlagMapping", DoNotGenerateAcw=true, ApiSince=29)]
	partial class IntFlagMapping {}

Unfortunately, we have found that Google's support of this file isn't
guaranteed.  Sometimes it is missing, other times it changes in
unexpected ways, causing `ApiCompat` breakage within xamarin-android.

In short, we have lost faith in `api-versions.xml`.

Instead of using `api-versions.xml`, allow `RegisterAttribute.ApiSince`
to be populated by a new `//@api-since` attribute, which is now honored
on `package`, `class`/`interface`, `method`, and `field` elements:

	<field name='VERSION_CODE' api-since='7' />

This allows it to be set via `metadata` or any external tooling that
modifies `api.xml`.

Note that members will inherit versions from parent types and parent
package definitions, but can also override them as necessary.  For
example a package added in API-7 containing a class added in API-9:

	<package name='com.example.test' jni-name='com/example/test' api-since='7'>
	  <class name='MyClassFrom7' />
	  <class name='MyClassFrom9' api-since='9' />
	</package>

As previously, this feature is probably only useful for
`Mono.Android.dll` purposes, but it is now more accessible.
@jpobst jpobst added this to the 10.4 (16.7 / 8.7) milestone May 19, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 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.

3 participants