Skip to content

Commit

Permalink
[NET Attribute Conversion][generator] Generate NET style attributes (#…
Browse files Browse the repository at this point in the history
…14779)

This PR teaches our code generator to generate .NET 6 style availability attributes, adds a 4th Cecil test to verify our generated attributes, and a metric ton of API changes to satisfy that test.

The generator work is the core of this PR, and includes:

- Hacking out chunks of generator.cs that "helpfully" remove duplicate attributes, which are no longer duplicate in the new order that NET6 attributes force upon us. See changes in FilterMinimumVersion and PrintPlatformAttributes
- Prevent a crash when the generator processes availability attributes with no version included (example: introduced on iOS but no version). See Is64BitiOSOnly.
- The meat, GetPlatformAttributesToPrint, which synthesizes many attributes "out of thing air" from:
        - The parent context
        - Implied introduced just because the class exists on a given framework at all
        - Implied Catalyst because iOS exists
- A few cludgy hacks PrintPlatformAttributesNoDuplicates and GenerateProperty because the existing PrintPlatformAttributes did not pass down parent context down, and the refactor was dangerous/too time consuming given time pressure.

There are two intended API changes introduced by the reviews in this PR:

- GetCurrentInputDevice was obviously intended by availability attributes to exist on Catalyst but due to define confusion was excluded. It is an addition in Microsoft.MacCatalyst.dll only.
- The NEAppRule constructors were mis-marked on platforms, and were showing up incorrectly on Mac/Catalyst. I corrected the Catalyst one unconditionally, as we have not shipped Catalyst yet, but Mac is only fixed in NET6.

There is a lot of follow up work in #14802 to do to remove a number of hard coded test failures, but this should be almost all of the remaining work in NET6 attributes.

🤞 this doesn't break too much for future us.

Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
Co-authored-by: Manuel de la Pena <[email protected]>
  • Loading branch information
