Skip to content

Commit 9a504f3

Browse files
committed
Support wildcards
1 parent 28efafc commit 9a504f3

File tree

2 files changed

+80
-31
lines changed

2 files changed

+80
-31
lines changed

src/Sentry.Bindings.Cocoa/ApiDefinitions.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,10 @@ interface SentrySpanContext : SentrySerializable
719719
[Export ("operation")]
720720
string Operation { get; }
721721

722+
// @property (readonly, copy, nonatomic) NSString * _Nullable spanDescription;
723+
[NullAllowed, Export ("spanDescription")]
724+
string SpanDescription { get; }
725+
722726
// @property (copy, nonatomic) NSString * _Nonnull origin;
723727
[Export ("origin")]
724728
string Origin { get; set; }
@@ -777,6 +781,11 @@ interface SentrySpan : SentrySerializable
777781
[Export ("origin")]
778782
string Origin { get; set; }
779783

784+
// @required @property (copy, nonatomic) NSString * _Nullable spanDescription;
785+
[Abstract]
786+
[NullAllowed, Export ("spanDescription")]
787+
string SpanDescription { get; set; }
788+
780789
// @required @property (nonatomic) SentrySpanStatus status;
781790
[Abstract]
782791
[Export ("status", ArgumentSemantic.Assign)]
@@ -1600,6 +1609,11 @@ interface SentryOptions
16001609
[Export ("enableMetricKit")]
16011610
bool EnableMetricKit { get; set; }
16021611

1612+
// @property (assign, nonatomic) BOOL enableMetricKitRawPayload __attribute__((availability(ios, introduced=15.0))) __attribute__((availability(macos, introduced=12.0))) __attribute__((availability(maccatalyst, introduced=15.0))) __attribute__((availability(tvos, unavailable))) __attribute__((availability(watchos, unavailable)));
1613+
[NoWatch, NoTV, Introduced (PlatformName.MacCatalyst, 15, 0), Introduced (PlatformName.MacOSX, 12, 0), Introduced (PlatformName.iOS, 15, 0)]
1614+
[Export ("enableMetricKitRawPayload")]
1615+
bool EnableMetricKitRawPayload { get; set; }
1616+
16031617
// @property (nonatomic) BOOL enableTimeToFullDisplayTracing;
16041618
[Export ("enableTimeToFullDisplayTracing")]
16051619
bool EnableTimeToFullDisplayTracing { get; set; }
@@ -2899,11 +2913,6 @@ interface PrivateSentrySDKOnly
28992913
[Export ("options", ArgumentSemantic.Copy)]
29002914
SentryOptions Options { get; }
29012915

2902-
// @property (assign, nonatomic, class) BOOL appStartMeasurementHybridSDKMode;
2903-
[Static]
2904-
[Export ("appStartMeasurementHybridSDKMode")]
2905-
bool AppStartMeasurementHybridSDKMode { get; set; }
2906-
29072916
// @property (assign, nonatomic, class) BOOL framesTrackingMeasurementHybridSDKMode;
29082917
[Static]
29092918
[Export ("framesTrackingMeasurementHybridSDKMode")]
@@ -2979,11 +2988,6 @@ interface PrivateSentrySDKOnly
29792988
[Export ("setReplayTags:")]
29802989
void SetReplayTags (NSDictionary<NSString, NSObject> tags);
29812990

2982-
// +(NSDictionary<NSString *,id> * _Nullable)appStartMeasurementWithSpans;
2983-
[Static]
2984-
[NullAllowed, Export ("appStartMeasurementWithSpans")]
2985-
NSDictionary<NSString, NSObject> AppStartMeasurementWithSpans { get; }
2986-
29872991
// +(SentryUser * _Nonnull)userWithDictionary:(NSDictionary * _Nonnull)dictionary;
29882992
[Static]
29892993
[Export ("userWithDictionary:")]

tools/Sentry.Bindings.Cocoa.PostProcessor/Program.cs

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@
1212
var tree = CSharpSyntaxTree.ParseText(code);
1313
var nodes = tree.GetCompilationUnitRoot()
1414
.Blacklist<MethodDeclarationSyntax>(
15-
// NSObject
16-
"IsEqual",
17-
"CopyWithZone",
18-
// PrivateSentrySDKOnly
19-
"StoreEnvelope",
20-
"CaptureEnvelope",
21-
"EnvelopeWithData",
22-
// SentryOptions
23-
"CaptureUserFeedback"
15+
// error CS0114: 'SentryXxx.IsEqual(NSObject?)' hides inherited member 'NSObject.IsEqual(NSObject?)'.
16+
"Sentry*.IsEqual",
17+
// error CS0246: The type or namespace name '_NSZone' could not be found
18+
"Sentry*.CopyWithZone",
19+
// SentryEnvelope* is blacklisted
20+
"PrivateSentrySDKOnly.CaptureEnvelope",
21+
"PrivateSentrySDKOnly.EnvelopeWithData",
22+
"PrivateSentrySDKOnly.StoreEnvelope",
23+
// deprecated
24+
"Sentry*.CaptureUserFeedback"
2425
)
2526
.Blacklist<DelegateDeclarationSyntax>(
27+
// deprecated
2628
"SentryUserFeedbackConfigurationBlock"
2729
)
2830
.Blacklist<PropertyDeclarationSyntax>(
29-
"ConfigureUserFeedback",
30-
"Description",
31-
"EnableMetricKitRawPayload",
32-
"AppStartMeasurement",
33-
"AppStartMeasurementTimeoutInterval",
34-
"OnAppStartMeasurementAvailable",
35-
"SentryExperimentalOptions",
36-
"SpanDescription"
31+
// error CS0114: 'SentryXxx.Description' hides inherited member 'NSObject.Description'.
32+
"Sentry*.Description",
33+
// SentryAppStartMeasurement is not whitelisted
34+
"PrivateSentrySDKOnly.*AppStartMeasurement*",
35+
// deprecated
36+
"SentryOptions.ConfigureUserFeedback"
3737
)
3838
.Whitelist<InterfaceDeclarationSyntax>(
3939
"Constants",
@@ -108,25 +108,70 @@ private static string GetIdentifier(SyntaxNode node)
108108
};
109109
}
110110

111+
private static string GetQualifiedName(SyntaxNode node)
112+
{
113+
var identifier = GetIdentifier(node);
114+
var parent = node.Parent;
115+
while (parent != null)
116+
{
117+
if (parent is TypeDeclarationSyntax typeDecl)
118+
{
119+
return $"{typeDecl.Identifier.Text}.{identifier}";
120+
}
121+
parent = parent.Parent;
122+
}
123+
return identifier;
124+
}
125+
126+
private static bool MatchesPattern(string name, string pattern)
127+
{
128+
if (pattern == name)
129+
{
130+
return true;
131+
}
132+
133+
if (!pattern.Contains('*') && !pattern.Contains('?'))
134+
{
135+
return false;
136+
}
137+
138+
var regexPattern = "^" + Regex.Escape(pattern)
139+
.Replace("\\*", ".*")
140+
.Replace("\\?", ".") + "$";
141+
return Regex.IsMatch(name, regexPattern);
142+
}
143+
144+
private static bool MatchesName(SyntaxNode node, string[] patterns)
145+
{
146+
var identifier = GetIdentifier(node);
147+
var qualifiedName = GetQualifiedName(node);
148+
foreach (var pattern in patterns)
149+
{
150+
if (MatchesPattern(identifier, pattern) || MatchesPattern(qualifiedName, pattern))
151+
{
152+
return true;
153+
}
154+
}
155+
return false;
156+
}
157+
111158
public static CompilationUnitSyntax Blacklist<T>(
112159
this CompilationUnitSyntax root,
113160
params string[] names) where T : SyntaxNode
114161
{
115-
var nameSet = new HashSet<string>(names);
116162
var nodesToRemove = root.DescendantNodes()
117163
.OfType<T>()
118-
.Where(node => nameSet.Contains(GetIdentifier(node)));
164+
.Where(node => MatchesName(node, names));
119165
return root.RemoveNodes(nodesToRemove, SyntaxRemoveOptions.KeepNoTrivia)!;
120166
}
121167

122168
public static CompilationUnitSyntax Whitelist<T>(
123169
this CompilationUnitSyntax root,
124170
params string[] names) where T : SyntaxNode
125171
{
126-
var nameSet = new HashSet<string>(names);
127172
var nodesToRemove = root.DescendantNodes()
128173
.OfType<T>()
129-
.Where(node => !nameSet.Contains(GetIdentifier(node)));
174+
.Where(node => !MatchesName(node, names));
130175
return root.RemoveNodes(nodesToRemove, SyntaxRemoveOptions.KeepNoTrivia)!;
131176
}
132177
}

0 commit comments

Comments
 (0)