Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Dec 16, 2022

Context: #7558

Currently when api-merge loops through type members, its first check is to see if there is any existing member with the same name. If there isn't, it can short-circuit, add the new member, and move to the next one. If there is, we compare the existing API level member to the new API level one to see if it has been marked deprecated in this level, and if so we can add the deprecated-since attribute.

However, this initial existing member check was solely done on member name, not signature. If the member is a method, a later check finds the exact matching method with the same signature. We are performing the deprecated-since logic against the first method with a matching name rather than the method with the same signature. Thus we are producing incorrect results.

This commit moves UpdateDeprecatedSince to be called after we have the method with the matching signature.

The acceptable-breakages changes reflect additional [Obsolete] attributes that are now being converted to [ObsoletedOSPlatform ("android-XX.0")] attributes.

@jpobst jpobst marked this pull request as ready for review January 3, 2023 21:24
@jpobst jpobst requested a review from jonpryor as a code owner January 3, 2023 21:24
@jonpryor
Copy link
Contributor

jonpryor commented Jan 5, 2023

Draft commit message:

Fixes: https://github.com/xamarin/xamarin-android/issues/7558

Context: https://github.com/xamarin/monodroid/commit/16338f99568db892f37f6b5ddf927c139fcd4f50
Context: a073d99a838d15a2e4977fda63ecb1064a214d49
Context: 938c349725b677f1fa291a94f12546ef3d3c5a60

Currently when `api-merge` loops through type members, its first check
is to see if there is any existing member with the same name.  If there
isn't, it can short-circuit, add the new member, and move to the next
one.  If there is, we compare the existing API level member to the new
API level one to see if it has been marked deprecated in this level,
and if so we can add the `deprecated-since` attribute.

However, this initial existing member check was solely done on member
*name*, not signature.  😱

If the member is a method, a later check finds the exact matching
method with the same signature.  We were performing the
`deprecated-since` logic against the first method with a matching name
rather than the method with the same signature.

For example, [`PackageManager.getPackageInfo(String, int)`][0], which
was deprecated in *API-33*.  Yet our binding uses `[Obsolete]`, meaning
it has been deprecated since API-21 or before!

	namespace Android.Content.PM;
	partial class PackageManager {
	    [global::System.Obsolete (@"deprecated")]
	    [Register ("getPackageInfo", "(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;", "GetGetPackageInfo_Ljava_lang_String_IHandler")]
	    public override unsafe Android.Content.PM.PackageInfo? GetPackageInfo (string packageName, [global::Android.Runtime.GeneratedEnum] Android.Content.PM.PackageInfoFlags flags) => …
	}

This was wrong; it should instead have used `[ObsoletedOSPlatform]`:

	namespace Android.Content.PM;
	partial class PackageManager {
	    [global::System.Runtime.Versioning.ObsoletedOSPlatform ("android33.0")]
	    [Register ("getPackageInfo", "(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;", "GetGetPackageInfo_Ljava_lang_String_IHandler")]
	    public override unsafe Android.Content.PM.PackageInfo? GetPackageInfo (string packageName, [global::Android.Runtime.GeneratedEnum] Android.Content.PM.PackageInfoFlags flags) => …
	}


Move the `UpdateDeprecatedSince()` invocations to be called *after*
we have the method with the matching signature.

The `acceptable-breakages` changes reflect additional `[Obsolete]`
attributes that are now being converted to
`[ObsoletedOSPlatform ("android-XX.0")]` attributes.

[0]: https://developer.android.com/reference/android/content/pm/PackageManager#getPackageInfo(java.lang.String,%20int)

@jonpryor
Copy link
Contributor

jonpryor commented Jan 5, 2023

@jpobst: one thing that concerns me is that tests/api-compatibility/acceptable-breakages-vReference-net8.0.txt doesn't have an entry for PackageManager.GetPackageInfo(string, PackageInfoFlags), which was #7558.

Shouldn't PackageManager.GetPackageInfo() be in acceptable-breakages-vReference-net8.0.txt?

@jpobst
Copy link
Contributor Author

jpobst commented Jan 5, 2023

I verified that the package CI is building does include the new attributes:

image

Looking at the reference assembly we use for api-compat, the methods are not marked as [Obsolete] at all. Thus, this is simply an attribute addition and it will not show up in api-compat:

image

Our reference assembly must not have been updated since these methods were marked as deprecated.

@jonpryor jonpryor merged commit c339d1f into main Jan 5, 2023
@jonpryor jonpryor deleted the merge-deprecated-since branch January 5, 2023 16:09
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 17, 2023
* main:
  [Xamarin.Android.Build.Tasks] skip XA1034 logic in some cases (dotnet#7680)
  [ci] Move OneLocBuild task to scheduled pipeline (dotnet#7679)
  [Mono.Android] ServerCertificateValidationCallback() and redirects (dotnet#7662)
  Bump to xamarin/Java.Interop/main@cf80deb7 (dotnet#7664)
  Localized file check-in by OneLocBuild (dotnet#7668)
  [api-merge] Correctly compute //method/@deprecated-since (dotnet#7645)
  [Xamarin.Android.Build.Tasks] _Microsoft.Android.Resource.Designer (dotnet#6427)
  [Xamarin.Android.Build.Tasks] downgrade d8/r8 `warning` messages to `info` (dotnet#7643)
  [Xamarin.Android.Build.Tasks] fix cases of missing `@(Reference)` (dotnet#7642)
  [Xamarin.Android.Build.Tasks] delay ToJniName calls in ManifestDocument (dotnet#7653)
  [Xamarin.Android.Build.Tasks] fast path for `<CheckClientHandlerType/>` (dotnet#7652)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 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