3 people authored May 2, 2022
1 parent 7a69d08 commit 1dcefc9
Show file tree
Hide file tree
Showing 102 changed files with 1,499 additions and 755 deletions.
2 changes: 2 additions & 0 deletions src/ARKit/ARSkeleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public partial class ARSkeleton {

#if NET
[SupportedOSPlatform ("ios14.0")]
[UnsupportedOSPlatform ("maccatalyst")]
#else
[iOS (14,0)]
#endif
Expand All @@ -20,6 +21,7 @@ public partial class ARSkeleton {

#if NET
[SupportedOSPlatform ("ios14.0")]
[UnsupportedOSPlatform ("maccatalyst")]
#else
[iOS (14,0)]
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/AVFoundation/AVCaptureVideoPreviewLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public enum InitMode {
WithConnection,
#if NET
[SupportedOSPlatform ("ios8.0")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst")]
#else
[iOS (8,0)]
#endif
Expand Down
7 changes: 1 addition & 6 deletions src/AVFoundation/AVTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,6 @@ public override int GetHashCode ()
}
}

#if NET
[SupportedOSPlatform ("ios8.0")]
[SupportedOSPlatform ("macos10.10")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
#endif
#if !COREBUILD
public static partial class AVMetadataIdentifiers {
}
Expand Down Expand Up @@ -419,6 +413,7 @@ public struct AVSampleCursorChunkInfo {

#if NET
[SupportedOSPlatform ("macos10.15")]
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[Mac (10,15)]
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/AVFoundation/AVVideoSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public double? MaxKeyFrameIntervalDuration {
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("macos")]
[UnsupportedOSPlatform ("macos")]
#else
[iOS (7,0)]
#endif
Expand All @@ -257,8 +257,8 @@ public bool? AllowFrameReordering {
#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
#else
[iOS (7,0)]
#endif
Expand Down Expand Up @@ -300,8 +300,8 @@ public AVVideoH264EntropyMode? EntropyEncoding {
#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
#else
[iOS (7,0)]
#endif
Expand All @@ -318,8 +318,8 @@ public float? ExpectedSourceFrameRate {
#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
#else
[iOS (7,0)]
#endif
Expand Down
1 change: 1 addition & 0 deletions src/AVFoundation/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ public enum AVCaptureAutoFocusSystem : long {
[NoWatch]
[iOS (9, 0)]
[Native]
[NoMac]
public enum AVCaptureSessionInterruptionReason : long {
VideoDeviceNotAvailableInBackground = 1,
AudioDeviceInUseByAnotherClient = 2,
Expand Down
2 changes: 2 additions & 0 deletions src/AddressBook/ABPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace AddressBook {

#if NET
[UnsupportedOSPlatform ("ios9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
#if IOS
[Obsolete ("Starting with ios9.0 use the 'Contacts' API instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
Expand Down Expand Up @@ -251,6 +252,7 @@ internal static void Init ()

#if NET
[UnsupportedOSPlatform ("ios9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
#if IOS
[Obsolete ("Starting with ios9.0 use the 'Contacts' API instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
Expand Down
1 change: 1 addition & 0 deletions src/AddressBook/ABSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public ABSourceType SourceType {

#if NET
[UnsupportedOSPlatform ("ios9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
#if IOS
[Obsolete ("Starting with ios9.0 use the 'Contacts' API instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
Expand Down
1 change: 1 addition & 0 deletions src/AppKit/Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace AppKit {
#if NET
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst")]
#endif
[StructLayout (LayoutKind.Sequential)]
public struct NSEdgeInsets {
Expand Down
5 changes: 0 additions & 5 deletions src/AppKit/NSAccessibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@

namespace AppKit
{
#if NET
[SupportedOSPlatform ("macos10.10")]
#else
[Mac (10,10)] // protocol added in 10.10
#endif
public partial interface INSAccessibility {}

#if NET
Expand Down
17 changes: 15 additions & 2 deletions src/AudioUnit/AUEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,20 @@ public enum AudioObjectPropertySelector : uint
TranslateUIDToBox = 1969841250, // 'uidb'
ClockDeviceList = 1668049699, //'clk#'
TranslateUidToClockDevice = 1969841251, // 'uidc',
#if XAMCORE_3_0
[NoiOS][NoTV]
#endif
[Deprecated (PlatformName.iOS, 15,0, message : "Use the 'ProcessIsMain' element instead.")]
[Deprecated (PlatformName.MacCatalyst, 15,0, message : "Use the 'ProcessIsMain' element instead.")]
[Deprecated (PlatformName.MacOSX, 12,0, message : "Use the 'ProcessIsMain' element instead.")]
[Obsolete ("Use the 'ProcessIsMain' element instead.")]
ProcessIsMaster = 1835103092, // 'mast'
[iOS (15,0), MacCatalyst (15,0), Mac (12,0), NoTV, NoWatch]
#if !XAMCORE_3_0
[iOS (15,0)]
#else
[NoiOS]
#endif
[MacCatalyst (15,0), Mac (12,0), NoTV, NoWatch]
ProcessIsMain = 1835100526, // 'main'
IsInitingOrExiting = 1768845172, // 'inot'
UserIDChanged = 1702193508, // 'euid'
Expand All @@ -208,7 +216,12 @@ public enum AudioObjectPropertySelector : uint
ActualSampleRate = 1634955892,// 'asrt',
ClockDevice = 1634755428, // 'apcd',
IOThreadOSWorkgroup = 1869838183, // 'oswg'
[iOS (15,0), MacCatalyst (15,0), Mac (12,0), NoTV, NoWatch]
#if !XAMCORE_3_0
[iOS (15,0)]
#else
[NoiOS]
#endif
[MacCatalyst (15,0), Mac (12,0), NoTV, NoWatch]
ProcessMute = 1634758765, // 'appm'
}

Expand Down
9 changes: 0 additions & 9 deletions src/AudioUnit/AUParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@

namespace AudioUnit
{
#if NET
[SupportedOSPlatform ("ios9.0")]
[SupportedOSPlatform ("macos10.11")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
#else
[iOS (9,0)]
[Mac (10,11)]
#endif
public partial class AUParameter
{
public string GetString (float? value)
Expand Down
12 changes: 6 additions & 6 deletions src/AudioUnit/AudioComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ public Version? Version {
#if !__MACCATALYST__
#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos")]
[UnsupportedOSPlatform ("tvos14.0")]
[UnsupportedOSPlatform ("ios14.0")]
#if TVOS
Expand All @@ -412,9 +412,9 @@ public Version? Version {

#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos")]
[UnsupportedOSPlatform ("tvos14.0")]
[UnsupportedOSPlatform ("ios14.0")]
#if TVOS
Expand All @@ -436,11 +436,11 @@ public Version? Version {
#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst14.0")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("tvos13.0")]
[UnsupportedOSPlatform ("maccatalyst14.0")]
[UnsupportedOSPlatform ("ios13.0")]
[UnsupportedOSPlatform ("macos")]
#if TVOS
[Obsolete ("Starting with tvos13.0.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#elif __MACCATALYST__
Expand All @@ -461,11 +461,11 @@ public Version? Version {
#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst14.0")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("tvos13.0")]
[UnsupportedOSPlatform ("maccatalyst14.0")]
[UnsupportedOSPlatform ("ios13.0")]
[UnsupportedOSPlatform ("macos")]
#if TVOS
[Obsolete ("Starting with tvos13.0 use 'AudioUnit' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#elif __MACCATALYST__
Expand Down
14 changes: 9 additions & 5 deletions src/AudioUnit/AudioComponentDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public enum AudioTypeConverter { // OSType in AudioComponentDescription
#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
[UnsupportedOSPlatform ("tvos13.0")]
[UnsupportedOSPlatform ("ios13.0")]
#if TVOS
Expand Down Expand Up @@ -210,10 +210,10 @@ public enum AudioTypeEffect { // OSType in AudioComponentDescription
#else
#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("tvos13.0")]
[UnsupportedOSPlatform ("ios13.0")]
[UnsupportedOSPlatform ("macos")]
#if TVOS
[Obsolete ("Starting with tvos13.0 use 'AudioTypeEffect.GraphicEQ' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#elif IOS
Expand Down Expand Up @@ -248,10 +248,10 @@ public enum AudioTypeMixer { // OSType in AudioComponentDescription
#if MONOMAC
Stereo=0x736d7872, // 'smxr'
#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos10.10")]
#if MONOMAC
[Obsolete ("Starting with macos10.10 use 'Spacial' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
Expand All @@ -262,7 +262,11 @@ public enum AudioTypeMixer { // OSType in AudioComponentDescription
ThreeD=0x33646d78, // '3dmx'
#else
#if NET
[SupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("ios8.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
#if IOS
[Obsolete ("Starting with ios8.0 use 'Spacial' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
Expand Down
14 changes: 7 additions & 7 deletions src/AudioUnit/AudioUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,15 @@ public uint GetCurrentDevice (AudioUnitScopeType scope, uint audioUnitElement =
return device;
}

#if !XAMCORE_3_0 || MONOMAC
#if !MONOMAC
#if !XAMCORE_3_0 || MONOMAC || __MACCATALYST__
#if !MONOMAC && !__MACCATALYST__
[Obsolete ("This API is not available on iOS.")]
#endif
#if NET
[SupportedOSPlatform ("maccatalyst15.0")]
[SupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#else
[MacCatalyst (15,0)]
#endif
Expand Down Expand Up @@ -748,11 +748,11 @@ static AudioUnitStatus InputCallbackImpl (IntPtr clientData, ref AudioUnitRender
#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst14.0")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("tvos13.0")]
[UnsupportedOSPlatform ("maccatalyst14.0")]
[UnsupportedOSPlatform ("ios13.0")]
[UnsupportedOSPlatform ("macos")]
#if TVOS
[Obsolete ("Starting with tvos13.0 use 'AudioUnit' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#elif __MACCATALYST__
Expand Down Expand Up @@ -784,11 +784,11 @@ public AudioComponentStatus AudioOutputUnitPublish (AudioComponentDescription de
#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst14.0")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("tvos13.0")]
[UnsupportedOSPlatform ("maccatalyst14.0")]
[UnsupportedOSPlatform ("ios13.0")]
[UnsupportedOSPlatform ("macos")]
#if TVOS
[Obsolete ("Starting with tvos13.0.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#elif __MACCATALYST__
Expand All @@ -809,11 +809,11 @@ public AudioComponentStatus AudioOutputUnitPublish (AudioComponentDescription de
#if NET
[SupportedOSPlatform ("ios7.0")]
[SupportedOSPlatform ("maccatalyst14.0")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("tvos13.0")]
[UnsupportedOSPlatform ("maccatalyst14.0")]
[UnsupportedOSPlatform ("ios13.0")]
[UnsupportedOSPlatform ("macos")]
#if TVOS
[Obsolete ("Starting with tvos13.0 use 'AudioUnit' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#elif __MACCATALYST__
Expand Down
1 change: 1 addition & 0 deletions src/CFNetwork/CFHTTPMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ public enum AuthenticationScheme {
[UnsupportedOSPlatform ("tvos12.0")]
[UnsupportedOSPlatform ("macos10.14")]
[UnsupportedOSPlatform ("ios12.0")]
[UnsupportedOSPlatform ("maccatalyst")]
#if TVOS
[Obsolete ("Starting with tvos12.0 not available anymore.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#elif MONOMAC
Expand Down
2 changes: 2 additions & 0 deletions src/Contacts/CNEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ public enum CNContactOptions : long {
NonGregorianBirthday = 1 << 8,
Note = 1 << 9,
#if !MONOMAC
[NoMac]
ImageData = 1 << 10,
#endif
ThumbnailImageData = 1 << 11,
#if !MONOMAC
[NoMac]
ImageDataAvailable = 1 << 12,
#endif
Type = 1 << 13,
Expand Down
Loading

5 comments on commit 1dcefc9

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 [CI Build] API Diff 📋

API Current PR diff

ℹ️ API Diff (from PR only) (please review changes)

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Generator diff

ℹ️ Generator Diff (please review changes)

Pipeline on Agent XAMMINI-053.Monterey'
Hash: 1dcefc9c560d95f6b64a1a93e497bf69d4d95fed

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: 1dcefc9c560d95f6b64a1a93e497bf69d4d95fed

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests on macOS Mac Catalina (10.15) failed ❌

Failed tests are:

  • introspection

Pipeline on Agent
Hash: 1dcefc9c560d95f6b64a1a93e497bf69d4d95fed

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 [CI Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMMINI-061.Monterey
Hash: 1dcefc9c560d95f6b64a1a93e497bf69d4d95fed

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

3 tests failed, 231 tests passed.

Failed tests

  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - simulator/Debug: Failed
  • introspection/iOS Unified 64-bits - simulator/Debug (iOS 12.4) [dotnet]: Failed
  • introspection/tvOS - simulator/Debug (tvOS 12.4) [dotnet]: Failed

Pipeline on Agent XAMBOT-1043.Monterey'
[NET Attribute Conversion][generator] Generate NET style attributes (#14779)

Please sign in to comment.