Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Mono.Android.dll] Add support for ObsoletedOSPlatformAttribute #7234

Closed
2 tasks done
jpobst opened this issue Aug 4, 2022 · 0 comments
Closed
2 tasks done

[Mono.Android.dll] Add support for ObsoletedOSPlatformAttribute #7234

jpobst opened this issue Aug 4, 2022 · 0 comments
Assignees

Comments

@jpobst
Copy link
Contributor

jpobst commented Aug 4, 2022

Context: #6349
Context: dotnet/runtime#47601

Imagine Android adds a new overload of a method and deprecates the existing method:

[SupportedOSPlatformAttribute ("android33.0")]
public void Foo (string bar) { ... }

[Obsolete]
[SupportedOSPlatformAttribute ("android26.0")]
public void Foo (int bar) { ... }

If you are compiling against API-33 reference assemblies, there is no reasonable way to consume this API without generating an "obsolete" warning:

  • Using the old method generates a warning
  • Using the new method won't work on pre-API-33

In .NET 6 we did not have a good way to express "obsoleted in API X" warnings. In .NET 7 [ObsoletedOSPlatformAttribute] has been added, allowing us to express this properly.

In order to support this, we will need to:

@jpobst jpobst added this to the .NET 7 milestone Aug 4, 2022
@jpobst jpobst self-assigned this Aug 4, 2022
jonpryor pushed a commit to jonpryor/java.interop that referenced this issue Aug 23, 2022
…#1024)

Context: dotnet/android#7234

Refactor logic for applying `[Obsolete]` attributes into a single
common method.  This method will later be extended to add support for
[`[ObsoletedOSPlatformAttribute]`][0].

Doing this piece first and separately allows us to verify that the
refactor does not break anything, as the existing logic is tricky.
A future PR will also remove the temporary hacks used to preserve
stylistic compatibility with a `generator` refactor in 6bbb00a.

[0]: dotnet/runtime#72970
jonpryor pushed a commit to dotnet/java-interop that referenced this issue Aug 23, 2022
Context: dotnet/android#7234

Add support for a new option
`generator --lang-features=obsoleted-platform-attributes`.

When used, for an API that was obsoleted in API levels greater than
our .NET 7 minimum (API-21), we will generate .NET 7's new
`[ObsoletedOSPlatform]` attribute *instead of* `[Obsolete]`:

	// New
	[global::System.Runtime.Versioning.ObsoletedOSPlatform ("android22.0",
	    @"This class is obsoleted in this android platform")]
	public partial class CookieSpecParamBean : Org.Apache.Http.Params.HttpAbstractParamBean {
	}

	// Previous
	[global::System.Obsolete (@"This class is obsoleted in this android platform")]
	public partial class CookieSpecParamBean : Org.Apache.Http.Params.HttpAbstractParamBean {
	}

This is useful in a .NET 7+ context because we always *compile*
against the "latest" `Mono.Android`, even if you are *targeting* an
earlier version.

For example, the use of `[Obsolete]` means that using
`CookieSpecParamBean` would always result in a CS0618 obsolete usage
warning, even when building with `$(SupportedOSPlatformVersion)`=21.
(`CookieSpecParamBean` was obsoleted in API-22.)
jonathanpeppers pushed a commit that referenced this issue Aug 24, 2022
Fixes: #7234

Changes: dotnet/java-interop@a5756ca...e31d9c6

  * dotnet/java-interop@e31d9c62: Context: #7285 (comment) (#1029)
  * dotnet/java-interop@d3ea180c: [generator] Add support for `[ObsoletedOSPlatform]` (#1026)
  * dotnet/java-interop@6d1ae4ee: [generator] Remove [Obsolete] style compatibility hacks. (#1025)
  * dotnet/java-interop@440c05ee: [generator] Refactor logic for applying [Obsolete] attributes (#1024)
  * dotnet/java-interop@9b1d3ab7: [Localization] Import translated resx files (#1018)

`generator` can now emit `[ObsoletedOSPlatformAttribute]`.  Requires:

  - Update `Mono.Android.targets` to pass
    `lang-feature=obsoleted-platform-attributes` to `generator` when
    building for .NET 7+

  - Update `acceptable-breakages-vReference-net7.0.txt` to account
    for removing existing `[Obsolete]` attributes in favor of the new
    ones, for .NET 7+ only
@ghost ghost locked as resolved and limited conversation to collaborators Sep 23, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant