Skip to content

Commit

Permalink
[xtro] Skip native enum values that aren't available on the current p…
Browse files Browse the repository at this point in the history
…latform. (#21958)

This also required a fix in cecil-tests: don't skip obsolete members when
verifying availability attributes.

We end up failing a test that verifies that a member must exist on a platform,
if it has an availability attribute claiming so in other platforms' assemblies
- the problem being that the test wouldn't find the member on a platform it
was merely obsoleted (but still existing!) there.
  • Loading branch information
rolfbjarne authored Jan 14, 2025
1 parent 9de395d commit b47cbd2
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 43 deletions.
47 changes: 29 additions & 18 deletions src/Metal/MTLEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -971,14 +971,39 @@ public enum MTLPipelineOption : ulong {
/// <summary>Enumerates the hardware feature sets that are available on a device.</summary>
[Native]
public enum MTLFeatureSet : ulong {
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily1_v1 = 0,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily1_v2 = 2,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily2_v1 = 1,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily2_v2 = 3,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily3_v1 = 4,
[NoTV, NoMac, NoMacCatalyst]
Expand Down Expand Up @@ -1010,29 +1035,14 @@ public enum MTLFeatureSet : ulong {
[NoiOS, NoTV, NoMacCatalyst]
macOS_GPUFamily1_v1 = 10000,

#if !NET
[Obsolete ("Use 'macOS_GPUFamily1_v1' instead.")]
OSX_GPUFamily1_v1 = macOS_GPUFamily1_v1,
#endif

[NoiOS, NoTV]
[NoMacCatalyst]
macOS_GPUFamily1_v2 = 10001,

#if !NET
[Obsolete ("Use 'macOS_GPUFamily1_v2' instead.")]
OSX_GPUFamily1_v2 = macOS_GPUFamily1_v2,
#endif

[NoiOS, NoTV]
[NoMacCatalyst]
macOS_ReadWriteTextureTier2 = 10002,

#if !NET
[Obsolete ("Use 'macOS_ReadWriteTextureTier2' instead.")]
OSX_ReadWriteTextureTier2 = macOS_ReadWriteTextureTier2,
#endif

[NoiOS, NoTV]
[NoMacCatalyst]
macOS_GPUFamily1_v3 = 10003,
Expand All @@ -1045,9 +1055,10 @@ public enum MTLFeatureSet : ulong {
[NoMacCatalyst]
macOS_GPUFamily2_v1 = 10005,

#if !NET
[Obsolete ("Use 'tvOS_GPUFamily1_v1' instead.")]
TVOS_GPUFamily1_v1 = 30000,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif

[NoiOS, NoMac]
Expand Down
6 changes: 6 additions & 0 deletions src/oslog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ enum OSLogMessageComponentArgumentCategory : long {
[TV (15, 0), iOS (15, 0), MacCatalyst (15, 0)]
[Native]
enum OSLogStoreScope : long {
#if XAMCORE_5_0
[NoTV, NoiOS, NoMacCatalyst]
#endif
#if !MONOMAC
[Obsolete ("Not available on the current platform.")]
#endif
System = 0,
CurrentProcessIdentifier = 1,
}
Expand Down
4 changes: 0 additions & 4 deletions tests/cecil-tests/AttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ public void FindSupportedOnElementsThatDoNotExistInThatAssembly ()
continue;
}
foreach (var member in GetAllTypeMembers (type)) {
// If a member is hidden, it's probably because it's broken in some way, so don't consider it.
if (ObsoleteTest.HasEditorBrowseableNeverAttribute (member))
continue;

var mentionedPlatforms = GetAvailabilityAttributes (member).ToList ();
if (mentionedPlatforms.Any ()) {
var claimedPlatforms = GetSupportedAvailabilityAttributes (member).ToList ();
Expand Down
1 change: 0 additions & 1 deletion tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16865,7 +16865,6 @@ F:OSLog.OSLogMessageComponentArgumentCategory.String
F:OSLog.OSLogMessageComponentArgumentCategory.UInt64
F:OSLog.OSLogMessageComponentArgumentCategory.Undefined
F:OSLog.OSLogStoreScope.CurrentProcessIdentifier
F:OSLog.OSLogStoreScope.System
F:PassKit.PKAddPassButtonStyle.Black
F:PassKit.PKAddPassButtonStyle.Outline
F:PassKit.PKAddPaymentPassError.SystemCancelled
Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tests/xtro-sharpie/api-annotations-dotnet/iOS-OSLog.todo

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
!missing-pinvoke! MIDISendEventList is not bound
!missing-pinvoke! MIDISourceCreateWithProtocol is not bound

# header's clearly say this enum value is not supported on macOS, yet xtro claims it is
!missing-enum-value! MidiNotificationMessageId native value kMIDIMsgInternalStart = 4096 not bound
!missing-pinvoke! MIDIEventPacketSysexBytesForGroup is not bound
!missing-pinvoke! MIDISendUMPSysex is not bound
!missing-pinvoke! MIDISendUMPSysex8 is not bound

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tests/xtro-sharpie/api-annotations-dotnet/tvOS-OSLog.todo

This file was deleted.

3 changes: 0 additions & 3 deletions tests/xtro-sharpie/api-annotations-dotnet/tvOS-UIKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,6 @@
## Enums not needed on tvOS
!missing-enum! UIListSeparatorVisibility not bound
!missing-enum! UIPrintRenderingQuality not bound
!missing-enum-value! UICollectionLayoutListAppearance native value UICollectionLayoutListAppearanceInsetGrouped = 2 not bound
!missing-enum-value! UICollectionLayoutListAppearance native value UICollectionLayoutListAppearanceSidebar = 3 not bound
!missing-enum-value! UICollectionLayoutListAppearance native value UICollectionLayoutListAppearanceSidebarPlain = 4 not bound

# Not binding for now, does not make sense on tvOS
!missing-selector! +UITextInputContext::current not bound
Expand Down
19 changes: 15 additions & 4 deletions tests/xtro-sharpie/xtro-sharpie/EnumCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,12 @@ public override void VisitEnumDecl (EnumDecl decl, VisitKind visitKind)

// couldn't find a matching managed enum value for the native enum value
// don't report deprecated native enum values (or if the native enum itself is deprecated) as missing
if (!valueDecl.IsDeprecated () && !decl.IsDeprecated ())
if (!valueDecl.IsDeprecated () && !decl.IsDeprecated ()) {
// skip native enum values that aren't available on the current platform, unless it's an error enum.
if (!valueDecl.IsAvailable () && !IsErrorEnum (mname))
continue;
Log.On (framework).Add ($"!missing-enum-value! {type.Name} native value {valueName} = {value} not bound");
}
}
}

Expand Down Expand Up @@ -280,14 +284,21 @@ public override void VisitEnumDecl (EnumDecl decl, VisitKind visitKind)
Log.On (framework).Add ($"!wrong-enum-size! {name} managed {managed_size} vs native {native_size}");
}

static bool IsErrorEnum (string typeName)
{
if (typeName.EndsWith ("Error", StringComparison.Ordinal))
return true;
if (typeName.EndsWith ("ErrorCode", StringComparison.Ordinal))
return true;
return false;
}

static bool IsErrorEnum (TypeDefinition type)
{
if (!type.IsEnum)
return false;

if (type.Name.EndsWith ("Error", StringComparison.Ordinal))
return true;
if (type.Name.EndsWith ("ErrorCode", StringComparison.Ordinal))
if (IsErrorEnum (type.Name))
return true;

if (!type.HasCustomAttributes)
Expand Down

0 comments on commit b47cbd2

Please sign in to comment.