diff --git a/modules/sentry-cocoa b/modules/sentry-cocoa index 00a2fec32e..d3562ee73e 160000 --- a/modules/sentry-cocoa +++ b/modules/sentry-cocoa @@ -1 +1 @@ -Subproject commit 00a2fec32ea665b81e406419e078bb713238e23f +Subproject commit d3562ee73e56a7b0b8319ec613db3c529924f07a diff --git a/scripts/patch-cocoa-bindings.cs b/scripts/patch-cocoa-bindings.cs index f092bc9d27..6d6eb801e7 100644 --- a/scripts/patch-cocoa-bindings.cs +++ b/scripts/patch-cocoa-bindings.cs @@ -32,6 +32,12 @@ var nodes = tree.GetCompilationUnitRoot() .WithNamespace("Sentry.CocoaSdk") .RemoveClass("CFunctions") + // Fold Swift-extension categories back into their base interface. Objective Sharpie emits + // members declared in a Swift `extension` (e.g. the entire `SentrySDK` API since sentry-cocoa + // 9.19.1 moved its class body into an extension) as a separate `[Category]` interface with an + // auto-generated name like `SentrySDK_Sentry_Swift_8248`. Left alone, KeepInterfaces would drop + // it because that generated name isn't in the keep-list, silently emptying the SentrySDK binding. + .MergeInterface("SentrySDK_*", "SentrySDK") // Make enums, interfaces, and delegates internal .AsInternal("Sentry*", "internal") .WithAttribute("*Sentry*", "Internal") @@ -192,6 +198,32 @@ public static CompilationUnitSyntax KeepInterfaces( return root.RemoveNodes(nodes, SyntaxRemoveOptions.KeepNoTrivia)!; } + public static CompilationUnitSyntax MergeInterface( + this CompilationUnitSyntax root, + string from, + string into) + { + bool IsSource(InterfaceDeclarationSyntax node) => + node.Identifier.Matches(from) && !node.Identifier.Matches(into); + + // Move the members of every category interface matching `from` into the base interface `into`. + var members = root.DescendantNodes() + .OfType() + .Where(IsSource) + .SelectMany(node => node.Members) + .ToArray(); + + if (members.Length > 0) + { + root = root.ReplaceNodes( + root.DescendantNodes().OfType().Where(node => node.Identifier.Matches(into)), + (node, _) => node.AddMembers(members)); + } + + // Drop the now-empty category interfaces. + return root.RemoveByPredicate(IsSource); + } + public static CompilationUnitSyntax WithNamespace( this CompilationUnitSyntax root, string name)