From 6826c9f8add6f3d033134ef3b60e8e03ecbe6f70 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Thu, 10 Apr 2025 13:06:29 -0400 Subject: [PATCH 01/30] Initial commit --- .../Sentry.Samples.Android.csproj | 2 + .../Sentry.Samples.Ios.csproj | 3 + .../Sentry.Samples.MacCatalyst.csproj | 2 + .../Sentry.Samples.Maui.csproj | 2 + .../BuildVariableSourceGenerator.cs | 73 +++++++++++++++++++ src/Sentry/Internal/AotHelper.cs | 23 +++++- src/Sentry/SentrySdk.cs | 24 ++++++ src/Sentry/buildTransitive/Sentry.targets | 8 ++ 8 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 src/Sentry.Analyzers/BuildVariableSourceGenerator.cs diff --git a/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj b/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj index ace5748bae..2d4467e1c7 100644 --- a/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj +++ b/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj @@ -40,4 +40,6 @@ full + + diff --git a/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj b/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj index b1820343e6..8e4744a486 100644 --- a/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj +++ b/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj @@ -44,4 +44,7 @@ + + + diff --git a/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj b/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj index deacfb2b37..713b376eda 100644 --- a/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj +++ b/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj @@ -46,4 +46,6 @@ + + diff --git a/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj b/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj index 28c0f0d502..591d51c86e 100644 --- a/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj +++ b/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj @@ -109,4 +109,6 @@ + + diff --git a/src/Sentry.Analyzers/BuildVariableSourceGenerator.cs b/src/Sentry.Analyzers/BuildVariableSourceGenerator.cs new file mode 100644 index 0000000000..feab18e6e4 --- /dev/null +++ b/src/Sentry.Analyzers/BuildVariableSourceGenerator.cs @@ -0,0 +1,73 @@ +using Microsoft.CodeAnalysis; + +namespace Sentry.Analyzers; + + +/// +/// Generates the necessary msbuild variables +/// +[Generator(LanguageNames.CSharp)] +public class BuildVariableSourceGenerator : ISourceGenerator +{ + /// + /// Initialize the source gen + /// + /// + public void Initialize(GeneratorInitializationContext context) + { + } + + /// + /// Execute the source gen + /// + /// + public void Execute(GeneratorExecutionContext context) + { + var opts = context.AnalyzerConfigOptions.GlobalOptions; + var properties = opts.Keys.Where(x => x.StartsWith("build_property.")).ToList(); + if (properties.Count == 0) + return; + + if (opts.TryGetValue("build_property.DisableSentrySourceGenerator", out var _)) + return; + + // we only want to generate code where host setup takes place + if (!opts.TryGetValue("build_property.outputtype", out var outputType)) + return; + + if (!outputType.Equals("exe", StringComparison.InvariantCultureIgnoreCase)) + return; + + var sb = new StringBuilder(); + sb + .AppendLine("namespace Sentry;") + .AppendLine() + .AppendLine("[global::System.Runtime.CompilerServices.CompilerGenerated]") + .AppendLine("public static class BuildVariableInitializer") + .AppendLine("{") + .AppendLine("\t[global::System.Runtime.CompilerServices.ModuleInitializer]") + .AppendLine("\tpublic static void Initialize()") + .AppendLine("\t{") + .AppendLine("\t\tglobal::Sentry.SentrySdk.InitializeBuildVariables(new global::System.Collections.Generic.Dictionary {"); + + foreach (var property in properties) + { + if (opts.TryGetValue(property, out var value)) + { + var pn = property.Replace("build_property.", ""); + var ev = value.Replace("\\", "\\\\"); + sb + .Append("\t\t\t{") + .Append($"\"{pn}\", \"{ev}\"") + .Append("},\r\n"); + } + } + + sb + .AppendLine("\t\t});") // close dictionary + .AppendLine("\t}") + .AppendLine("}"); + + context.AddSource("__BuildVariables.g.cs", sb.ToString()); + } +} diff --git a/src/Sentry/Internal/AotHelper.cs b/src/Sentry/Internal/AotHelper.cs index 53165c81ca..199c6c2ff1 100644 --- a/src/Sentry/Internal/AotHelper.cs +++ b/src/Sentry/Internal/AotHelper.cs @@ -1,5 +1,3 @@ -using Sentry.Protocol; - namespace Sentry.Internal; internal static class AotHelper @@ -13,10 +11,31 @@ static AotHelper() IsTrimmed = CheckIsTrimmed(); } + [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AvoidAtRuntime)] private static bool CheckIsTrimmed() { + if (Check("publishtrimmed")) + return true; + + if (Check("publishaot")) + return true; + + // fallback check var stackTrace = new StackTrace(false); return stackTrace.GetFrame(0)?.GetMethod() is null; } + + static bool Check(string key) + { + if (SentrySdk.BuildVariables?.TryGetValue(key, out var aotValue) ?? false) + { + if (bool.TryParse(aotValue, out var result)) + { + return result; + } + } + + return false; + } } diff --git a/src/Sentry/SentrySdk.cs b/src/Sentry/SentrySdk.cs index 8c5efbd967..d587df33ad 100644 --- a/src/Sentry/SentrySdk.cs +++ b/src/Sentry/SentrySdk.cs @@ -1,6 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using Sentry.Extensibility; using Sentry.Infrastructure; using Sentry.Internal; +using Sentry.Internal.Extensions; using Sentry.Protocol.Envelopes; namespace Sentry; @@ -17,8 +22,27 @@ public static partial class SentrySdk { internal static IHub CurrentHub = DisabledHub.Instance; + /// + /// The Build Variables generated from you csproj file and initialized by the Sentry Source Generated Module Initializer + /// + public static IReadOnlyDictionary? BuildVariables { get; private set; } + internal static SentryOptions? CurrentOptions => CurrentHub.GetSentryOptions(); + + /// + /// This is called by a Sentry Source-Generator module initializers to help us determine things like + /// Is your app AOT + /// + /// + public static void InitializeBuildVariables(Dictionary variables) + { + if (BuildVariables == null) + { + BuildVariables = variables.AsReadOnly(); + } + } + /// /// Last event id recorded in the current scope. /// diff --git a/src/Sentry/buildTransitive/Sentry.targets b/src/Sentry/buildTransitive/Sentry.targets index 790ed2aa1e..313e3f2c4f 100644 --- a/src/Sentry/buildTransitive/Sentry.targets +++ b/src/Sentry/buildTransitive/Sentry.targets @@ -5,6 +5,14 @@ + + + + + + + + Sentry.Attributes$(MSBuildProjectExtension.Replace('proj', '')) From a3d3a16c7cd73dbfcac18538dea1b71a497018aa Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Thu, 10 Apr 2025 13:13:46 -0400 Subject: [PATCH 02/30] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6986a39fa7..59bfee463d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- New source generator allows Sentry to see true build variables like PublishAot and PublishTrimmed to properly adapt checks in the Sentry SDK ([#4101](https://github.com/getsentry/sentry-dotnet/pull/4101)) + ## 5.5.1 ### Fixes From 48860aa5bcb1a628210234082469f127ee8de11b Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Thu, 10 Apr 2025 13:40:07 -0400 Subject: [PATCH 03/30] Updates path refs --- samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj | 5 ++++- samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj | 5 ++++- .../Sentry.Samples.MacCatalyst.csproj | 5 ++++- samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj b/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj index 2d4467e1c7..1b6d3e5436 100644 --- a/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj +++ b/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj @@ -12,6 +12,9 @@ + @@ -41,5 +44,5 @@ - + diff --git a/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj b/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj index 8e4744a486..60ee498c2a 100644 --- a/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj +++ b/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj @@ -43,8 +43,11 @@ + - + diff --git a/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj b/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj index 713b376eda..72f57e291c 100644 --- a/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj +++ b/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj @@ -44,8 +44,11 @@ + - + diff --git a/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj b/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj index 591d51c86e..0d46333008 100644 --- a/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj +++ b/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj @@ -103,6 +103,9 @@ + @@ -110,5 +113,5 @@ - + From 94800bb929d0bf5b3272944719e5e7997478481d Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 10 Apr 2025 17:53:47 +0000 Subject: [PATCH 04/30] Format code --- src/Sentry/Internal/AotHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry/Internal/AotHelper.cs b/src/Sentry/Internal/AotHelper.cs index 199c6c2ff1..17ea9a011f 100644 --- a/src/Sentry/Internal/AotHelper.cs +++ b/src/Sentry/Internal/AotHelper.cs @@ -26,7 +26,7 @@ private static bool CheckIsTrimmed() return stackTrace.GetFrame(0)?.GetMethod() is null; } - static bool Check(string key) + private static bool Check(string key) { if (SentrySdk.BuildVariables?.TryGetValue(key, out var aotValue) ?? false) { From 7c9f1e221d8cc3a568c94a46d14566b90c414dce Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 15 Apr 2025 14:37:03 -0400 Subject: [PATCH 05/30] Package analyzer with sentry nuget --- src/Sentry/Sentry.csproj | 17 +++++++++++++---- .../buildTransitive/Sentry.Analyzers.targets | 9 +++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/Sentry/buildTransitive/Sentry.Analyzers.targets diff --git a/src/Sentry/Sentry.csproj b/src/Sentry/Sentry.csproj index 49632a39aa..666f07834a 100644 --- a/src/Sentry/Sentry.csproj +++ b/src/Sentry/Sentry.csproj @@ -106,10 +106,6 @@ This file contains targets that are invoked during the end-user's build. The same file is included twice, so it ends up being used for both direct and transitive package references to Sentry. --> - - - - @@ -195,4 +191,17 @@ + + + + + + + + + + diff --git a/src/Sentry/buildTransitive/Sentry.Analyzers.targets b/src/Sentry/buildTransitive/Sentry.Analyzers.targets new file mode 100644 index 0000000000..244f5e38e7 --- /dev/null +++ b/src/Sentry/buildTransitive/Sentry.Analyzers.targets @@ -0,0 +1,9 @@ + + + + + + + + + From 5320e8a5ada548fa7f24b32c96dffcba96c74d61 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Thu, 24 Apr 2025 13:57:07 -0400 Subject: [PATCH 06/30] add tests - having tooling issues lighting this up - trying in CI --- Sentry.sln | 7 ++ SentryMobile.slnf | 3 +- .../BuildVariableSourceGenerator.cs | 29 +++-- .../Sentry.SourceGenerators.csproj | 26 +++++ src/Sentry/Sentry.csproj | 6 +- ...argets => Sentry.SourceGenerators.targets} | 0 .../BuildPropertySourceGeneratorTests.cs | 102 ++++++++++++++++++ test/Sentry.Tests/Sentry.Tests.csproj | 7 ++ 8 files changed, 167 insertions(+), 13 deletions(-) rename src/{Sentry.Analyzers => Sentry.SourceGenerators}/BuildVariableSourceGenerator.cs (67%) create mode 100644 src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj rename src/Sentry/buildTransitive/{Sentry.Analyzers.targets => Sentry.SourceGenerators.targets} (100%) create mode 100644 test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs diff --git a/Sentry.sln b/Sentry.sln index 3ef6fd24aa..40806dc53b 100644 --- a/Sentry.sln +++ b/Sentry.sln @@ -197,6 +197,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.TrimTest", "test\Sen EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.MauiTrimTest", "test\Sentry.MauiTrimTest\Sentry.MauiTrimTest.csproj", "{DF92E098-822C-4B94-B96B-56BFB91FBB54}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators", "src\Sentry.SourceGenerators\Sentry.SourceGenerators.csproj", "{C3CDF61C-3E28-441C-A9CE-011C89D11719}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -532,6 +534,10 @@ Global {DF92E098-822C-4B94-B96B-56BFB91FBB54}.Debug|Any CPU.Build.0 = Debug|Any CPU {DF92E098-822C-4B94-B96B-56BFB91FBB54}.Release|Any CPU.ActiveCfg = Release|Any CPU {DF92E098-822C-4B94-B96B-56BFB91FBB54}.Release|Any CPU.Build.0 = Release|Any CPU + {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -619,5 +625,6 @@ Global {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821} = {21B42F60-5802-404E-90F0-AEBCC56760C0} {6030B748-0000-43B5-B8A8-399AA42F5229} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {DF92E098-822C-4B94-B96B-56BFB91FBB54} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} + {C3CDF61C-3E28-441C-A9CE-011C89D11719} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} EndGlobalSection EndGlobal diff --git a/SentryMobile.slnf b/SentryMobile.slnf index c38fa573cc..8f14531395 100644 --- a/SentryMobile.slnf +++ b/SentryMobile.slnf @@ -12,6 +12,7 @@ "src\\Sentry.Bindings.Cocoa\\Sentry.Bindings.Cocoa.csproj", "src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj", "src\\Sentry.Maui\\Sentry.Maui.csproj", + "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj", "test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj", "test\\Sentry.Extensions.Logging.Tests\\Sentry.Extensions.Logging.Tests.csproj", @@ -21,4 +22,4 @@ "test\\Sentry.Tests\\Sentry.Tests.csproj" ] } -} +} \ No newline at end of file diff --git a/src/Sentry.Analyzers/BuildVariableSourceGenerator.cs b/src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs similarity index 67% rename from src/Sentry.Analyzers/BuildVariableSourceGenerator.cs rename to src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs index feab18e6e4..2c0d679e5a 100644 --- a/src/Sentry.Analyzers/BuildVariableSourceGenerator.cs +++ b/src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs @@ -1,18 +1,19 @@ +using System; +using System.Linq; using Microsoft.CodeAnalysis; -namespace Sentry.Analyzers; +namespace Sentry.SourceGenerators; /// /// Generates the necessary msbuild variables /// [Generator(LanguageNames.CSharp)] -public class BuildVariableSourceGenerator : ISourceGenerator +public class BuildPropertySourceGenerator : ISourceGenerator { /// /// Initialize the source gen /// - /// public void Initialize(GeneratorInitializationContext context) { } @@ -20,16 +21,18 @@ public void Initialize(GeneratorInitializationContext context) /// /// Execute the source gen /// - /// public void Execute(GeneratorExecutionContext context) { + // we'll wrap code in ifdef as it is safer than checking all of the various pieces involved here + // ((CSharpCompilation)context.Compilation).LanguageVersion == LanguageVersion.CSharp9 + var opts = context.AnalyzerConfigOptions.GlobalOptions; var properties = opts.Keys.Where(x => x.StartsWith("build_property.")).ToList(); if (properties.Count == 0) return; - if (opts.TryGetValue("build_property.DisableSentrySourceGenerator", out var _)) - return; + if (!opts.TryGetValue("build_property.debugpropertycapture", out var debug) && (debug?.Equals("true", StringComparison.InvariantCultureIgnoreCase) ?? false)) + Debugger.Break(); // we only want to generate code where host setup takes place if (!opts.TryGetValue("build_property.outputtype", out var outputType)) @@ -40,6 +43,10 @@ public void Execute(GeneratorExecutionContext context) var sb = new StringBuilder(); sb + .AppendLine("#if NET8_0_OR_GREATER") + .AppendLine("using System;") + .AppendLine("using System.Collections.Generic;") + .AppendLine() .AppendLine("namespace Sentry;") .AppendLine() .AppendLine("[global::System.Runtime.CompilerServices.CompilerGenerated]") @@ -54,8 +61,8 @@ public void Execute(GeneratorExecutionContext context) { if (opts.TryGetValue(property, out var value)) { - var pn = property.Replace("build_property.", ""); - var ev = value.Replace("\\", "\\\\"); + var pn = EscapeString(property.Replace("build_property.", "")); + var ev = EscapeString(value); sb .Append("\t\t\t{") .Append($"\"{pn}\", \"{ev}\"") @@ -66,8 +73,12 @@ public void Execute(GeneratorExecutionContext context) sb .AppendLine("\t\t});") // close dictionary .AppendLine("\t}") - .AppendLine("}"); + .AppendLine("}") + .AppendLine("#endif"); context.AddSource("__BuildVariables.g.cs", sb.ToString()); } + + + private static string EscapeString(string value) => value.Replace("\\", "\\\\"); } diff --git a/src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj b/src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj new file mode 100644 index 0000000000..087c8ef2a6 --- /dev/null +++ b/src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj @@ -0,0 +1,26 @@ + + + + netstandard2.0 + false + enable + false + + true + true + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/src/Sentry/Sentry.csproj b/src/Sentry/Sentry.csproj index 666f07834a..cfeefdd197 100644 --- a/src/Sentry/Sentry.csproj +++ b/src/Sentry/Sentry.csproj @@ -194,12 +194,12 @@ - - + + - diff --git a/src/Sentry/buildTransitive/Sentry.Analyzers.targets b/src/Sentry/buildTransitive/Sentry.SourceGenerators.targets similarity index 100% rename from src/Sentry/buildTransitive/Sentry.Analyzers.targets rename to src/Sentry/buildTransitive/Sentry.SourceGenerators.targets diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs new file mode 100644 index 0000000000..a86459dc7d --- /dev/null +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs @@ -0,0 +1,102 @@ +#if NET8_0_OR_GREATER && !__ANDROID__ && !__IOS__ +#nullable enable +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.VisualStudio.TestPlatform.TestHost; +using Sentry.SourceGenerators; + +namespace Sentry.Tests; + + +public class BuildPropertySourceGeneratorTests +{ + [Fact] + public Task Driver_Success() + { + var driver = BuildDriver(typeof(Program).Assembly); + return Verify(driver); + } + + + [Fact] + public Task RunResult_Success() + { + var driver = BuildDriver(typeof(Program).Assembly, ("PublishAot", "false"), ("OutputType", "exe")); + var result = driver.GetRunResult().Results.FirstOrDefault(); + result.Exception.Should().BeNull(); + result.GeneratedSources.Length.Should().Be(1); + result.GeneratedSources.First().HintName.Should().Be("__BuildVariables.g.cs"); + return Verify(result); + } + + + [Fact] + public Task RunResult_BadStrings() + { + // we're hijacking PublishAot to make life easy + var driver = BuildDriver(typeof(Program).Assembly, ("My\\Key", "test\\test"), ("OutputType", "exe")); + var result = driver.GetRunResult().Results.FirstOrDefault(); + result.Exception.Should().BeNull(); + result.GeneratedSources.Length.Should().Be(1); + result.GeneratedSources.First().HintName.Should().Be("__BuildVariables.g.cs"); + return Verify(result); + } + + + [Fact] + public Task RunResult_Publish_AotTrue() + { + var driver = BuildDriver(typeof(Program).Assembly, ("PublishAot", "true"), ("OutputType", "exe")); + var result = driver.GetRunResult().Results.FirstOrDefault(); + result.Exception.Should().BeNull(); + result.GeneratedSources.Length.Should().Be(1); + result.GeneratedSources.First().HintName.Should().Be("__BuildVariables.g.cs"); + return Verify(result); + } + + + [Fact] + public Task RunResult_Expect_None() + { + var driver = BuildDriver(typeof(Program).Assembly, ("PublishAot", "false")); + var result = driver.GetRunResult().Results.FirstOrDefault(); + result.Exception.Should().BeNull(); + result.GeneratedSources.Length.Should().Be(0); + + return Verify(result); + } + + + static GeneratorDriver BuildDriver(Assembly metadataAssembly, params IEnumerable<(string Key, string Value)> buildProperties) + { + var metadataReference = MetadataReference.CreateFromFile(metadataAssembly.Location); + var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); + var compilation = CSharpCompilation.Create("TestAssembly", [], [metadataReference], options); + var generator = new BuildPropertySourceGenerator(); + + var dict = buildProperties.ToDictionary(x => "build_property." + x.Key, x => x.Value, comparer: StringComparer.InvariantCultureIgnoreCase); + var provider = new MockAnalyzerConfigOptionsProvider(dict); + + var driver = CSharpGeneratorDriver.Create([generator], optionsProvider: provider); + return driver.RunGenerators(compilation); + } +} + +file class MockAnalyzerConfigOptionsProvider(Dictionary buildProperties) : AnalyzerConfigOptionsProvider +{ + readonly MockAnalyzerConfigOptions options = new (buildProperties); + + public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => this.options; + public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => this.options; + public override AnalyzerConfigOptions GlobalOptions => this.options; +} + +file class MockAnalyzerConfigOptions(Dictionary values) : AnalyzerConfigOptions +{ + public override bool TryGetValue(string key, [NotNullWhen(true)] out string? value) + => values.TryGetValue(key, out value); + + public override IEnumerable Keys => values.Keys; +} +#endif diff --git a/test/Sentry.Tests/Sentry.Tests.csproj b/test/Sentry.Tests/Sentry.Tests.csproj index d2c5db0dfc..5798e48fd1 100644 --- a/test/Sentry.Tests/Sentry.Tests.csproj +++ b/test/Sentry.Tests/Sentry.Tests.csproj @@ -43,4 +43,11 @@ + + + + + + + From c034685695b5d1d7b288a0d01b30e836cd29dcc0 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 24 Apr 2025 18:10:16 +0000 Subject: [PATCH 07/30] Format code --- modules/sentry-native | 2 +- .../BuildPropertySourceGeneratorTests.cs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/sentry-native b/modules/sentry-native index 69f006a722..19d50848fb 160000 --- a/modules/sentry-native +++ b/modules/sentry-native @@ -1 +1 @@ -Subproject commit 69f006a722ac1688ff3373acf0f7dcf0b067b56f +Subproject commit 19d50848fb80a7f56f98fe30fef6731b1eedb8b3 diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs index a86459dc7d..9136e36f4b 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs @@ -68,7 +68,7 @@ public Task RunResult_Expect_None() } - static GeneratorDriver BuildDriver(Assembly metadataAssembly, params IEnumerable<(string Key, string Value)> buildProperties) + private static GeneratorDriver BuildDriver(Assembly metadataAssembly, params IEnumerable<(string Key, string Value)> buildProperties) { var metadataReference = MetadataReference.CreateFromFile(metadataAssembly.Location); var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); @@ -85,11 +85,19 @@ static GeneratorDriver BuildDriver(Assembly metadataAssembly, params IEnumerable file class MockAnalyzerConfigOptionsProvider(Dictionary buildProperties) : AnalyzerConfigOptionsProvider { - readonly MockAnalyzerConfigOptions options = new (buildProperties); + private readonly MockAnalyzerConfigOptions options = new(buildProperties); - public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => this.options; + public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => options; + +<<<<<<< TODO: Unmerged change from project 'Sentry.Tests(net8.0)', Before: public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => this.options; public override AnalyzerConfigOptions GlobalOptions => this.options; +======= + public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => options; + public override AnalyzerConfigOptions GlobalOptions => options; +>>>>>>> After + public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => options; + public override AnalyzerConfigOptions GlobalOptions => options; } file class MockAnalyzerConfigOptions(Dictionary values) : AnalyzerConfigOptions From 09fba9e636bdbdb310a852061ff053b172a32c4e Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Thu, 24 Apr 2025 14:12:01 -0400 Subject: [PATCH 08/30] Updates --- .generated.NoMobile.sln | 7 + SentryNoMobile.slnf | 5 +- ...torTests.RunResult_BadStrings.verified.txt | 323 ++++++++++++++++++ ...orTests.RunResult_Expect_None.verified.txt | 5 + ...sts.RunResult_Publish_AotTrue.verified.txt | 323 ++++++++++++++++++ ...eratorTests.RunResult_Success.verified.txt | 323 ++++++++++++++++++ .../BuildPropertySourceGeneratorTests.cs | 16 +- test/Sentry.Tests/Sentry.Tests.csproj | 3 +- 8 files changed, 989 insertions(+), 16 deletions(-) create mode 100644 test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt create mode 100644 test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Expect_None.verified.txt create mode 100644 test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt create mode 100644 test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt diff --git a/.generated.NoMobile.sln b/.generated.NoMobile.sln index 62290abdc9..09f5325835 100644 --- a/.generated.NoMobile.sln +++ b/.generated.NoMobile.sln @@ -197,6 +197,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.TrimTest", "test\Sen EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.MauiTrimTest", "test\Sentry.MauiTrimTest\Sentry.MauiTrimTest.csproj", "{DF92E098-822C-4B94-B96B-56BFB91FBB54}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators", "src\Sentry.SourceGenerators\Sentry.SourceGenerators.csproj", "{E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -532,6 +534,10 @@ Global {DF92E098-822C-4B94-B96B-56BFB91FBB54}.Debug|Any CPU.Build.0 = Debug|Any CPU {DF92E098-822C-4B94-B96B-56BFB91FBB54}.Release|Any CPU.ActiveCfg = Release|Any CPU {DF92E098-822C-4B94-B96B-56BFB91FBB54}.Release|Any CPU.Build.0 = Release|Any CPU + {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -619,5 +625,6 @@ Global {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821} = {21B42F60-5802-404E-90F0-AEBCC56760C0} {6030B748-0000-43B5-B8A8-399AA42F5229} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {DF92E098-822C-4B94-B96B-56BFB91FBB54} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} + {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} EndGlobalSection EndGlobal diff --git a/SentryNoMobile.slnf b/SentryNoMobile.slnf index e6e27c6ee7..3960b05c00 100644 --- a/SentryNoMobile.slnf +++ b/SentryNoMobile.slnf @@ -32,10 +32,10 @@ "samples\\Sentry.Samples.OpenTelemetry.Console\\Sentry.Samples.OpenTelemetry.Console.csproj", "samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj", "src\\Sentry.Analyzers\\Sentry.Analyzers.csproj", - "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.AspNetCore.Blazor.WebAssembly\\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj", "src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj", + "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj", "src\\Sentry.DiagnosticSource\\Sentry.DiagnosticSource.csproj", "src\\Sentry.EntityFramework\\Sentry.EntityFramework.csproj", @@ -47,6 +47,7 @@ "src\\Sentry.OpenTelemetry\\Sentry.OpenTelemetry.csproj", "src\\Sentry.Profiling\\Sentry.Profiling.csproj", "src\\Sentry.Serilog\\Sentry.Serilog.csproj", + "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj", "test\\Sentry.Analyzers.Tests\\Sentry.Analyzers.Tests.csproj", "test\\Sentry.AspNet.Tests\\Sentry.AspNet.Tests.csproj", @@ -71,4 +72,4 @@ "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } -} +} \ No newline at end of file diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt new file mode 100644 index 0000000000..22b3e3d75e --- /dev/null +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt @@ -0,0 +1,323 @@ +{ + Generator: {}, + GeneratedSources: [ + { + SyntaxTree: { + FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildVariables.g.cs, + Encoding: utf-8, + Length: 490, + HasCompilationUnitRoot: true, + Options: { + LanguageVersion: CSharp12, + Language: C#, + DocumentationMode: Parse, + Errors: null + } + }, + SourceText: { + Encoding: utf-8, + Source: +#if NET8_0_OR_GREATER +using System; +using System.Collections.Generic; + +namespace Sentry; + +[global::System.Runtime.CompilerServices.CompilerGenerated] +public static class BuildVariableInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::Sentry.SentrySdk.InitializeBuildVariables(new global::System.Collections.Generic.Dictionary { + {"My\\Key", "test\\test"}, + {"OutputType", "exe"}, + }); + } +} +#endif +, + Length: 490, + ChecksumAlgorithm: Sha1, + CanBeEmbedded: true, + Container: {}, + Lines: [ + { + End: 21, + EndIncludingLineBreak: 22, + Span: { + Length: 21 + }, + SpanIncludingLineBreak: { + Length: 22 + } + }, + { + LineNumber: 1, + Start: 22, + End: 35, + EndIncludingLineBreak: 36, + Span: { + Start: 22, + Length: 13 + }, + SpanIncludingLineBreak: { + Start: 22, + Length: 14 + } + }, + { + LineNumber: 2, + Start: 36, + End: 69, + EndIncludingLineBreak: 70, + Span: { + Start: 36, + Length: 33 + }, + SpanIncludingLineBreak: { + Start: 36, + Length: 34 + } + }, + { + LineNumber: 3, + Start: 70, + End: 70, + EndIncludingLineBreak: 71, + Span: { + Start: 70 + }, + SpanIncludingLineBreak: { + Start: 70, + Length: 1 + } + }, + { + LineNumber: 4, + Start: 71, + End: 88, + EndIncludingLineBreak: 89, + Span: { + Start: 71, + Length: 17 + }, + SpanIncludingLineBreak: { + Start: 71, + Length: 18 + } + }, + { + LineNumber: 5, + Start: 89, + End: 89, + EndIncludingLineBreak: 90, + Span: { + Start: 89 + }, + SpanIncludingLineBreak: { + Start: 89, + Length: 1 + } + }, + { + LineNumber: 6, + Start: 90, + End: 149, + EndIncludingLineBreak: 150, + Span: { + Start: 90, + Length: 59 + }, + SpanIncludingLineBreak: { + Start: 90, + Length: 60 + } + }, + { + LineNumber: 7, + Start: 150, + End: 194, + EndIncludingLineBreak: 195, + Span: { + Start: 150, + Length: 44 + }, + SpanIncludingLineBreak: { + Start: 150, + Length: 45 + } + }, + { + LineNumber: 8, + Start: 195, + End: 196, + EndIncludingLineBreak: 197, + Span: { + Start: 195, + Length: 1 + }, + SpanIncludingLineBreak: { + Start: 195, + Length: 2 + } + }, + { + LineNumber: 9, + Start: 197, + End: 257, + EndIncludingLineBreak: 258, + Span: { + Start: 197, + Length: 60 + }, + SpanIncludingLineBreak: { + Start: 197, + Length: 61 + } + }, + { + LineNumber: 10, + Start: 258, + End: 290, + EndIncludingLineBreak: 291, + Span: { + Start: 258, + Length: 32 + }, + SpanIncludingLineBreak: { + Start: 258, + Length: 33 + } + }, + { + LineNumber: 11, + Start: 291, + End: 293, + EndIncludingLineBreak: 294, + Span: { + Start: 291, + Length: 2 + }, + SpanIncludingLineBreak: { + Start: 291, + Length: 3 + } + }, + { + LineNumber: 12, + Start: 294, + End: 413, + EndIncludingLineBreak: 414, + Span: { + Start: 294, + Length: 119 + }, + SpanIncludingLineBreak: { + Start: 294, + Length: 120 + } + }, + { + LineNumber: 13, + Start: 414, + End: 443, + EndIncludingLineBreak: 445, + Span: { + Start: 414, + Length: 29 + }, + SpanIncludingLineBreak: { + Start: 414, + Length: 31 + } + }, + { + LineNumber: 14, + Start: 445, + End: 470, + EndIncludingLineBreak: 472, + Span: { + Start: 445, + Length: 25 + }, + SpanIncludingLineBreak: { + Start: 445, + Length: 27 + } + }, + { + LineNumber: 15, + Start: 472, + End: 477, + EndIncludingLineBreak: 478, + Span: { + Start: 472, + Length: 5 + }, + SpanIncludingLineBreak: { + Start: 472, + Length: 6 + } + }, + { + LineNumber: 16, + Start: 478, + End: 480, + EndIncludingLineBreak: 481, + Span: { + Start: 478, + Length: 2 + }, + SpanIncludingLineBreak: { + Start: 478, + Length: 3 + } + }, + { + LineNumber: 17, + Start: 481, + End: 482, + EndIncludingLineBreak: 483, + Span: { + Start: 481, + Length: 1 + }, + SpanIncludingLineBreak: { + Start: 481, + Length: 2 + } + }, + { + LineNumber: 18, + Start: 483, + End: 489, + EndIncludingLineBreak: 490, + Span: { + Start: 483, + Length: 6 + }, + SpanIncludingLineBreak: { + Start: 483, + Length: 7 + } + }, + { + LineNumber: 19, + Start: 490, + End: 490, + EndIncludingLineBreak: 490, + Span: { + Start: 490 + }, + SpanIncludingLineBreak: { + Start: 490 + } + } + ] + }, + HintName: __BuildVariables.g.cs + } + ], + Diagnostics: null +} \ No newline at end of file diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Expect_None.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Expect_None.verified.txt new file mode 100644 index 0000000000..f2b746dde0 --- /dev/null +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Expect_None.verified.txt @@ -0,0 +1,5 @@ +{ + Generator: {}, + GeneratedSources: null, + Diagnostics: null +} \ No newline at end of file diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt new file mode 100644 index 0000000000..cc40131f65 --- /dev/null +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt @@ -0,0 +1,323 @@ +{ + Generator: {}, + GeneratedSources: [ + { + SyntaxTree: { + FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildVariables.g.cs, + Encoding: utf-8, + Length: 487, + HasCompilationUnitRoot: true, + Options: { + LanguageVersion: CSharp12, + Language: C#, + DocumentationMode: Parse, + Errors: null + } + }, + SourceText: { + Encoding: utf-8, + Source: +#if NET8_0_OR_GREATER +using System; +using System.Collections.Generic; + +namespace Sentry; + +[global::System.Runtime.CompilerServices.CompilerGenerated] +public static class BuildVariableInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::Sentry.SentrySdk.InitializeBuildVariables(new global::System.Collections.Generic.Dictionary { + {"PublishAot", "true"}, + {"OutputType", "exe"}, + }); + } +} +#endif +, + Length: 487, + ChecksumAlgorithm: Sha1, + CanBeEmbedded: true, + Container: {}, + Lines: [ + { + End: 21, + EndIncludingLineBreak: 22, + Span: { + Length: 21 + }, + SpanIncludingLineBreak: { + Length: 22 + } + }, + { + LineNumber: 1, + Start: 22, + End: 35, + EndIncludingLineBreak: 36, + Span: { + Start: 22, + Length: 13 + }, + SpanIncludingLineBreak: { + Start: 22, + Length: 14 + } + }, + { + LineNumber: 2, + Start: 36, + End: 69, + EndIncludingLineBreak: 70, + Span: { + Start: 36, + Length: 33 + }, + SpanIncludingLineBreak: { + Start: 36, + Length: 34 + } + }, + { + LineNumber: 3, + Start: 70, + End: 70, + EndIncludingLineBreak: 71, + Span: { + Start: 70 + }, + SpanIncludingLineBreak: { + Start: 70, + Length: 1 + } + }, + { + LineNumber: 4, + Start: 71, + End: 88, + EndIncludingLineBreak: 89, + Span: { + Start: 71, + Length: 17 + }, + SpanIncludingLineBreak: { + Start: 71, + Length: 18 + } + }, + { + LineNumber: 5, + Start: 89, + End: 89, + EndIncludingLineBreak: 90, + Span: { + Start: 89 + }, + SpanIncludingLineBreak: { + Start: 89, + Length: 1 + } + }, + { + LineNumber: 6, + Start: 90, + End: 149, + EndIncludingLineBreak: 150, + Span: { + Start: 90, + Length: 59 + }, + SpanIncludingLineBreak: { + Start: 90, + Length: 60 + } + }, + { + LineNumber: 7, + Start: 150, + End: 194, + EndIncludingLineBreak: 195, + Span: { + Start: 150, + Length: 44 + }, + SpanIncludingLineBreak: { + Start: 150, + Length: 45 + } + }, + { + LineNumber: 8, + Start: 195, + End: 196, + EndIncludingLineBreak: 197, + Span: { + Start: 195, + Length: 1 + }, + SpanIncludingLineBreak: { + Start: 195, + Length: 2 + } + }, + { + LineNumber: 9, + Start: 197, + End: 257, + EndIncludingLineBreak: 258, + Span: { + Start: 197, + Length: 60 + }, + SpanIncludingLineBreak: { + Start: 197, + Length: 61 + } + }, + { + LineNumber: 10, + Start: 258, + End: 290, + EndIncludingLineBreak: 291, + Span: { + Start: 258, + Length: 32 + }, + SpanIncludingLineBreak: { + Start: 258, + Length: 33 + } + }, + { + LineNumber: 11, + Start: 291, + End: 293, + EndIncludingLineBreak: 294, + Span: { + Start: 291, + Length: 2 + }, + SpanIncludingLineBreak: { + Start: 291, + Length: 3 + } + }, + { + LineNumber: 12, + Start: 294, + End: 413, + EndIncludingLineBreak: 414, + Span: { + Start: 294, + Length: 119 + }, + SpanIncludingLineBreak: { + Start: 294, + Length: 120 + } + }, + { + LineNumber: 13, + Start: 414, + End: 440, + EndIncludingLineBreak: 442, + Span: { + Start: 414, + Length: 26 + }, + SpanIncludingLineBreak: { + Start: 414, + Length: 28 + } + }, + { + LineNumber: 14, + Start: 442, + End: 467, + EndIncludingLineBreak: 469, + Span: { + Start: 442, + Length: 25 + }, + SpanIncludingLineBreak: { + Start: 442, + Length: 27 + } + }, + { + LineNumber: 15, + Start: 469, + End: 474, + EndIncludingLineBreak: 475, + Span: { + Start: 469, + Length: 5 + }, + SpanIncludingLineBreak: { + Start: 469, + Length: 6 + } + }, + { + LineNumber: 16, + Start: 475, + End: 477, + EndIncludingLineBreak: 478, + Span: { + Start: 475, + Length: 2 + }, + SpanIncludingLineBreak: { + Start: 475, + Length: 3 + } + }, + { + LineNumber: 17, + Start: 478, + End: 479, + EndIncludingLineBreak: 480, + Span: { + Start: 478, + Length: 1 + }, + SpanIncludingLineBreak: { + Start: 478, + Length: 2 + } + }, + { + LineNumber: 18, + Start: 480, + End: 486, + EndIncludingLineBreak: 487, + Span: { + Start: 480, + Length: 6 + }, + SpanIncludingLineBreak: { + Start: 480, + Length: 7 + } + }, + { + LineNumber: 19, + Start: 487, + End: 487, + EndIncludingLineBreak: 487, + Span: { + Start: 487 + }, + SpanIncludingLineBreak: { + Start: 487 + } + } + ] + }, + HintName: __BuildVariables.g.cs + } + ], + Diagnostics: null +} \ No newline at end of file diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt new file mode 100644 index 0000000000..dddefc506c --- /dev/null +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt @@ -0,0 +1,323 @@ +{ + Generator: {}, + GeneratedSources: [ + { + SyntaxTree: { + FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildVariables.g.cs, + Encoding: utf-8, + Length: 488, + HasCompilationUnitRoot: true, + Options: { + LanguageVersion: CSharp12, + Language: C#, + DocumentationMode: Parse, + Errors: null + } + }, + SourceText: { + Encoding: utf-8, + Source: +#if NET8_0_OR_GREATER +using System; +using System.Collections.Generic; + +namespace Sentry; + +[global::System.Runtime.CompilerServices.CompilerGenerated] +public static class BuildVariableInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::Sentry.SentrySdk.InitializeBuildVariables(new global::System.Collections.Generic.Dictionary { + {"PublishAot", "false"}, + {"OutputType", "exe"}, + }); + } +} +#endif +, + Length: 488, + ChecksumAlgorithm: Sha1, + CanBeEmbedded: true, + Container: {}, + Lines: [ + { + End: 21, + EndIncludingLineBreak: 22, + Span: { + Length: 21 + }, + SpanIncludingLineBreak: { + Length: 22 + } + }, + { + LineNumber: 1, + Start: 22, + End: 35, + EndIncludingLineBreak: 36, + Span: { + Start: 22, + Length: 13 + }, + SpanIncludingLineBreak: { + Start: 22, + Length: 14 + } + }, + { + LineNumber: 2, + Start: 36, + End: 69, + EndIncludingLineBreak: 70, + Span: { + Start: 36, + Length: 33 + }, + SpanIncludingLineBreak: { + Start: 36, + Length: 34 + } + }, + { + LineNumber: 3, + Start: 70, + End: 70, + EndIncludingLineBreak: 71, + Span: { + Start: 70 + }, + SpanIncludingLineBreak: { + Start: 70, + Length: 1 + } + }, + { + LineNumber: 4, + Start: 71, + End: 88, + EndIncludingLineBreak: 89, + Span: { + Start: 71, + Length: 17 + }, + SpanIncludingLineBreak: { + Start: 71, + Length: 18 + } + }, + { + LineNumber: 5, + Start: 89, + End: 89, + EndIncludingLineBreak: 90, + Span: { + Start: 89 + }, + SpanIncludingLineBreak: { + Start: 89, + Length: 1 + } + }, + { + LineNumber: 6, + Start: 90, + End: 149, + EndIncludingLineBreak: 150, + Span: { + Start: 90, + Length: 59 + }, + SpanIncludingLineBreak: { + Start: 90, + Length: 60 + } + }, + { + LineNumber: 7, + Start: 150, + End: 194, + EndIncludingLineBreak: 195, + Span: { + Start: 150, + Length: 44 + }, + SpanIncludingLineBreak: { + Start: 150, + Length: 45 + } + }, + { + LineNumber: 8, + Start: 195, + End: 196, + EndIncludingLineBreak: 197, + Span: { + Start: 195, + Length: 1 + }, + SpanIncludingLineBreak: { + Start: 195, + Length: 2 + } + }, + { + LineNumber: 9, + Start: 197, + End: 257, + EndIncludingLineBreak: 258, + Span: { + Start: 197, + Length: 60 + }, + SpanIncludingLineBreak: { + Start: 197, + Length: 61 + } + }, + { + LineNumber: 10, + Start: 258, + End: 290, + EndIncludingLineBreak: 291, + Span: { + Start: 258, + Length: 32 + }, + SpanIncludingLineBreak: { + Start: 258, + Length: 33 + } + }, + { + LineNumber: 11, + Start: 291, + End: 293, + EndIncludingLineBreak: 294, + Span: { + Start: 291, + Length: 2 + }, + SpanIncludingLineBreak: { + Start: 291, + Length: 3 + } + }, + { + LineNumber: 12, + Start: 294, + End: 413, + EndIncludingLineBreak: 414, + Span: { + Start: 294, + Length: 119 + }, + SpanIncludingLineBreak: { + Start: 294, + Length: 120 + } + }, + { + LineNumber: 13, + Start: 414, + End: 441, + EndIncludingLineBreak: 443, + Span: { + Start: 414, + Length: 27 + }, + SpanIncludingLineBreak: { + Start: 414, + Length: 29 + } + }, + { + LineNumber: 14, + Start: 443, + End: 468, + EndIncludingLineBreak: 470, + Span: { + Start: 443, + Length: 25 + }, + SpanIncludingLineBreak: { + Start: 443, + Length: 27 + } + }, + { + LineNumber: 15, + Start: 470, + End: 475, + EndIncludingLineBreak: 476, + Span: { + Start: 470, + Length: 5 + }, + SpanIncludingLineBreak: { + Start: 470, + Length: 6 + } + }, + { + LineNumber: 16, + Start: 476, + End: 478, + EndIncludingLineBreak: 479, + Span: { + Start: 476, + Length: 2 + }, + SpanIncludingLineBreak: { + Start: 476, + Length: 3 + } + }, + { + LineNumber: 17, + Start: 479, + End: 480, + EndIncludingLineBreak: 481, + Span: { + Start: 479, + Length: 1 + }, + SpanIncludingLineBreak: { + Start: 479, + Length: 2 + } + }, + { + LineNumber: 18, + Start: 481, + End: 487, + EndIncludingLineBreak: 488, + Span: { + Start: 481, + Length: 6 + }, + SpanIncludingLineBreak: { + Start: 481, + Length: 7 + } + }, + { + LineNumber: 19, + Start: 488, + End: 488, + EndIncludingLineBreak: 488, + Span: { + Start: 488 + }, + SpanIncludingLineBreak: { + Start: 488 + } + } + ] + }, + HintName: __BuildVariables.g.cs + } + ], + Diagnostics: null +} \ No newline at end of file diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs index a86459dc7d..27b28adbce 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs @@ -1,4 +1,4 @@ -#if NET8_0_OR_GREATER && !__ANDROID__ && !__IOS__ +#if !__MOBILE__ && (NET8_0 || NET9_0) #nullable enable using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -11,14 +11,6 @@ namespace Sentry.Tests; public class BuildPropertySourceGeneratorTests { - [Fact] - public Task Driver_Success() - { - var driver = BuildDriver(typeof(Program).Assembly); - return Verify(driver); - } - - [Fact] public Task RunResult_Success() { @@ -87,9 +79,9 @@ file class MockAnalyzerConfigOptionsProvider(Dictionary buildPro { readonly MockAnalyzerConfigOptions options = new (buildProperties); - public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => this.options; - public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => this.options; - public override AnalyzerConfigOptions GlobalOptions => this.options; + public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => options; + public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => options; + public override AnalyzerConfigOptions GlobalOptions => options; } file class MockAnalyzerConfigOptions(Dictionary values) : AnalyzerConfigOptions diff --git a/test/Sentry.Tests/Sentry.Tests.csproj b/test/Sentry.Tests/Sentry.Tests.csproj index 5798e48fd1..5642a0910e 100644 --- a/test/Sentry.Tests/Sentry.Tests.csproj +++ b/test/Sentry.Tests/Sentry.Tests.csproj @@ -44,10 +44,9 @@ - + - From a9ca3d23f06f74ea453222b35db111e4d62fec85 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 24 Apr 2025 18:27:08 +0000 Subject: [PATCH 09/30] Format code --- test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs index 173b7a27e7..b272a17328 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs @@ -80,7 +80,7 @@ file class MockAnalyzerConfigOptionsProvider(Dictionary buildPro private readonly MockAnalyzerConfigOptions options = new(buildProperties); public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => options; - public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => options; + public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => options; public override AnalyzerConfigOptions GlobalOptions => options; } From f5ea7a28ab17031a5a6ad57173bbd0ad0979ac63 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 29 Apr 2025 09:16:10 -0400 Subject: [PATCH 10/30] code review fix --- samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj b/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj index 1b6d3e5436..f462c52a34 100644 --- a/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj +++ b/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj @@ -12,7 +12,7 @@ - From 194041f3b085f9aa8e5dd2537b7fb3bc7cd16515 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 29 Apr 2025 09:47:25 -0400 Subject: [PATCH 11/30] Update Sentry.SourceGenerators.csproj --- src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj b/src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj index 087c8ef2a6..047ca032ed 100644 --- a/src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj +++ b/src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj @@ -16,7 +16,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - From 4ebc989fa523617646015044692abc856a37a33b Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 29 Apr 2025 10:29:07 -0400 Subject: [PATCH 12/30] Update for unit tests --- .../BuildVariableSourceGenerator.cs | 47 +-- .../CompilerServices/BuildProperties.cs | 26 ++ src/Sentry/Internal/AotHelper.cs | 4 +- src/Sentry/SentrySdk.cs | 19 - ...torTests.RunResult_BadStrings.verified.txt | 357 +++++++++++------- ...sts.RunResult_Publish_AotTrue.verified.txt | 357 +++++++++++------- ...eratorTests.RunResult_Success.verified.txt | 357 +++++++++++------- .../BuildPropertySourceGeneratorTests.cs | 6 +- 8 files changed, 727 insertions(+), 446 deletions(-) create mode 100644 src/Sentry/CompilerServices/BuildProperties.cs diff --git a/src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs b/src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs index 2c0d679e5a..b0e1dbf09e 100644 --- a/src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs +++ b/src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs @@ -23,17 +23,11 @@ public void Initialize(GeneratorInitializationContext context) /// public void Execute(GeneratorExecutionContext context) { - // we'll wrap code in ifdef as it is safer than checking all of the various pieces involved here - // ((CSharpCompilation)context.Compilation).LanguageVersion == LanguageVersion.CSharp9 - var opts = context.AnalyzerConfigOptions.GlobalOptions; var properties = opts.Keys.Where(x => x.StartsWith("build_property.")).ToList(); if (properties.Count == 0) return; - if (!opts.TryGetValue("build_property.debugpropertycapture", out var debug) && (debug?.Equals("true", StringComparison.InvariantCultureIgnoreCase) ?? false)) - Debugger.Break(); - // we only want to generate code where host setup takes place if (!opts.TryGetValue("build_property.outputtype", out var outputType)) return; @@ -43,19 +37,30 @@ public void Execute(GeneratorExecutionContext context) var sb = new StringBuilder(); sb - .AppendLine("#if NET8_0_OR_GREATER") - .AppendLine("using System;") - .AppendLine("using System.Collections.Generic;") - .AppendLine() - .AppendLine("namespace Sentry;") - .AppendLine() - .AppendLine("[global::System.Runtime.CompilerServices.CompilerGenerated]") - .AppendLine("public static class BuildVariableInitializer") - .AppendLine("{") - .AppendLine("\t[global::System.Runtime.CompilerServices.ModuleInitializer]") - .AppendLine("\tpublic static void Initialize()") - .AppendLine("\t{") - .AppendLine("\t\tglobal::Sentry.SentrySdk.InitializeBuildVariables(new global::System.Collections.Generic.Dictionary {"); + .Append( +""" +// +// Code generated by Sentry Source Generators +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +#if NET8_0_OR_GREATER +using System; +using System.Collections.Generic; + +namespace Sentry; + +[global::System.Runtime.CompilerServices.CompilerGenerated] +public static class BuildVariableInitializer +{ + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::Sentry.CompilerServices.BuildProperties.Initialize(new global::System.Collections.Generic.Dictionary { + +""" + ); foreach (var property in properties) { @@ -66,7 +71,7 @@ public void Execute(GeneratorExecutionContext context) sb .Append("\t\t\t{") .Append($"\"{pn}\", \"{ev}\"") - .Append("},\r\n"); + .AppendLine("},"); } } @@ -76,7 +81,7 @@ public void Execute(GeneratorExecutionContext context) .AppendLine("}") .AppendLine("#endif"); - context.AddSource("__BuildVariables.g.cs", sb.ToString()); + context.AddSource("__BuildProperties.g.cs", sb.ToString()); } diff --git a/src/Sentry/CompilerServices/BuildProperties.cs b/src/Sentry/CompilerServices/BuildProperties.cs new file mode 100644 index 0000000000..d4cd7db07e --- /dev/null +++ b/src/Sentry/CompilerServices/BuildProperties.cs @@ -0,0 +1,26 @@ +using Sentry.Internal.Extensions; + +namespace Sentry.CompilerServices; + +/// +/// This class is not meant for external usage +/// +public static class BuildProperties +{ + /// + /// The Build Variables generated from you csproj file and initialized by the Sentry Source Generated Module Initializer + /// + public static IReadOnlyDictionary? Values { get; private set; } + + /// + /// This is called by a Sentry Source-Generator module initializers to help us determine things like + /// Is your app AOT + /// Has your application been trimmed + /// What build configuration is being used + /// + /// + public static void Initialize(Dictionary properties) + { + Values ??= properties.AsReadOnly(); + } +} diff --git a/src/Sentry/Internal/AotHelper.cs b/src/Sentry/Internal/AotHelper.cs index 17ea9a011f..83a500f9d5 100644 --- a/src/Sentry/Internal/AotHelper.cs +++ b/src/Sentry/Internal/AotHelper.cs @@ -1,3 +1,5 @@ +using Sentry.CompilerServices; + namespace Sentry.Internal; internal static class AotHelper @@ -28,7 +30,7 @@ private static bool CheckIsTrimmed() private static bool Check(string key) { - if (SentrySdk.BuildVariables?.TryGetValue(key, out var aotValue) ?? false) + if (BuildProperties.Values?.TryGetValue(key, out var aotValue) ?? false) { if (bool.TryParse(aotValue, out var result)) { diff --git a/src/Sentry/SentrySdk.cs b/src/Sentry/SentrySdk.cs index d587df33ad..1c7c688213 100644 --- a/src/Sentry/SentrySdk.cs +++ b/src/Sentry/SentrySdk.cs @@ -22,27 +22,8 @@ public static partial class SentrySdk { internal static IHub CurrentHub = DisabledHub.Instance; - /// - /// The Build Variables generated from you csproj file and initialized by the Sentry Source Generated Module Initializer - /// - public static IReadOnlyDictionary? BuildVariables { get; private set; } - internal static SentryOptions? CurrentOptions => CurrentHub.GetSentryOptions(); - - /// - /// This is called by a Sentry Source-Generator module initializers to help us determine things like - /// Is your app AOT - /// - /// - public static void InitializeBuildVariables(Dictionary variables) - { - if (BuildVariables == null) - { - BuildVariables = variables.AsReadOnly(); - } - } - /// /// Last event id recorded in the current scope. /// diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt index 22b3e3d75e..23d83df1b0 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt @@ -3,9 +3,9 @@ GeneratedSources: [ { SyntaxTree: { - FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildVariables.g.cs, + FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildProperties.g.cs, Encoding: utf-8, - Length: 490, + Length: 688, HasCompilationUnitRoot: true, Options: { LanguageVersion: CSharp12, @@ -17,6 +17,12 @@ SourceText: { Encoding: utf-8, Source: +// +// Code generated by Sentry Source Generators +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + #if NET8_0_OR_GREATER using System; using System.Collections.Generic; @@ -26,10 +32,10 @@ namespace Sentry; [global::System.Runtime.CompilerServices.CompilerGenerated] public static class BuildVariableInitializer { - [global::System.Runtime.CompilerServices.ModuleInitializer] - public static void Initialize() - { - global::Sentry.SentrySdk.InitializeBuildVariables(new global::System.Collections.Generic.Dictionary { + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::Sentry.CompilerServices.BuildProperties.Initialize(new global::System.Collections.Generic.Dictionary { {"My\\Key", "test\\test"}, {"OutputType", "exe"}, }); @@ -37,286 +43,369 @@ public static class BuildVariableInitializer } #endif , - Length: 490, + Length: 688, ChecksumAlgorithm: Sha1, CanBeEmbedded: true, Container: {}, Lines: [ { - End: 21, - EndIncludingLineBreak: 22, + End: 19, + EndIncludingLineBreak: 20, + Span: { + Length: 19 + }, + SpanIncludingLineBreak: { + Length: 20 + } + }, + { + LineNumber: 1, + Start: 20, + End: 65, + EndIncludingLineBreak: 66, + Span: { + Start: 20, + Length: 45 + }, + SpanIncludingLineBreak: { + Start: 20, + Length: 46 + } + }, + { + LineNumber: 2, + Start: 66, + End: 137, + EndIncludingLineBreak: 138, Span: { + Start: 66, + Length: 71 + }, + SpanIncludingLineBreak: { + Start: 66, + Length: 72 + } + }, + { + LineNumber: 3, + Start: 138, + End: 153, + EndIncludingLineBreak: 154, + Span: { + Start: 138, + Length: 15 + }, + SpanIncludingLineBreak: { + Start: 138, + Length: 16 + } + }, + { + LineNumber: 4, + Start: 154, + End: 174, + EndIncludingLineBreak: 175, + Span: { + Start: 154, + Length: 20 + }, + SpanIncludingLineBreak: { + Start: 154, Length: 21 + } + }, + { + LineNumber: 5, + Start: 175, + End: 175, + EndIncludingLineBreak: 176, + Span: { + Start: 175 }, SpanIncludingLineBreak: { + Start: 175, + Length: 1 + } + }, + { + LineNumber: 6, + Start: 176, + End: 197, + EndIncludingLineBreak: 198, + Span: { + Start: 176, + Length: 21 + }, + SpanIncludingLineBreak: { + Start: 176, Length: 22 } }, { - LineNumber: 1, - Start: 22, - End: 35, - EndIncludingLineBreak: 36, + LineNumber: 7, + Start: 198, + End: 211, + EndIncludingLineBreak: 212, Span: { - Start: 22, + Start: 198, Length: 13 }, SpanIncludingLineBreak: { - Start: 22, + Start: 198, Length: 14 } }, { - LineNumber: 2, - Start: 36, - End: 69, - EndIncludingLineBreak: 70, + LineNumber: 8, + Start: 212, + End: 245, + EndIncludingLineBreak: 246, Span: { - Start: 36, + Start: 212, Length: 33 }, SpanIncludingLineBreak: { - Start: 36, + Start: 212, Length: 34 } }, { - LineNumber: 3, - Start: 70, - End: 70, - EndIncludingLineBreak: 71, + LineNumber: 9, + Start: 246, + End: 246, + EndIncludingLineBreak: 247, Span: { - Start: 70 + Start: 246 }, SpanIncludingLineBreak: { - Start: 70, + Start: 246, Length: 1 } }, { - LineNumber: 4, - Start: 71, - End: 88, - EndIncludingLineBreak: 89, + LineNumber: 10, + Start: 247, + End: 264, + EndIncludingLineBreak: 265, Span: { - Start: 71, + Start: 247, Length: 17 }, SpanIncludingLineBreak: { - Start: 71, + Start: 247, Length: 18 } }, { - LineNumber: 5, - Start: 89, - End: 89, - EndIncludingLineBreak: 90, + LineNumber: 11, + Start: 265, + End: 265, + EndIncludingLineBreak: 266, Span: { - Start: 89 + Start: 265 }, SpanIncludingLineBreak: { - Start: 89, + Start: 265, Length: 1 } }, { - LineNumber: 6, - Start: 90, - End: 149, - EndIncludingLineBreak: 150, + LineNumber: 12, + Start: 266, + End: 325, + EndIncludingLineBreak: 326, Span: { - Start: 90, + Start: 266, Length: 59 }, SpanIncludingLineBreak: { - Start: 90, + Start: 266, Length: 60 } }, { - LineNumber: 7, - Start: 150, - End: 194, - EndIncludingLineBreak: 195, + LineNumber: 13, + Start: 326, + End: 370, + EndIncludingLineBreak: 371, Span: { - Start: 150, + Start: 326, Length: 44 }, SpanIncludingLineBreak: { - Start: 150, + Start: 326, Length: 45 } }, { - LineNumber: 8, - Start: 195, - End: 196, - EndIncludingLineBreak: 197, + LineNumber: 14, + Start: 371, + End: 372, + EndIncludingLineBreak: 373, Span: { - Start: 195, + Start: 371, Length: 1 }, SpanIncludingLineBreak: { - Start: 195, + Start: 371, Length: 2 } }, { - LineNumber: 9, - Start: 197, - End: 257, - EndIncludingLineBreak: 258, + LineNumber: 15, + Start: 373, + End: 436, + EndIncludingLineBreak: 437, Span: { - Start: 197, - Length: 60 + Start: 373, + Length: 63 }, SpanIncludingLineBreak: { - Start: 197, - Length: 61 + Start: 373, + Length: 64 } }, { - LineNumber: 10, - Start: 258, - End: 290, - EndIncludingLineBreak: 291, + LineNumber: 16, + Start: 437, + End: 472, + EndIncludingLineBreak: 473, Span: { - Start: 258, - Length: 32 + Start: 437, + Length: 35 }, SpanIncludingLineBreak: { - Start: 258, - Length: 33 + Start: 437, + Length: 36 } }, { - LineNumber: 11, - Start: 291, - End: 293, - EndIncludingLineBreak: 294, + LineNumber: 17, + Start: 473, + End: 478, + EndIncludingLineBreak: 479, Span: { - Start: 291, - Length: 2 + Start: 473, + Length: 5 }, SpanIncludingLineBreak: { - Start: 291, - Length: 3 + Start: 473, + Length: 6 } }, { - LineNumber: 12, - Start: 294, - End: 413, - EndIncludingLineBreak: 414, + LineNumber: 18, + Start: 479, + End: 613, + EndIncludingLineBreak: 614, Span: { - Start: 294, - Length: 119 + Start: 479, + Length: 134 }, SpanIncludingLineBreak: { - Start: 294, - Length: 120 + Start: 479, + Length: 135 } }, { - LineNumber: 13, - Start: 414, - End: 443, - EndIncludingLineBreak: 445, + LineNumber: 19, + Start: 614, + End: 643, + EndIncludingLineBreak: 644, Span: { - Start: 414, + Start: 614, Length: 29 }, SpanIncludingLineBreak: { - Start: 414, - Length: 31 + Start: 614, + Length: 30 } }, { - LineNumber: 14, - Start: 445, - End: 470, - EndIncludingLineBreak: 472, + LineNumber: 20, + Start: 644, + End: 669, + EndIncludingLineBreak: 670, Span: { - Start: 445, + Start: 644, Length: 25 }, SpanIncludingLineBreak: { - Start: 445, - Length: 27 + Start: 644, + Length: 26 } }, { - LineNumber: 15, - Start: 472, - End: 477, - EndIncludingLineBreak: 478, + LineNumber: 21, + Start: 670, + End: 675, + EndIncludingLineBreak: 676, Span: { - Start: 472, + Start: 670, Length: 5 }, SpanIncludingLineBreak: { - Start: 472, + Start: 670, Length: 6 } }, { - LineNumber: 16, - Start: 478, - End: 480, - EndIncludingLineBreak: 481, + LineNumber: 22, + Start: 676, + End: 678, + EndIncludingLineBreak: 679, Span: { - Start: 478, + Start: 676, Length: 2 }, SpanIncludingLineBreak: { - Start: 478, + Start: 676, Length: 3 } }, { - LineNumber: 17, - Start: 481, - End: 482, - EndIncludingLineBreak: 483, + LineNumber: 23, + Start: 679, + End: 680, + EndIncludingLineBreak: 681, Span: { - Start: 481, + Start: 679, Length: 1 }, SpanIncludingLineBreak: { - Start: 481, + Start: 679, Length: 2 } }, { - LineNumber: 18, - Start: 483, - End: 489, - EndIncludingLineBreak: 490, + LineNumber: 24, + Start: 681, + End: 687, + EndIncludingLineBreak: 688, Span: { - Start: 483, + Start: 681, Length: 6 }, SpanIncludingLineBreak: { - Start: 483, + Start: 681, Length: 7 } }, { - LineNumber: 19, - Start: 490, - End: 490, - EndIncludingLineBreak: 490, + LineNumber: 25, + Start: 688, + End: 688, + EndIncludingLineBreak: 688, Span: { - Start: 490 + Start: 688 }, SpanIncludingLineBreak: { - Start: 490 + Start: 688 } } ] }, - HintName: __BuildVariables.g.cs + HintName: __BuildProperties.g.cs } ], Diagnostics: null diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt index cc40131f65..0114136523 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt @@ -3,9 +3,9 @@ GeneratedSources: [ { SyntaxTree: { - FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildVariables.g.cs, + FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildProperties.g.cs, Encoding: utf-8, - Length: 487, + Length: 685, HasCompilationUnitRoot: true, Options: { LanguageVersion: CSharp12, @@ -17,6 +17,12 @@ SourceText: { Encoding: utf-8, Source: +// +// Code generated by Sentry Source Generators +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + #if NET8_0_OR_GREATER using System; using System.Collections.Generic; @@ -26,10 +32,10 @@ namespace Sentry; [global::System.Runtime.CompilerServices.CompilerGenerated] public static class BuildVariableInitializer { - [global::System.Runtime.CompilerServices.ModuleInitializer] - public static void Initialize() - { - global::Sentry.SentrySdk.InitializeBuildVariables(new global::System.Collections.Generic.Dictionary { + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::Sentry.CompilerServices.BuildProperties.Initialize(new global::System.Collections.Generic.Dictionary { {"PublishAot", "true"}, {"OutputType", "exe"}, }); @@ -37,286 +43,369 @@ public static class BuildVariableInitializer } #endif , - Length: 487, + Length: 685, ChecksumAlgorithm: Sha1, CanBeEmbedded: true, Container: {}, Lines: [ { - End: 21, - EndIncludingLineBreak: 22, + End: 19, + EndIncludingLineBreak: 20, + Span: { + Length: 19 + }, + SpanIncludingLineBreak: { + Length: 20 + } + }, + { + LineNumber: 1, + Start: 20, + End: 65, + EndIncludingLineBreak: 66, + Span: { + Start: 20, + Length: 45 + }, + SpanIncludingLineBreak: { + Start: 20, + Length: 46 + } + }, + { + LineNumber: 2, + Start: 66, + End: 137, + EndIncludingLineBreak: 138, + Span: { + Start: 66, + Length: 71 + }, + SpanIncludingLineBreak: { + Start: 66, + Length: 72 + } + }, + { + LineNumber: 3, + Start: 138, + End: 153, + EndIncludingLineBreak: 154, + Span: { + Start: 138, + Length: 15 + }, + SpanIncludingLineBreak: { + Start: 138, + Length: 16 + } + }, + { + LineNumber: 4, + Start: 154, + End: 174, + EndIncludingLineBreak: 175, + Span: { + Start: 154, + Length: 20 + }, + SpanIncludingLineBreak: { + Start: 154, + Length: 21 + } + }, + { + LineNumber: 5, + Start: 175, + End: 175, + EndIncludingLineBreak: 176, + Span: { + Start: 175 + }, + SpanIncludingLineBreak: { + Start: 175, + Length: 1 + } + }, + { + LineNumber: 6, + Start: 176, + End: 197, + EndIncludingLineBreak: 198, Span: { + Start: 176, Length: 21 }, SpanIncludingLineBreak: { + Start: 176, Length: 22 } }, { - LineNumber: 1, - Start: 22, - End: 35, - EndIncludingLineBreak: 36, + LineNumber: 7, + Start: 198, + End: 211, + EndIncludingLineBreak: 212, Span: { - Start: 22, + Start: 198, Length: 13 }, SpanIncludingLineBreak: { - Start: 22, + Start: 198, Length: 14 } }, { - LineNumber: 2, - Start: 36, - End: 69, - EndIncludingLineBreak: 70, + LineNumber: 8, + Start: 212, + End: 245, + EndIncludingLineBreak: 246, Span: { - Start: 36, + Start: 212, Length: 33 }, SpanIncludingLineBreak: { - Start: 36, + Start: 212, Length: 34 } }, { - LineNumber: 3, - Start: 70, - End: 70, - EndIncludingLineBreak: 71, + LineNumber: 9, + Start: 246, + End: 246, + EndIncludingLineBreak: 247, Span: { - Start: 70 + Start: 246 }, SpanIncludingLineBreak: { - Start: 70, + Start: 246, Length: 1 } }, { - LineNumber: 4, - Start: 71, - End: 88, - EndIncludingLineBreak: 89, + LineNumber: 10, + Start: 247, + End: 264, + EndIncludingLineBreak: 265, Span: { - Start: 71, + Start: 247, Length: 17 }, SpanIncludingLineBreak: { - Start: 71, + Start: 247, Length: 18 } }, { - LineNumber: 5, - Start: 89, - End: 89, - EndIncludingLineBreak: 90, + LineNumber: 11, + Start: 265, + End: 265, + EndIncludingLineBreak: 266, Span: { - Start: 89 + Start: 265 }, SpanIncludingLineBreak: { - Start: 89, + Start: 265, Length: 1 } }, { - LineNumber: 6, - Start: 90, - End: 149, - EndIncludingLineBreak: 150, + LineNumber: 12, + Start: 266, + End: 325, + EndIncludingLineBreak: 326, Span: { - Start: 90, + Start: 266, Length: 59 }, SpanIncludingLineBreak: { - Start: 90, + Start: 266, Length: 60 } }, { - LineNumber: 7, - Start: 150, - End: 194, - EndIncludingLineBreak: 195, + LineNumber: 13, + Start: 326, + End: 370, + EndIncludingLineBreak: 371, Span: { - Start: 150, + Start: 326, Length: 44 }, SpanIncludingLineBreak: { - Start: 150, + Start: 326, Length: 45 } }, { - LineNumber: 8, - Start: 195, - End: 196, - EndIncludingLineBreak: 197, + LineNumber: 14, + Start: 371, + End: 372, + EndIncludingLineBreak: 373, Span: { - Start: 195, + Start: 371, Length: 1 }, SpanIncludingLineBreak: { - Start: 195, + Start: 371, Length: 2 } }, { - LineNumber: 9, - Start: 197, - End: 257, - EndIncludingLineBreak: 258, + LineNumber: 15, + Start: 373, + End: 436, + EndIncludingLineBreak: 437, Span: { - Start: 197, - Length: 60 + Start: 373, + Length: 63 }, SpanIncludingLineBreak: { - Start: 197, - Length: 61 + Start: 373, + Length: 64 } }, { - LineNumber: 10, - Start: 258, - End: 290, - EndIncludingLineBreak: 291, + LineNumber: 16, + Start: 437, + End: 472, + EndIncludingLineBreak: 473, Span: { - Start: 258, - Length: 32 + Start: 437, + Length: 35 }, SpanIncludingLineBreak: { - Start: 258, - Length: 33 + Start: 437, + Length: 36 } }, { - LineNumber: 11, - Start: 291, - End: 293, - EndIncludingLineBreak: 294, + LineNumber: 17, + Start: 473, + End: 478, + EndIncludingLineBreak: 479, Span: { - Start: 291, - Length: 2 + Start: 473, + Length: 5 }, SpanIncludingLineBreak: { - Start: 291, - Length: 3 + Start: 473, + Length: 6 } }, { - LineNumber: 12, - Start: 294, - End: 413, - EndIncludingLineBreak: 414, + LineNumber: 18, + Start: 479, + End: 613, + EndIncludingLineBreak: 614, Span: { - Start: 294, - Length: 119 + Start: 479, + Length: 134 }, SpanIncludingLineBreak: { - Start: 294, - Length: 120 + Start: 479, + Length: 135 } }, { - LineNumber: 13, - Start: 414, - End: 440, - EndIncludingLineBreak: 442, + LineNumber: 19, + Start: 614, + End: 640, + EndIncludingLineBreak: 641, Span: { - Start: 414, + Start: 614, Length: 26 }, SpanIncludingLineBreak: { - Start: 414, - Length: 28 + Start: 614, + Length: 27 } }, { - LineNumber: 14, - Start: 442, - End: 467, - EndIncludingLineBreak: 469, + LineNumber: 20, + Start: 641, + End: 666, + EndIncludingLineBreak: 667, Span: { - Start: 442, + Start: 641, Length: 25 }, SpanIncludingLineBreak: { - Start: 442, - Length: 27 + Start: 641, + Length: 26 } }, { - LineNumber: 15, - Start: 469, - End: 474, - EndIncludingLineBreak: 475, + LineNumber: 21, + Start: 667, + End: 672, + EndIncludingLineBreak: 673, Span: { - Start: 469, + Start: 667, Length: 5 }, SpanIncludingLineBreak: { - Start: 469, + Start: 667, Length: 6 } }, { - LineNumber: 16, - Start: 475, - End: 477, - EndIncludingLineBreak: 478, + LineNumber: 22, + Start: 673, + End: 675, + EndIncludingLineBreak: 676, Span: { - Start: 475, + Start: 673, Length: 2 }, SpanIncludingLineBreak: { - Start: 475, + Start: 673, Length: 3 } }, { - LineNumber: 17, - Start: 478, - End: 479, - EndIncludingLineBreak: 480, + LineNumber: 23, + Start: 676, + End: 677, + EndIncludingLineBreak: 678, Span: { - Start: 478, + Start: 676, Length: 1 }, SpanIncludingLineBreak: { - Start: 478, + Start: 676, Length: 2 } }, { - LineNumber: 18, - Start: 480, - End: 486, - EndIncludingLineBreak: 487, + LineNumber: 24, + Start: 678, + End: 684, + EndIncludingLineBreak: 685, Span: { - Start: 480, + Start: 678, Length: 6 }, SpanIncludingLineBreak: { - Start: 480, + Start: 678, Length: 7 } }, { - LineNumber: 19, - Start: 487, - End: 487, - EndIncludingLineBreak: 487, + LineNumber: 25, + Start: 685, + End: 685, + EndIncludingLineBreak: 685, Span: { - Start: 487 + Start: 685 }, SpanIncludingLineBreak: { - Start: 487 + Start: 685 } } ] }, - HintName: __BuildVariables.g.cs + HintName: __BuildProperties.g.cs } ], Diagnostics: null diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt index dddefc506c..db6ee0f7a7 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt @@ -3,9 +3,9 @@ GeneratedSources: [ { SyntaxTree: { - FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildVariables.g.cs, + FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildProperties.g.cs, Encoding: utf-8, - Length: 488, + Length: 686, HasCompilationUnitRoot: true, Options: { LanguageVersion: CSharp12, @@ -17,6 +17,12 @@ SourceText: { Encoding: utf-8, Source: +// +// Code generated by Sentry Source Generators +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + #if NET8_0_OR_GREATER using System; using System.Collections.Generic; @@ -26,10 +32,10 @@ namespace Sentry; [global::System.Runtime.CompilerServices.CompilerGenerated] public static class BuildVariableInitializer { - [global::System.Runtime.CompilerServices.ModuleInitializer] - public static void Initialize() - { - global::Sentry.SentrySdk.InitializeBuildVariables(new global::System.Collections.Generic.Dictionary { + [global::System.Runtime.CompilerServices.ModuleInitializer] + public static void Initialize() + { + global::Sentry.CompilerServices.BuildProperties.Initialize(new global::System.Collections.Generic.Dictionary { {"PublishAot", "false"}, {"OutputType", "exe"}, }); @@ -37,286 +43,369 @@ public static class BuildVariableInitializer } #endif , - Length: 488, + Length: 686, ChecksumAlgorithm: Sha1, CanBeEmbedded: true, Container: {}, Lines: [ { - End: 21, - EndIncludingLineBreak: 22, + End: 19, + EndIncludingLineBreak: 20, + Span: { + Length: 19 + }, + SpanIncludingLineBreak: { + Length: 20 + } + }, + { + LineNumber: 1, + Start: 20, + End: 65, + EndIncludingLineBreak: 66, + Span: { + Start: 20, + Length: 45 + }, + SpanIncludingLineBreak: { + Start: 20, + Length: 46 + } + }, + { + LineNumber: 2, + Start: 66, + End: 137, + EndIncludingLineBreak: 138, + Span: { + Start: 66, + Length: 71 + }, + SpanIncludingLineBreak: { + Start: 66, + Length: 72 + } + }, + { + LineNumber: 3, + Start: 138, + End: 153, + EndIncludingLineBreak: 154, + Span: { + Start: 138, + Length: 15 + }, + SpanIncludingLineBreak: { + Start: 138, + Length: 16 + } + }, + { + LineNumber: 4, + Start: 154, + End: 174, + EndIncludingLineBreak: 175, + Span: { + Start: 154, + Length: 20 + }, + SpanIncludingLineBreak: { + Start: 154, + Length: 21 + } + }, + { + LineNumber: 5, + Start: 175, + End: 175, + EndIncludingLineBreak: 176, + Span: { + Start: 175 + }, + SpanIncludingLineBreak: { + Start: 175, + Length: 1 + } + }, + { + LineNumber: 6, + Start: 176, + End: 197, + EndIncludingLineBreak: 198, Span: { + Start: 176, Length: 21 }, SpanIncludingLineBreak: { + Start: 176, Length: 22 } }, { - LineNumber: 1, - Start: 22, - End: 35, - EndIncludingLineBreak: 36, + LineNumber: 7, + Start: 198, + End: 211, + EndIncludingLineBreak: 212, Span: { - Start: 22, + Start: 198, Length: 13 }, SpanIncludingLineBreak: { - Start: 22, + Start: 198, Length: 14 } }, { - LineNumber: 2, - Start: 36, - End: 69, - EndIncludingLineBreak: 70, + LineNumber: 8, + Start: 212, + End: 245, + EndIncludingLineBreak: 246, Span: { - Start: 36, + Start: 212, Length: 33 }, SpanIncludingLineBreak: { - Start: 36, + Start: 212, Length: 34 } }, { - LineNumber: 3, - Start: 70, - End: 70, - EndIncludingLineBreak: 71, + LineNumber: 9, + Start: 246, + End: 246, + EndIncludingLineBreak: 247, Span: { - Start: 70 + Start: 246 }, SpanIncludingLineBreak: { - Start: 70, + Start: 246, Length: 1 } }, { - LineNumber: 4, - Start: 71, - End: 88, - EndIncludingLineBreak: 89, + LineNumber: 10, + Start: 247, + End: 264, + EndIncludingLineBreak: 265, Span: { - Start: 71, + Start: 247, Length: 17 }, SpanIncludingLineBreak: { - Start: 71, + Start: 247, Length: 18 } }, { - LineNumber: 5, - Start: 89, - End: 89, - EndIncludingLineBreak: 90, + LineNumber: 11, + Start: 265, + End: 265, + EndIncludingLineBreak: 266, Span: { - Start: 89 + Start: 265 }, SpanIncludingLineBreak: { - Start: 89, + Start: 265, Length: 1 } }, { - LineNumber: 6, - Start: 90, - End: 149, - EndIncludingLineBreak: 150, + LineNumber: 12, + Start: 266, + End: 325, + EndIncludingLineBreak: 326, Span: { - Start: 90, + Start: 266, Length: 59 }, SpanIncludingLineBreak: { - Start: 90, + Start: 266, Length: 60 } }, { - LineNumber: 7, - Start: 150, - End: 194, - EndIncludingLineBreak: 195, + LineNumber: 13, + Start: 326, + End: 370, + EndIncludingLineBreak: 371, Span: { - Start: 150, + Start: 326, Length: 44 }, SpanIncludingLineBreak: { - Start: 150, + Start: 326, Length: 45 } }, { - LineNumber: 8, - Start: 195, - End: 196, - EndIncludingLineBreak: 197, + LineNumber: 14, + Start: 371, + End: 372, + EndIncludingLineBreak: 373, Span: { - Start: 195, + Start: 371, Length: 1 }, SpanIncludingLineBreak: { - Start: 195, + Start: 371, Length: 2 } }, { - LineNumber: 9, - Start: 197, - End: 257, - EndIncludingLineBreak: 258, + LineNumber: 15, + Start: 373, + End: 436, + EndIncludingLineBreak: 437, Span: { - Start: 197, - Length: 60 + Start: 373, + Length: 63 }, SpanIncludingLineBreak: { - Start: 197, - Length: 61 + Start: 373, + Length: 64 } }, { - LineNumber: 10, - Start: 258, - End: 290, - EndIncludingLineBreak: 291, + LineNumber: 16, + Start: 437, + End: 472, + EndIncludingLineBreak: 473, Span: { - Start: 258, - Length: 32 + Start: 437, + Length: 35 }, SpanIncludingLineBreak: { - Start: 258, - Length: 33 + Start: 437, + Length: 36 } }, { - LineNumber: 11, - Start: 291, - End: 293, - EndIncludingLineBreak: 294, + LineNumber: 17, + Start: 473, + End: 478, + EndIncludingLineBreak: 479, Span: { - Start: 291, - Length: 2 + Start: 473, + Length: 5 }, SpanIncludingLineBreak: { - Start: 291, - Length: 3 + Start: 473, + Length: 6 } }, { - LineNumber: 12, - Start: 294, - End: 413, - EndIncludingLineBreak: 414, + LineNumber: 18, + Start: 479, + End: 613, + EndIncludingLineBreak: 614, Span: { - Start: 294, - Length: 119 + Start: 479, + Length: 134 }, SpanIncludingLineBreak: { - Start: 294, - Length: 120 + Start: 479, + Length: 135 } }, { - LineNumber: 13, - Start: 414, - End: 441, - EndIncludingLineBreak: 443, + LineNumber: 19, + Start: 614, + End: 641, + EndIncludingLineBreak: 642, Span: { - Start: 414, + Start: 614, Length: 27 }, SpanIncludingLineBreak: { - Start: 414, - Length: 29 + Start: 614, + Length: 28 } }, { - LineNumber: 14, - Start: 443, - End: 468, - EndIncludingLineBreak: 470, + LineNumber: 20, + Start: 642, + End: 667, + EndIncludingLineBreak: 668, Span: { - Start: 443, + Start: 642, Length: 25 }, SpanIncludingLineBreak: { - Start: 443, - Length: 27 + Start: 642, + Length: 26 } }, { - LineNumber: 15, - Start: 470, - End: 475, - EndIncludingLineBreak: 476, + LineNumber: 21, + Start: 668, + End: 673, + EndIncludingLineBreak: 674, Span: { - Start: 470, + Start: 668, Length: 5 }, SpanIncludingLineBreak: { - Start: 470, + Start: 668, Length: 6 } }, { - LineNumber: 16, - Start: 476, - End: 478, - EndIncludingLineBreak: 479, + LineNumber: 22, + Start: 674, + End: 676, + EndIncludingLineBreak: 677, Span: { - Start: 476, + Start: 674, Length: 2 }, SpanIncludingLineBreak: { - Start: 476, + Start: 674, Length: 3 } }, { - LineNumber: 17, - Start: 479, - End: 480, - EndIncludingLineBreak: 481, + LineNumber: 23, + Start: 677, + End: 678, + EndIncludingLineBreak: 679, Span: { - Start: 479, + Start: 677, Length: 1 }, SpanIncludingLineBreak: { - Start: 479, + Start: 677, Length: 2 } }, { - LineNumber: 18, - Start: 481, - End: 487, - EndIncludingLineBreak: 488, + LineNumber: 24, + Start: 679, + End: 685, + EndIncludingLineBreak: 686, Span: { - Start: 481, + Start: 679, Length: 6 }, SpanIncludingLineBreak: { - Start: 481, + Start: 679, Length: 7 } }, { - LineNumber: 19, - Start: 488, - End: 488, - EndIncludingLineBreak: 488, + LineNumber: 25, + Start: 686, + End: 686, + EndIncludingLineBreak: 686, Span: { - Start: 488 + Start: 686 }, SpanIncludingLineBreak: { - Start: 488 + Start: 686 } } ] }, - HintName: __BuildVariables.g.cs + HintName: __BuildProperties.g.cs } ], Diagnostics: null diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs index b272a17328..01ac592ead 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs @@ -18,7 +18,7 @@ public Task RunResult_Success() var result = driver.GetRunResult().Results.FirstOrDefault(); result.Exception.Should().BeNull(); result.GeneratedSources.Length.Should().Be(1); - result.GeneratedSources.First().HintName.Should().Be("__BuildVariables.g.cs"); + result.GeneratedSources.First().HintName.Should().Be("__BuildProperties.g.cs"); return Verify(result); } @@ -31,7 +31,7 @@ public Task RunResult_BadStrings() var result = driver.GetRunResult().Results.FirstOrDefault(); result.Exception.Should().BeNull(); result.GeneratedSources.Length.Should().Be(1); - result.GeneratedSources.First().HintName.Should().Be("__BuildVariables.g.cs"); + result.GeneratedSources.First().HintName.Should().Be("__BuildProperties.g.cs"); return Verify(result); } @@ -43,7 +43,7 @@ public Task RunResult_Publish_AotTrue() var result = driver.GetRunResult().Results.FirstOrDefault(); result.Exception.Should().BeNull(); result.GeneratedSources.Length.Should().Be(1); - result.GeneratedSources.First().HintName.Should().Be("__BuildVariables.g.cs"); + result.GeneratedSources.First().HintName.Should().Be("__BuildProperties.g.cs"); return Verify(result); } From bc99a75682107793554260fe15fcfd19b9829098 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 29 Apr 2025 10:35:00 -0400 Subject: [PATCH 13/30] Fixes and name alignments --- samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj | 2 +- samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj | 4 ++-- .../Sentry.Samples.MacCatalyst.csproj | 4 ++-- samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj | 2 +- ...ableSourceGenerator.cs => BuildPropertySourceGenerator.cs} | 0 5 files changed, 6 insertions(+), 6 deletions(-) rename src/Sentry.SourceGenerators/{BuildVariableSourceGenerator.cs => BuildPropertySourceGenerator.cs} (100%) diff --git a/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj b/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj index f462c52a34..61fcb9bc31 100644 --- a/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj +++ b/samples/Sentry.Samples.Android/Sentry.Samples.Android.csproj @@ -44,5 +44,5 @@ - + diff --git a/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj b/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj index fca65f940f..25f4b66c46 100644 --- a/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj +++ b/samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj @@ -44,11 +44,11 @@ - - + diff --git a/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj b/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj index 72f57e291c..e48c894e34 100644 --- a/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj +++ b/samples/Sentry.Samples.MacCatalyst/Sentry.Samples.MacCatalyst.csproj @@ -44,11 +44,11 @@ - - + diff --git a/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj b/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj index 0d46333008..007984df42 100644 --- a/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj +++ b/samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj @@ -113,5 +113,5 @@ - + diff --git a/src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs b/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs similarity index 100% rename from src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs rename to src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs From 4547af6438643af1bde28d27e82a3d12176fbb48 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 29 Apr 2025 10:47:11 -0400 Subject: [PATCH 14/30] Fix bad bot changes --- test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs index 01ac592ead..f8237d2dbf 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs @@ -77,7 +77,7 @@ private static GeneratorDriver BuildDriver(Assembly metadataAssembly, params IEn file class MockAnalyzerConfigOptionsProvider(Dictionary buildProperties) : AnalyzerConfigOptionsProvider { - private readonly MockAnalyzerConfigOptions options = new(buildProperties); + readonly MockAnalyzerConfigOptions options = new (buildProperties); public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => options; public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => options; From ca53bc4b87884696745bd9d328d23298d54189d6 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 29 Apr 2025 11:03:44 -0400 Subject: [PATCH 15/30] Add disable sentry changes per code review as well as unit tests for it --- .../BuildPropertySourceGenerator.cs | 3 +++ .../Sentry.SourceGenerators.targets | 2 +- src/Sentry/buildTransitive/Sentry.targets | 2 +- .../BuildPropertySourceGeneratorTests.cs | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs b/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs index b0e1dbf09e..d7f843d66e 100644 --- a/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs +++ b/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs @@ -28,6 +28,9 @@ public void Execute(GeneratorExecutionContext context) if (properties.Count == 0) return; + if (opts.TryGetValue("build_property.SentryDisableSourceGenerator", out var disable) && disable.Equals("true", StringComparison.InvariantCultureIgnoreCase)) + return; + // we only want to generate code where host setup takes place if (!opts.TryGetValue("build_property.outputtype", out var outputType)) return; diff --git a/src/Sentry/buildTransitive/Sentry.SourceGenerators.targets b/src/Sentry/buildTransitive/Sentry.SourceGenerators.targets index 244f5e38e7..292d49e34b 100644 --- a/src/Sentry/buildTransitive/Sentry.SourceGenerators.targets +++ b/src/Sentry/buildTransitive/Sentry.SourceGenerators.targets @@ -3,7 +3,7 @@ - + diff --git a/src/Sentry/buildTransitive/Sentry.targets b/src/Sentry/buildTransitive/Sentry.targets index f8a14d8bd4..58338dbbd0 100644 --- a/src/Sentry/buildTransitive/Sentry.targets +++ b/src/Sentry/buildTransitive/Sentry.targets @@ -9,7 +9,7 @@ - + diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs index f8237d2dbf..8e304f475c 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs @@ -48,6 +48,21 @@ public Task RunResult_Publish_AotTrue() } + [Theory] + [InlineData("no", true)] + [InlineData("true", false)] + [InlineData("false", true)] + public void RunResult_SentryDisableSourceGenerator_Values(string value, bool sourceGenExpected) + { + var driver = BuildDriver(typeof(Program).Assembly, ("SentryDisableSourceGenerator", value), ("OutputType", "exe")); + var result = driver.GetRunResult().Results.FirstOrDefault(); + result.Exception.Should().BeNull(); + + var generated = result.GeneratedSources.Any(x => x.HintName.Equals("__BuildProperties.g.cs")); + generated.Should().Be(sourceGenExpected); + } + + [Fact] public Task RunResult_Expect_None() { From 800c7bf4c4168acf284da6a75f06c90eebd09092 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 29 Apr 2025 11:05:26 -0400 Subject: [PATCH 16/30] Try to revert bad bot --- test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs index 8e304f475c..1a38f530c5 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs @@ -92,11 +92,11 @@ private static GeneratorDriver BuildDriver(Assembly metadataAssembly, params IEn file class MockAnalyzerConfigOptionsProvider(Dictionary buildProperties) : AnalyzerConfigOptionsProvider { - readonly MockAnalyzerConfigOptions options = new (buildProperties); + private readonly MockAnalyzerConfigOptions _options = new (buildProperties); - public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => options; - public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => options; - public override AnalyzerConfigOptions GlobalOptions => options; + public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => _options; + public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => _options; + public override AnalyzerConfigOptions GlobalOptions => _options; } file class MockAnalyzerConfigOptions(Dictionary values) : AnalyzerConfigOptions From 214abdad88c73b8f6649afb4f7508fe2d7f06f0d Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 29 Apr 2025 15:23:32 +0000 Subject: [PATCH 17/30] Format code --- test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs index 1a38f530c5..218524c0d9 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs @@ -92,7 +92,7 @@ private static GeneratorDriver BuildDriver(Assembly metadataAssembly, params IEn file class MockAnalyzerConfigOptionsProvider(Dictionary buildProperties) : AnalyzerConfigOptionsProvider { - private readonly MockAnalyzerConfigOptions _options = new (buildProperties); + private readonly MockAnalyzerConfigOptions _options = new(buildProperties); public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => _options; public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => _options; From 852c4cad4246bbdfc4bd3770e8220ba683b1f9b4 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Wed, 30 Apr 2025 09:28:23 -0400 Subject: [PATCH 18/30] Done --- .../BuildPropertySourceGenerator.cs | 14 ++++++++++---- test/Sentry.Tests/Sentry.Tests.csproj | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs b/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs index d7f843d66e..7110b4f3a7 100644 --- a/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs +++ b/src/Sentry.SourceGenerators/BuildPropertySourceGenerator.cs @@ -26,17 +26,26 @@ public void Execute(GeneratorExecutionContext context) var opts = context.AnalyzerConfigOptions.GlobalOptions; var properties = opts.Keys.Where(x => x.StartsWith("build_property.")).ToList(); if (properties.Count == 0) + { return; + } - if (opts.TryGetValue("build_property.SentryDisableSourceGenerator", out var disable) && disable.Equals("true", StringComparison.InvariantCultureIgnoreCase)) + if (opts.TryGetValue("build_property.SentryDisableSourceGenerator", out var disable) && + disable.Equals("true", StringComparison.InvariantCultureIgnoreCase)) + { return; + } // we only want to generate code where host setup takes place if (!opts.TryGetValue("build_property.outputtype", out var outputType)) + { return; + } if (!outputType.Equals("exe", StringComparison.InvariantCultureIgnoreCase)) + { return; + } var sb = new StringBuilder(); sb @@ -49,9 +58,6 @@ public void Execute(GeneratorExecutionContext context) // #if NET8_0_OR_GREATER -using System; -using System.Collections.Generic; - namespace Sentry; [global::System.Runtime.CompilerServices.CompilerGenerated] diff --git a/test/Sentry.Tests/Sentry.Tests.csproj b/test/Sentry.Tests/Sentry.Tests.csproj index 5642a0910e..06cacd10f4 100644 --- a/test/Sentry.Tests/Sentry.Tests.csproj +++ b/test/Sentry.Tests/Sentry.Tests.csproj @@ -43,7 +43,7 @@ - + From 1c436bf60ef14512735d41e6730963bbea787e03 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Wed, 30 Apr 2025 09:29:09 -0400 Subject: [PATCH 19/30] Update CHANGELOG.md Co-authored-by: Bruno Garcia --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75618163a2..3421d56ff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - New source generator allows Sentry to see true build variables like PublishAot and PublishTrimmed to properly adapt checks in the Sentry SDK ([#4101](https://github.com/getsentry/sentry-dotnet/pull/4101)) + ### Features - Custom SessionReplay masks in MAUI Android apps ([#4121](https://github.com/getsentry/sentry-dotnet/pull/4121)) From 6f71d500ea815a0be81ec5cb7788802cca74c8fc Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Wed, 30 Apr 2025 09:33:45 -0400 Subject: [PATCH 20/30] Update SentrySdk.cs --- src/Sentry/SentrySdk.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Sentry/SentrySdk.cs b/src/Sentry/SentrySdk.cs index bd49f4e5f4..00ade61140 100644 --- a/src/Sentry/SentrySdk.cs +++ b/src/Sentry/SentrySdk.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; using Sentry.Extensibility; using Sentry.Infrastructure; using Sentry.Internal; From a21c92cffedcd5e7d9af9d13c9a8630712b3fcaf Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Thu, 1 May 2025 13:19:22 -0400 Subject: [PATCH 21/30] Update slnf as stated in CI :| --- .generated.NoMobile.sln | 14 +++++++------- Sentry-CI-Build-Linux.slnf | 1 + Sentry-CI-Build-Windows.slnf | 1 + Sentry-CI-Build-macOS.slnf | 1 + Sentry-CI-CodeQL.slnf | 1 + SentryMobile.slnf | 3 +-- SentryNoMobile.slnf | 4 ++-- SentryNoSamples.slnf | 1 + 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.generated.NoMobile.sln b/.generated.NoMobile.sln index 09f5325835..40806dc53b 100644 --- a/.generated.NoMobile.sln +++ b/.generated.NoMobile.sln @@ -170,7 +170,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Hangfire", "src\Sent EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Hangfire.Tests", "test\Sentry.Hangfire.Tests\Sentry.Hangfire.Tests.csproj", "{46E40BE8-1AB0-4846-B0A2-A40AD0272C64}" EndProject -Project("{00000000-0000-0000-0000-000000000000}") = "Sentry.Samples.AspNetCore.WebAPI.Profiling", "samples\Sentry.Samples.AspNetCore.WebAPI.Profiling\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "{A5B26C14-7313-4EDC-91E3-287F9374AB75}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.AspNetCore.WebAPI.Profiling", "samples\Sentry.Samples.AspNetCore.WebAPI.Profiling\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj", "{A5B26C14-7313-4EDC-91E3-287F9374AB75}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{233D34AB-970E-4913-AA1E-172E833FB5B2}" ProjectSection(SolutionItems) = preProject @@ -197,7 +197,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.TrimTest", "test\Sen EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.MauiTrimTest", "test\Sentry.MauiTrimTest\Sentry.MauiTrimTest.csproj", "{DF92E098-822C-4B94-B96B-56BFB91FBB54}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators", "src\Sentry.SourceGenerators\Sentry.SourceGenerators.csproj", "{E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators", "src\Sentry.SourceGenerators\Sentry.SourceGenerators.csproj", "{C3CDF61C-3E28-441C-A9CE-011C89D11719}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -534,10 +534,10 @@ Global {DF92E098-822C-4B94-B96B-56BFB91FBB54}.Debug|Any CPU.Build.0 = Debug|Any CPU {DF92E098-822C-4B94-B96B-56BFB91FBB54}.Release|Any CPU.ActiveCfg = Release|Any CPU {DF92E098-822C-4B94-B96B-56BFB91FBB54}.Release|Any CPU.Build.0 = Release|Any CPU - {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1}.Release|Any CPU.Build.0 = Release|Any CPU + {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -625,6 +625,6 @@ Global {D7DF0B26-AD43-4F8B-9BFE-C4471CCC9821} = {21B42F60-5802-404E-90F0-AEBCC56760C0} {6030B748-0000-43B5-B8A8-399AA42F5229} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {DF92E098-822C-4B94-B96B-56BFB91FBB54} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} - {E9B3DA59-E0FB-4CA6-93AC-05F0F5AD83E1} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} + {C3CDF61C-3E28-441C-A9CE-011C89D11719} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} EndGlobalSection EndGlobal diff --git a/Sentry-CI-Build-Linux.slnf b/Sentry-CI-Build-Linux.slnf index 06a3bafeea..701cca4bdb 100644 --- a/Sentry-CI-Build-Linux.slnf +++ b/Sentry-CI-Build-Linux.slnf @@ -49,6 +49,7 @@ "src\\Sentry.OpenTelemetry\\Sentry.OpenTelemetry.csproj", "src\\Sentry.Profiling\\Sentry.Profiling.csproj", "src\\Sentry.Serilog\\Sentry.Serilog.csproj", + "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj", "test\\Sentry.Analyzers.Tests\\Sentry.Analyzers.Tests.csproj", "test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj", diff --git a/Sentry-CI-Build-Windows.slnf b/Sentry-CI-Build-Windows.slnf index 1ad751775d..cb6cf4b77a 100644 --- a/Sentry-CI-Build-Windows.slnf +++ b/Sentry-CI-Build-Windows.slnf @@ -51,6 +51,7 @@ "src\\Sentry.OpenTelemetry\\Sentry.OpenTelemetry.csproj", "src\\Sentry.Profiling\\Sentry.Profiling.csproj", "src\\Sentry.Serilog\\Sentry.Serilog.csproj", + "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj", "test\\Sentry.Analyzers.Tests\\Sentry.Analyzers.Tests.csproj", "test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj", diff --git a/Sentry-CI-Build-macOS.slnf b/Sentry-CI-Build-macOS.slnf index 7857558117..ffa30fe1a6 100644 --- a/Sentry-CI-Build-macOS.slnf +++ b/Sentry-CI-Build-macOS.slnf @@ -56,6 +56,7 @@ "src\\Sentry.OpenTelemetry\\Sentry.OpenTelemetry.csproj", "src\\Sentry.Profiling\\Sentry.Profiling.csproj", "src\\Sentry.Serilog\\Sentry.Serilog.csproj", + "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj", "test\\Sentry.Analyzers.Tests\\Sentry.Analyzers.Tests.csproj", "test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj", diff --git a/Sentry-CI-CodeQL.slnf b/Sentry-CI-CodeQL.slnf index 44eb07a6e4..be252d4fe2 100644 --- a/Sentry-CI-CodeQL.slnf +++ b/Sentry-CI-CodeQL.slnf @@ -20,6 +20,7 @@ "src\\Sentry.OpenTelemetry\\Sentry.OpenTelemetry.csproj", "src\\Sentry.Profiling\\Sentry.Profiling.csproj", "src\\Sentry.Serilog\\Sentry.Serilog.csproj", + "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj" ] } diff --git a/SentryMobile.slnf b/SentryMobile.slnf index 8f14531395..c38fa573cc 100644 --- a/SentryMobile.slnf +++ b/SentryMobile.slnf @@ -12,7 +12,6 @@ "src\\Sentry.Bindings.Cocoa\\Sentry.Bindings.Cocoa.csproj", "src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj", "src\\Sentry.Maui\\Sentry.Maui.csproj", - "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj", "test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj", "test\\Sentry.Extensions.Logging.Tests\\Sentry.Extensions.Logging.Tests.csproj", @@ -22,4 +21,4 @@ "test\\Sentry.Tests\\Sentry.Tests.csproj" ] } -} \ No newline at end of file +} diff --git a/SentryNoMobile.slnf b/SentryNoMobile.slnf index 3960b05c00..269265e63e 100644 --- a/SentryNoMobile.slnf +++ b/SentryNoMobile.slnf @@ -32,10 +32,10 @@ "samples\\Sentry.Samples.OpenTelemetry.Console\\Sentry.Samples.OpenTelemetry.Console.csproj", "samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj", "src\\Sentry.Analyzers\\Sentry.Analyzers.csproj", + "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.AspNetCore.Blazor.WebAssembly\\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj", "src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj", - "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj", "src\\Sentry.DiagnosticSource\\Sentry.DiagnosticSource.csproj", "src\\Sentry.EntityFramework\\Sentry.EntityFramework.csproj", @@ -72,4 +72,4 @@ "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } -} \ No newline at end of file +} diff --git a/SentryNoSamples.slnf b/SentryNoSamples.slnf index 66ce4d76a5..e66cd71ff5 100644 --- a/SentryNoSamples.slnf +++ b/SentryNoSamples.slnf @@ -21,6 +21,7 @@ "src\\Sentry.OpenTelemetry\\Sentry.OpenTelemetry.csproj", "src\\Sentry.Profiling\\Sentry.Profiling.csproj", "src\\Sentry.Serilog\\Sentry.Serilog.csproj", + "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj", "test\\Sentry.Analyzers.Tests\\Sentry.Analyzers.Tests.csproj", "test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj", From f82ee972bd2ac7f47949dc350759932b5f0ab5b5 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Fri, 2 May 2025 11:46:20 -0400 Subject: [PATCH 22/30] update verify tests --- ...torTests.RunResult_BadStrings.verified.txt | 234 +++++++----------- ...sts.RunResult_Publish_AotTrue.verified.txt | 234 +++++++----------- ...eratorTests.RunResult_Success.verified.txt | 234 +++++++----------- 3 files changed, 285 insertions(+), 417 deletions(-) diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt index 23d83df1b0..94298c45c3 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt @@ -5,7 +5,7 @@ SyntaxTree: { FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildProperties.g.cs, Encoding: utf-8, - Length: 688, + Length: 639, HasCompilationUnitRoot: true, Options: { LanguageVersion: CSharp12, @@ -24,9 +24,6 @@ // #if NET8_0_OR_GREATER -using System; -using System.Collections.Generic; - namespace Sentry; [global::System.Runtime.CompilerServices.CompilerGenerated] @@ -43,7 +40,7 @@ public static class BuildVariableInitializer } #endif , - Length: 688, + Length: 639, ChecksumAlgorithm: Sha1, CanBeEmbedded: true, Container: {}, @@ -144,263 +141,222 @@ public static class BuildVariableInitializer { LineNumber: 7, Start: 198, - End: 211, - EndIncludingLineBreak: 212, + End: 215, + EndIncludingLineBreak: 216, Span: { Start: 198, - Length: 13 - }, - SpanIncludingLineBreak: { - Start: 198, - Length: 14 - } - }, - { - LineNumber: 8, - Start: 212, - End: 245, - EndIncludingLineBreak: 246, - Span: { - Start: 212, - Length: 33 - }, - SpanIncludingLineBreak: { - Start: 212, - Length: 34 - } - }, - { - LineNumber: 9, - Start: 246, - End: 246, - EndIncludingLineBreak: 247, - Span: { - Start: 246 - }, - SpanIncludingLineBreak: { - Start: 246, - Length: 1 - } - }, - { - LineNumber: 10, - Start: 247, - End: 264, - EndIncludingLineBreak: 265, - Span: { - Start: 247, Length: 17 }, SpanIncludingLineBreak: { - Start: 247, + Start: 198, Length: 18 } }, { - LineNumber: 11, - Start: 265, - End: 265, - EndIncludingLineBreak: 266, + LineNumber: 8, + Start: 216, + End: 216, + EndIncludingLineBreak: 217, Span: { - Start: 265 + Start: 216 }, SpanIncludingLineBreak: { - Start: 265, + Start: 216, Length: 1 } }, { - LineNumber: 12, - Start: 266, - End: 325, - EndIncludingLineBreak: 326, + LineNumber: 9, + Start: 217, + End: 276, + EndIncludingLineBreak: 277, Span: { - Start: 266, + Start: 217, Length: 59 }, SpanIncludingLineBreak: { - Start: 266, + Start: 217, Length: 60 } }, { - LineNumber: 13, - Start: 326, - End: 370, - EndIncludingLineBreak: 371, + LineNumber: 10, + Start: 277, + End: 321, + EndIncludingLineBreak: 322, Span: { - Start: 326, + Start: 277, Length: 44 }, SpanIncludingLineBreak: { - Start: 326, + Start: 277, Length: 45 } }, { - LineNumber: 14, - Start: 371, - End: 372, - EndIncludingLineBreak: 373, + LineNumber: 11, + Start: 322, + End: 323, + EndIncludingLineBreak: 324, Span: { - Start: 371, + Start: 322, Length: 1 }, SpanIncludingLineBreak: { - Start: 371, + Start: 322, Length: 2 } }, { - LineNumber: 15, - Start: 373, - End: 436, - EndIncludingLineBreak: 437, + LineNumber: 12, + Start: 324, + End: 387, + EndIncludingLineBreak: 388, Span: { - Start: 373, + Start: 324, Length: 63 }, SpanIncludingLineBreak: { - Start: 373, + Start: 324, Length: 64 } }, { - LineNumber: 16, - Start: 437, - End: 472, - EndIncludingLineBreak: 473, + LineNumber: 13, + Start: 388, + End: 423, + EndIncludingLineBreak: 424, Span: { - Start: 437, + Start: 388, Length: 35 }, SpanIncludingLineBreak: { - Start: 437, + Start: 388, Length: 36 } }, { - LineNumber: 17, - Start: 473, - End: 478, - EndIncludingLineBreak: 479, + LineNumber: 14, + Start: 424, + End: 429, + EndIncludingLineBreak: 430, Span: { - Start: 473, + Start: 424, Length: 5 }, SpanIncludingLineBreak: { - Start: 473, + Start: 424, Length: 6 } }, { - LineNumber: 18, - Start: 479, - End: 613, - EndIncludingLineBreak: 614, + LineNumber: 15, + Start: 430, + End: 564, + EndIncludingLineBreak: 565, Span: { - Start: 479, + Start: 430, Length: 134 }, SpanIncludingLineBreak: { - Start: 479, + Start: 430, Length: 135 } }, { - LineNumber: 19, - Start: 614, - End: 643, - EndIncludingLineBreak: 644, + LineNumber: 16, + Start: 565, + End: 594, + EndIncludingLineBreak: 595, Span: { - Start: 614, + Start: 565, Length: 29 }, SpanIncludingLineBreak: { - Start: 614, + Start: 565, Length: 30 } }, { - LineNumber: 20, - Start: 644, - End: 669, - EndIncludingLineBreak: 670, + LineNumber: 17, + Start: 595, + End: 620, + EndIncludingLineBreak: 621, Span: { - Start: 644, + Start: 595, Length: 25 }, SpanIncludingLineBreak: { - Start: 644, + Start: 595, Length: 26 } }, { - LineNumber: 21, - Start: 670, - End: 675, - EndIncludingLineBreak: 676, + LineNumber: 18, + Start: 621, + End: 626, + EndIncludingLineBreak: 627, Span: { - Start: 670, + Start: 621, Length: 5 }, SpanIncludingLineBreak: { - Start: 670, + Start: 621, Length: 6 } }, { - LineNumber: 22, - Start: 676, - End: 678, - EndIncludingLineBreak: 679, + LineNumber: 19, + Start: 627, + End: 629, + EndIncludingLineBreak: 630, Span: { - Start: 676, + Start: 627, Length: 2 }, SpanIncludingLineBreak: { - Start: 676, + Start: 627, Length: 3 } }, { - LineNumber: 23, - Start: 679, - End: 680, - EndIncludingLineBreak: 681, + LineNumber: 20, + Start: 630, + End: 631, + EndIncludingLineBreak: 632, Span: { - Start: 679, + Start: 630, Length: 1 }, SpanIncludingLineBreak: { - Start: 679, + Start: 630, Length: 2 } }, { - LineNumber: 24, - Start: 681, - End: 687, - EndIncludingLineBreak: 688, + LineNumber: 21, + Start: 632, + End: 638, + EndIncludingLineBreak: 639, Span: { - Start: 681, + Start: 632, Length: 6 }, SpanIncludingLineBreak: { - Start: 681, + Start: 632, Length: 7 } }, { - LineNumber: 25, - Start: 688, - End: 688, - EndIncludingLineBreak: 688, + LineNumber: 22, + Start: 639, + End: 639, + EndIncludingLineBreak: 639, Span: { - Start: 688 + Start: 639 }, SpanIncludingLineBreak: { - Start: 688 + Start: 639 } } ] diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt index 0114136523..37b44b9ecd 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt @@ -5,7 +5,7 @@ SyntaxTree: { FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildProperties.g.cs, Encoding: utf-8, - Length: 685, + Length: 636, HasCompilationUnitRoot: true, Options: { LanguageVersion: CSharp12, @@ -24,9 +24,6 @@ // #if NET8_0_OR_GREATER -using System; -using System.Collections.Generic; - namespace Sentry; [global::System.Runtime.CompilerServices.CompilerGenerated] @@ -43,7 +40,7 @@ public static class BuildVariableInitializer } #endif , - Length: 685, + Length: 636, ChecksumAlgorithm: Sha1, CanBeEmbedded: true, Container: {}, @@ -144,263 +141,222 @@ public static class BuildVariableInitializer { LineNumber: 7, Start: 198, - End: 211, - EndIncludingLineBreak: 212, + End: 215, + EndIncludingLineBreak: 216, Span: { Start: 198, - Length: 13 - }, - SpanIncludingLineBreak: { - Start: 198, - Length: 14 - } - }, - { - LineNumber: 8, - Start: 212, - End: 245, - EndIncludingLineBreak: 246, - Span: { - Start: 212, - Length: 33 - }, - SpanIncludingLineBreak: { - Start: 212, - Length: 34 - } - }, - { - LineNumber: 9, - Start: 246, - End: 246, - EndIncludingLineBreak: 247, - Span: { - Start: 246 - }, - SpanIncludingLineBreak: { - Start: 246, - Length: 1 - } - }, - { - LineNumber: 10, - Start: 247, - End: 264, - EndIncludingLineBreak: 265, - Span: { - Start: 247, Length: 17 }, SpanIncludingLineBreak: { - Start: 247, + Start: 198, Length: 18 } }, { - LineNumber: 11, - Start: 265, - End: 265, - EndIncludingLineBreak: 266, + LineNumber: 8, + Start: 216, + End: 216, + EndIncludingLineBreak: 217, Span: { - Start: 265 + Start: 216 }, SpanIncludingLineBreak: { - Start: 265, + Start: 216, Length: 1 } }, { - LineNumber: 12, - Start: 266, - End: 325, - EndIncludingLineBreak: 326, + LineNumber: 9, + Start: 217, + End: 276, + EndIncludingLineBreak: 277, Span: { - Start: 266, + Start: 217, Length: 59 }, SpanIncludingLineBreak: { - Start: 266, + Start: 217, Length: 60 } }, { - LineNumber: 13, - Start: 326, - End: 370, - EndIncludingLineBreak: 371, + LineNumber: 10, + Start: 277, + End: 321, + EndIncludingLineBreak: 322, Span: { - Start: 326, + Start: 277, Length: 44 }, SpanIncludingLineBreak: { - Start: 326, + Start: 277, Length: 45 } }, { - LineNumber: 14, - Start: 371, - End: 372, - EndIncludingLineBreak: 373, + LineNumber: 11, + Start: 322, + End: 323, + EndIncludingLineBreak: 324, Span: { - Start: 371, + Start: 322, Length: 1 }, SpanIncludingLineBreak: { - Start: 371, + Start: 322, Length: 2 } }, { - LineNumber: 15, - Start: 373, - End: 436, - EndIncludingLineBreak: 437, + LineNumber: 12, + Start: 324, + End: 387, + EndIncludingLineBreak: 388, Span: { - Start: 373, + Start: 324, Length: 63 }, SpanIncludingLineBreak: { - Start: 373, + Start: 324, Length: 64 } }, { - LineNumber: 16, - Start: 437, - End: 472, - EndIncludingLineBreak: 473, + LineNumber: 13, + Start: 388, + End: 423, + EndIncludingLineBreak: 424, Span: { - Start: 437, + Start: 388, Length: 35 }, SpanIncludingLineBreak: { - Start: 437, + Start: 388, Length: 36 } }, { - LineNumber: 17, - Start: 473, - End: 478, - EndIncludingLineBreak: 479, + LineNumber: 14, + Start: 424, + End: 429, + EndIncludingLineBreak: 430, Span: { - Start: 473, + Start: 424, Length: 5 }, SpanIncludingLineBreak: { - Start: 473, + Start: 424, Length: 6 } }, { - LineNumber: 18, - Start: 479, - End: 613, - EndIncludingLineBreak: 614, + LineNumber: 15, + Start: 430, + End: 564, + EndIncludingLineBreak: 565, Span: { - Start: 479, + Start: 430, Length: 134 }, SpanIncludingLineBreak: { - Start: 479, + Start: 430, Length: 135 } }, { - LineNumber: 19, - Start: 614, - End: 640, - EndIncludingLineBreak: 641, + LineNumber: 16, + Start: 565, + End: 591, + EndIncludingLineBreak: 592, Span: { - Start: 614, + Start: 565, Length: 26 }, SpanIncludingLineBreak: { - Start: 614, + Start: 565, Length: 27 } }, { - LineNumber: 20, - Start: 641, - End: 666, - EndIncludingLineBreak: 667, + LineNumber: 17, + Start: 592, + End: 617, + EndIncludingLineBreak: 618, Span: { - Start: 641, + Start: 592, Length: 25 }, SpanIncludingLineBreak: { - Start: 641, + Start: 592, Length: 26 } }, { - LineNumber: 21, - Start: 667, - End: 672, - EndIncludingLineBreak: 673, + LineNumber: 18, + Start: 618, + End: 623, + EndIncludingLineBreak: 624, Span: { - Start: 667, + Start: 618, Length: 5 }, SpanIncludingLineBreak: { - Start: 667, + Start: 618, Length: 6 } }, { - LineNumber: 22, - Start: 673, - End: 675, - EndIncludingLineBreak: 676, + LineNumber: 19, + Start: 624, + End: 626, + EndIncludingLineBreak: 627, Span: { - Start: 673, + Start: 624, Length: 2 }, SpanIncludingLineBreak: { - Start: 673, + Start: 624, Length: 3 } }, { - LineNumber: 23, - Start: 676, - End: 677, - EndIncludingLineBreak: 678, + LineNumber: 20, + Start: 627, + End: 628, + EndIncludingLineBreak: 629, Span: { - Start: 676, + Start: 627, Length: 1 }, SpanIncludingLineBreak: { - Start: 676, + Start: 627, Length: 2 } }, { - LineNumber: 24, - Start: 678, - End: 684, - EndIncludingLineBreak: 685, + LineNumber: 21, + Start: 629, + End: 635, + EndIncludingLineBreak: 636, Span: { - Start: 678, + Start: 629, Length: 6 }, SpanIncludingLineBreak: { - Start: 678, + Start: 629, Length: 7 } }, { - LineNumber: 25, - Start: 685, - End: 685, - EndIncludingLineBreak: 685, + LineNumber: 22, + Start: 636, + End: 636, + EndIncludingLineBreak: 636, Span: { - Start: 685 + Start: 636 }, SpanIncludingLineBreak: { - Start: 685 + Start: 636 } } ] diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt index db6ee0f7a7..ff9d84c52d 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt +++ b/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt @@ -5,7 +5,7 @@ SyntaxTree: { FilePath: Sentry.SourceGenerators/Sentry.SourceGenerators.BuildPropertySourceGenerator/__BuildProperties.g.cs, Encoding: utf-8, - Length: 686, + Length: 637, HasCompilationUnitRoot: true, Options: { LanguageVersion: CSharp12, @@ -24,9 +24,6 @@ // #if NET8_0_OR_GREATER -using System; -using System.Collections.Generic; - namespace Sentry; [global::System.Runtime.CompilerServices.CompilerGenerated] @@ -43,7 +40,7 @@ public static class BuildVariableInitializer } #endif , - Length: 686, + Length: 637, ChecksumAlgorithm: Sha1, CanBeEmbedded: true, Container: {}, @@ -144,263 +141,222 @@ public static class BuildVariableInitializer { LineNumber: 7, Start: 198, - End: 211, - EndIncludingLineBreak: 212, + End: 215, + EndIncludingLineBreak: 216, Span: { Start: 198, - Length: 13 - }, - SpanIncludingLineBreak: { - Start: 198, - Length: 14 - } - }, - { - LineNumber: 8, - Start: 212, - End: 245, - EndIncludingLineBreak: 246, - Span: { - Start: 212, - Length: 33 - }, - SpanIncludingLineBreak: { - Start: 212, - Length: 34 - } - }, - { - LineNumber: 9, - Start: 246, - End: 246, - EndIncludingLineBreak: 247, - Span: { - Start: 246 - }, - SpanIncludingLineBreak: { - Start: 246, - Length: 1 - } - }, - { - LineNumber: 10, - Start: 247, - End: 264, - EndIncludingLineBreak: 265, - Span: { - Start: 247, Length: 17 }, SpanIncludingLineBreak: { - Start: 247, + Start: 198, Length: 18 } }, { - LineNumber: 11, - Start: 265, - End: 265, - EndIncludingLineBreak: 266, + LineNumber: 8, + Start: 216, + End: 216, + EndIncludingLineBreak: 217, Span: { - Start: 265 + Start: 216 }, SpanIncludingLineBreak: { - Start: 265, + Start: 216, Length: 1 } }, { - LineNumber: 12, - Start: 266, - End: 325, - EndIncludingLineBreak: 326, + LineNumber: 9, + Start: 217, + End: 276, + EndIncludingLineBreak: 277, Span: { - Start: 266, + Start: 217, Length: 59 }, SpanIncludingLineBreak: { - Start: 266, + Start: 217, Length: 60 } }, { - LineNumber: 13, - Start: 326, - End: 370, - EndIncludingLineBreak: 371, + LineNumber: 10, + Start: 277, + End: 321, + EndIncludingLineBreak: 322, Span: { - Start: 326, + Start: 277, Length: 44 }, SpanIncludingLineBreak: { - Start: 326, + Start: 277, Length: 45 } }, { - LineNumber: 14, - Start: 371, - End: 372, - EndIncludingLineBreak: 373, + LineNumber: 11, + Start: 322, + End: 323, + EndIncludingLineBreak: 324, Span: { - Start: 371, + Start: 322, Length: 1 }, SpanIncludingLineBreak: { - Start: 371, + Start: 322, Length: 2 } }, { - LineNumber: 15, - Start: 373, - End: 436, - EndIncludingLineBreak: 437, + LineNumber: 12, + Start: 324, + End: 387, + EndIncludingLineBreak: 388, Span: { - Start: 373, + Start: 324, Length: 63 }, SpanIncludingLineBreak: { - Start: 373, + Start: 324, Length: 64 } }, { - LineNumber: 16, - Start: 437, - End: 472, - EndIncludingLineBreak: 473, + LineNumber: 13, + Start: 388, + End: 423, + EndIncludingLineBreak: 424, Span: { - Start: 437, + Start: 388, Length: 35 }, SpanIncludingLineBreak: { - Start: 437, + Start: 388, Length: 36 } }, { - LineNumber: 17, - Start: 473, - End: 478, - EndIncludingLineBreak: 479, + LineNumber: 14, + Start: 424, + End: 429, + EndIncludingLineBreak: 430, Span: { - Start: 473, + Start: 424, Length: 5 }, SpanIncludingLineBreak: { - Start: 473, + Start: 424, Length: 6 } }, { - LineNumber: 18, - Start: 479, - End: 613, - EndIncludingLineBreak: 614, + LineNumber: 15, + Start: 430, + End: 564, + EndIncludingLineBreak: 565, Span: { - Start: 479, + Start: 430, Length: 134 }, SpanIncludingLineBreak: { - Start: 479, + Start: 430, Length: 135 } }, { - LineNumber: 19, - Start: 614, - End: 641, - EndIncludingLineBreak: 642, + LineNumber: 16, + Start: 565, + End: 592, + EndIncludingLineBreak: 593, Span: { - Start: 614, + Start: 565, Length: 27 }, SpanIncludingLineBreak: { - Start: 614, + Start: 565, Length: 28 } }, { - LineNumber: 20, - Start: 642, - End: 667, - EndIncludingLineBreak: 668, + LineNumber: 17, + Start: 593, + End: 618, + EndIncludingLineBreak: 619, Span: { - Start: 642, + Start: 593, Length: 25 }, SpanIncludingLineBreak: { - Start: 642, + Start: 593, Length: 26 } }, { - LineNumber: 21, - Start: 668, - End: 673, - EndIncludingLineBreak: 674, + LineNumber: 18, + Start: 619, + End: 624, + EndIncludingLineBreak: 625, Span: { - Start: 668, + Start: 619, Length: 5 }, SpanIncludingLineBreak: { - Start: 668, + Start: 619, Length: 6 } }, { - LineNumber: 22, - Start: 674, - End: 676, - EndIncludingLineBreak: 677, + LineNumber: 19, + Start: 625, + End: 627, + EndIncludingLineBreak: 628, Span: { - Start: 674, + Start: 625, Length: 2 }, SpanIncludingLineBreak: { - Start: 674, + Start: 625, Length: 3 } }, { - LineNumber: 23, - Start: 677, - End: 678, - EndIncludingLineBreak: 679, + LineNumber: 20, + Start: 628, + End: 629, + EndIncludingLineBreak: 630, Span: { - Start: 677, + Start: 628, Length: 1 }, SpanIncludingLineBreak: { - Start: 677, + Start: 628, Length: 2 } }, { - LineNumber: 24, - Start: 679, - End: 685, - EndIncludingLineBreak: 686, + LineNumber: 21, + Start: 630, + End: 636, + EndIncludingLineBreak: 637, Span: { - Start: 679, + Start: 630, Length: 6 }, SpanIncludingLineBreak: { - Start: 679, + Start: 630, Length: 7 } }, { - LineNumber: 25, - Start: 686, - End: 686, - EndIncludingLineBreak: 686, + LineNumber: 22, + Start: 637, + End: 637, + EndIncludingLineBreak: 637, Span: { - Start: 686 + Start: 637 }, SpanIncludingLineBreak: { - Start: 686 + Start: 637 } } ] From 15f244ec2e40c676bf4cbc83523a28bf60e18488 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Fri, 2 May 2025 11:49:41 -0400 Subject: [PATCH 23/30] Finally forced these to update --- .../ApiApprovalTests.Run.DotNet8_0.verified.txt | 8 ++++++++ .../ApiApprovalTests.Run.DotNet9_0.verified.txt | 8 ++++++++ .../Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt index 925a97874c..f70df81000 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt @@ -1285,6 +1285,14 @@ namespace Sentry.Ben.BlockingDetector public void Dispose() { } } } +namespace Sentry.CompilerServices +{ + public static class BuildProperties + { + public static System.Collections.Generic.IReadOnlyDictionary? Values { get; } + public static void Initialize(System.Collections.Generic.Dictionary properties) { } + } +} namespace Sentry.Extensibility { public abstract class BaseRequestPayloadExtractor : Sentry.Extensibility.IRequestPayloadExtractor diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt index 925a97874c..f70df81000 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt @@ -1285,6 +1285,14 @@ namespace Sentry.Ben.BlockingDetector public void Dispose() { } } } +namespace Sentry.CompilerServices +{ + public static class BuildProperties + { + public static System.Collections.Generic.IReadOnlyDictionary? Values { get; } + public static void Initialize(System.Collections.Generic.Dictionary properties) { } + } +} namespace Sentry.Extensibility { public abstract class BaseRequestPayloadExtractor : Sentry.Extensibility.IRequestPayloadExtractor diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt index 583b80f350..3060d147e9 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt @@ -1266,6 +1266,14 @@ namespace Sentry.Ben.BlockingDetector public void Dispose() { } } } +namespace Sentry.CompilerServices +{ + public static class BuildProperties + { + public static System.Collections.Generic.IReadOnlyDictionary? Values { get; } + public static void Initialize(System.Collections.Generic.Dictionary properties) { } + } +} namespace Sentry.Extensibility { public abstract class BaseRequestPayloadExtractor : Sentry.Extensibility.IRequestPayloadExtractor From 86d8f4b83881c2a5c156f8cd0c5b16342c910b90 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Fri, 2 May 2025 13:25:12 -0400 Subject: [PATCH 24/30] Ensure source generator isn't included as reference --- test/Sentry.Tests/Sentry.Tests.csproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Sentry.Tests/Sentry.Tests.csproj b/test/Sentry.Tests/Sentry.Tests.csproj index 06cacd10f4..2763e09896 100644 --- a/test/Sentry.Tests/Sentry.Tests.csproj +++ b/test/Sentry.Tests/Sentry.Tests.csproj @@ -44,7 +44,9 @@ - + From 79f185f96c6997f0c1ae28dd063a20f3b4d261e3 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Fri, 2 May 2025 13:42:33 -0400 Subject: [PATCH 25/30] Moving to its own project --- Sentry.sln | 7 ++++++ SentryMobile.slnf | 4 +++- ...torTests.RunResult_BadStrings.verified.txt | 0 ...orTests.RunResult_Expect_None.verified.txt | 0 ...sts.RunResult_Publish_AotTrue.verified.txt | 0 ...eratorTests.RunResult_Success.verified.txt | 0 .../BuildPropertySourceGeneratorTests.cs | 3 --- .../Sentry.SourceGenerators.Tests.csproj | 22 +++++++++++++++++++ test/Sentry.Tests/Sentry.Tests.csproj | 9 -------- 9 files changed, 32 insertions(+), 13 deletions(-) rename test/{Sentry.Tests => Sentry.SourceGenerators.Tests}/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt (100%) rename test/{Sentry.Tests => Sentry.SourceGenerators.Tests}/BuildPropertySourceGeneratorTests.RunResult_Expect_None.verified.txt (100%) rename test/{Sentry.Tests => Sentry.SourceGenerators.Tests}/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt (100%) rename test/{Sentry.Tests => Sentry.SourceGenerators.Tests}/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt (100%) rename test/{Sentry.Tests => Sentry.SourceGenerators.Tests}/BuildPropertySourceGeneratorTests.cs (98%) create mode 100644 test/Sentry.SourceGenerators.Tests/Sentry.SourceGenerators.Tests.csproj diff --git a/Sentry.sln b/Sentry.sln index 40806dc53b..ea50adc690 100644 --- a/Sentry.sln +++ b/Sentry.sln @@ -199,6 +199,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.MauiTrimTest", "test EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators", "src\Sentry.SourceGenerators\Sentry.SourceGenerators.csproj", "{C3CDF61C-3E28-441C-A9CE-011C89D11719}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators.Tests", "test\Sentry.SourceGenerators.Tests\Sentry.SourceGenerators.Tests.csproj", "{3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -538,6 +540,10 @@ Global {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Debug|Any CPU.Build.0 = Debug|Any CPU {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.ActiveCfg = Release|Any CPU {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.Build.0 = Release|Any CPU + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -626,5 +632,6 @@ Global {6030B748-0000-43B5-B8A8-399AA42F5229} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {DF92E098-822C-4B94-B96B-56BFB91FBB54} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {C3CDF61C-3E28-441C-A9CE-011C89D11719} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} EndGlobalSection EndGlobal diff --git a/SentryMobile.slnf b/SentryMobile.slnf index c38fa573cc..2e015d740e 100644 --- a/SentryMobile.slnf +++ b/SentryMobile.slnf @@ -12,13 +12,15 @@ "src\\Sentry.Bindings.Cocoa\\Sentry.Bindings.Cocoa.csproj", "src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj", "src\\Sentry.Maui\\Sentry.Maui.csproj", + "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj", "test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj", "test\\Sentry.Extensions.Logging.Tests\\Sentry.Extensions.Logging.Tests.csproj", "test\\Sentry.Maui.Device.TestApp\\Sentry.Maui.Device.TestApp.csproj", "test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj", + "test\\Sentry.SourceGenerators.Tests\\Sentry.SourceGenerators.Tests.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj" ] } -} +} \ No newline at end of file diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt similarity index 100% rename from test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt rename to test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_BadStrings.verified.txt diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Expect_None.verified.txt b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Expect_None.verified.txt similarity index 100% rename from test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Expect_None.verified.txt rename to test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Expect_None.verified.txt diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt similarity index 100% rename from test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt rename to test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Publish_AotTrue.verified.txt diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt similarity index 100% rename from test/Sentry.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt rename to test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.RunResult_Success.verified.txt diff --git a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs similarity index 98% rename from test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs rename to test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs index 218524c0d9..5fb146c14c 100644 --- a/test/Sentry.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs @@ -1,5 +1,3 @@ -#if !__MOBILE__ && (NET8_0 || NET9_0) -#nullable enable using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; @@ -106,4 +104,3 @@ public override bool TryGetValue(string key, [NotNullWhen(true)] out string? val public override IEnumerable Keys => values.Keys; } -#endif diff --git a/test/Sentry.SourceGenerators.Tests/Sentry.SourceGenerators.Tests.csproj b/test/Sentry.SourceGenerators.Tests/Sentry.SourceGenerators.Tests.csproj new file mode 100644 index 0000000000..820c77dd05 --- /dev/null +++ b/test/Sentry.SourceGenerators.Tests/Sentry.SourceGenerators.Tests.csproj @@ -0,0 +1,22 @@ + + + + net9.0;net8.0 + enable + enable + + + + + + + + + + + + + + + + diff --git a/test/Sentry.Tests/Sentry.Tests.csproj b/test/Sentry.Tests/Sentry.Tests.csproj index 2763e09896..d2e0edd2a5 100644 --- a/test/Sentry.Tests/Sentry.Tests.csproj +++ b/test/Sentry.Tests/Sentry.Tests.csproj @@ -42,13 +42,4 @@ - - - - - - - From 5c7927d8ad2bacd6598ac693daeaa1b04068955d Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Fri, 2 May 2025 13:45:20 -0400 Subject: [PATCH 26/30] Update slnf --- .generated.NoMobile.sln | 7 +++++++ SentryNoMobile.slnf | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.generated.NoMobile.sln b/.generated.NoMobile.sln index 40806dc53b..39b67a016f 100644 --- a/.generated.NoMobile.sln +++ b/.generated.NoMobile.sln @@ -199,6 +199,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.MauiTrimTest", "test EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators", "src\Sentry.SourceGenerators\Sentry.SourceGenerators.csproj", "{C3CDF61C-3E28-441C-A9CE-011C89D11719}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators.Tests", "test\Sentry.SourceGenerators.Tests\Sentry.SourceGenerators.Tests.csproj", "{2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -538,6 +540,10 @@ Global {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Debug|Any CPU.Build.0 = Debug|Any CPU {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.ActiveCfg = Release|Any CPU {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.Build.0 = Release|Any CPU + {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -626,5 +632,6 @@ Global {6030B748-0000-43B5-B8A8-399AA42F5229} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {DF92E098-822C-4B94-B96B-56BFB91FBB54} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {C3CDF61C-3E28-441C-A9CE-011C89D11719} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} + {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} EndGlobalSection EndGlobal diff --git a/SentryNoMobile.slnf b/SentryNoMobile.slnf index 269265e63e..c51e7da02f 100644 --- a/SentryNoMobile.slnf +++ b/SentryNoMobile.slnf @@ -32,10 +32,10 @@ "samples\\Sentry.Samples.OpenTelemetry.Console\\Sentry.Samples.OpenTelemetry.Console.csproj", "samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj", "src\\Sentry.Analyzers\\Sentry.Analyzers.csproj", - "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.AspNetCore.Blazor.WebAssembly\\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj", "src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj", + "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj", "src\\Sentry.DiagnosticSource\\Sentry.DiagnosticSource.csproj", "src\\Sentry.EntityFramework\\Sentry.EntityFramework.csproj", @@ -66,10 +66,11 @@ "test\\Sentry.OpenTelemetry.Tests\\Sentry.OpenTelemetry.Tests.csproj", "test\\Sentry.Profiling.Tests\\Sentry.Profiling.Tests.csproj", "test\\Sentry.Serilog.Tests\\Sentry.Serilog.Tests.csproj", + "test\\Sentry.SourceGenerators.Tests\\Sentry.SourceGenerators.Tests.csproj", "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } -} +} \ No newline at end of file From d9da82d1d790cf725531964dc830ef5eab3a1559 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Fri, 2 May 2025 14:24:51 -0400 Subject: [PATCH 27/30] Update solution filters --- .generated.NoMobile.sln | 12 ++++++------ Sentry-CI-Build-Linux.slnf | 1 + Sentry-CI-Build-Windows.slnf | 1 + Sentry-CI-Build-macOS.slnf | 1 + SentryMobile.slnf | 4 +--- SentryNoMobile.slnf | 4 ++-- SentryNoSamples.slnf | 1 + 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.generated.NoMobile.sln b/.generated.NoMobile.sln index 39b67a016f..ea50adc690 100644 --- a/.generated.NoMobile.sln +++ b/.generated.NoMobile.sln @@ -199,7 +199,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.MauiTrimTest", "test EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators", "src\Sentry.SourceGenerators\Sentry.SourceGenerators.csproj", "{C3CDF61C-3E28-441C-A9CE-011C89D11719}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators.Tests", "test\Sentry.SourceGenerators.Tests\Sentry.SourceGenerators.Tests.csproj", "{2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.SourceGenerators.Tests", "test\Sentry.SourceGenerators.Tests\Sentry.SourceGenerators.Tests.csproj", "{3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -540,10 +540,10 @@ Global {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Debug|Any CPU.Build.0 = Debug|Any CPU {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.ActiveCfg = Release|Any CPU {C3CDF61C-3E28-441C-A9CE-011C89D11719}.Release|Any CPU.Build.0 = Release|Any CPU - {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8}.Release|Any CPU.Build.0 = Release|Any CPU + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -632,6 +632,6 @@ Global {6030B748-0000-43B5-B8A8-399AA42F5229} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {DF92E098-822C-4B94-B96B-56BFB91FBB54} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} {C3CDF61C-3E28-441C-A9CE-011C89D11719} = {230B9384-90FD-4551-A5DE-1A5C197F25B6} - {2E9ACF05-88E8-4719-9E3E-8BBA9CF8FBC8} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} + {3A76FF7D-2F32-4EA5-8999-2FFE3C7CB893} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D} EndGlobalSection EndGlobal diff --git a/Sentry-CI-Build-Linux.slnf b/Sentry-CI-Build-Linux.slnf index 701cca4bdb..70d49a65ef 100644 --- a/Sentry-CI-Build-Linux.slnf +++ b/Sentry-CI-Build-Linux.slnf @@ -70,6 +70,7 @@ "test\\Sentry.OpenTelemetry.Tests\\Sentry.OpenTelemetry.Tests.csproj", "test\\Sentry.Profiling.Tests\\Sentry.Profiling.Tests.csproj", "test\\Sentry.Serilog.Tests\\Sentry.Serilog.Tests.csproj", + "test\\Sentry.SourceGenerators.Tests\\Sentry.SourceGenerators.Tests.csproj", "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", diff --git a/Sentry-CI-Build-Windows.slnf b/Sentry-CI-Build-Windows.slnf index cb6cf4b77a..0e2a79aa0c 100644 --- a/Sentry-CI-Build-Windows.slnf +++ b/Sentry-CI-Build-Windows.slnf @@ -72,6 +72,7 @@ "test\\Sentry.OpenTelemetry.Tests\\Sentry.OpenTelemetry.Tests.csproj", "test\\Sentry.Profiling.Tests\\Sentry.Profiling.Tests.csproj", "test\\Sentry.Serilog.Tests\\Sentry.Serilog.Tests.csproj", + "test\\Sentry.SourceGenerators.Tests\\Sentry.SourceGenerators.Tests.csproj", "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", diff --git a/Sentry-CI-Build-macOS.slnf b/Sentry-CI-Build-macOS.slnf index ffa30fe1a6..fa6698101a 100644 --- a/Sentry-CI-Build-macOS.slnf +++ b/Sentry-CI-Build-macOS.slnf @@ -78,6 +78,7 @@ "test\\Sentry.OpenTelemetry.Tests\\Sentry.OpenTelemetry.Tests.csproj", "test\\Sentry.Profiling.Tests\\Sentry.Profiling.Tests.csproj", "test\\Sentry.Serilog.Tests\\Sentry.Serilog.Tests.csproj", + "test\\Sentry.SourceGenerators.Tests\\Sentry.SourceGenerators.Tests.csproj", "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj", diff --git a/SentryMobile.slnf b/SentryMobile.slnf index 2e015d740e..c38fa573cc 100644 --- a/SentryMobile.slnf +++ b/SentryMobile.slnf @@ -12,15 +12,13 @@ "src\\Sentry.Bindings.Cocoa\\Sentry.Bindings.Cocoa.csproj", "src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj", "src\\Sentry.Maui\\Sentry.Maui.csproj", - "src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj", "src\\Sentry\\Sentry.csproj", "test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj", "test\\Sentry.Extensions.Logging.Tests\\Sentry.Extensions.Logging.Tests.csproj", "test\\Sentry.Maui.Device.TestApp\\Sentry.Maui.Device.TestApp.csproj", "test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj", - "test\\Sentry.SourceGenerators.Tests\\Sentry.SourceGenerators.Tests.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj" ] } -} \ No newline at end of file +} diff --git a/SentryNoMobile.slnf b/SentryNoMobile.slnf index c51e7da02f..1592f77697 100644 --- a/SentryNoMobile.slnf +++ b/SentryNoMobile.slnf @@ -32,10 +32,10 @@ "samples\\Sentry.Samples.OpenTelemetry.Console\\Sentry.Samples.OpenTelemetry.Console.csproj", "samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj", "src\\Sentry.Analyzers\\Sentry.Analyzers.csproj", + "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.AspNetCore.Blazor.WebAssembly\\Sentry.AspNetCore.Blazor.WebAssembly.csproj", "src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj", "src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj", - "src\\Sentry.AspNet\\Sentry.AspNet.csproj", "src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj", "src\\Sentry.DiagnosticSource\\Sentry.DiagnosticSource.csproj", "src\\Sentry.EntityFramework\\Sentry.EntityFramework.csproj", @@ -73,4 +73,4 @@ "test\\SingleFileTestApp\\SingleFileTestApp.csproj" ] } -} \ No newline at end of file +} diff --git a/SentryNoSamples.slnf b/SentryNoSamples.slnf index e66cd71ff5..f823107fbf 100644 --- a/SentryNoSamples.slnf +++ b/SentryNoSamples.slnf @@ -42,6 +42,7 @@ "test\\Sentry.OpenTelemetry.Tests\\Sentry.OpenTelemetry.Tests.csproj", "test\\Sentry.Profiling.Tests\\Sentry.Profiling.Tests.csproj", "test\\Sentry.Serilog.Tests\\Sentry.Serilog.Tests.csproj", + "test\\Sentry.SourceGenerators.Tests\\Sentry.SourceGenerators.Tests.csproj", "test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj", "test\\Sentry.Testing\\Sentry.Testing.csproj", "test\\Sentry.Tests\\Sentry.Tests.csproj" From 8e2e8e7363f125dd97f286165d27dac36fb8f6af Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 6 May 2025 16:35:16 -0400 Subject: [PATCH 28/30] Fixes - Skip tests on windows for now --- CHANGELOG.md | 6 ++++- .../BuildPropertySourceGeneratorTests.cs | 23 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 631fff508f..15d041f326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ # Changelog -## 5.7.0-beta.0 +## Unreleased + +### Features - New source generator allows Sentry to see true build variables like PublishAot and PublishTrimmed to properly adapt checks in the Sentry SDK ([#4101](https://github.com/getsentry/sentry-dotnet/pull/4101)) +## 5.7.0-beta.0 + ### Features - When setting a transaction on the scope, the SDK will attempt to sync the transaction's trace context with the SDK on the native layer. Finishing a transaction will now also start a new trace ([#4153](https://github.com/getsentry/sentry-dotnet/pull/4153)) diff --git a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs index 5fb146c14c..b952748dd5 100644 --- a/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs +++ b/test/Sentry.SourceGenerators.Tests/BuildPropertySourceGeneratorTests.cs @@ -2,16 +2,17 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.VisualStudio.TestPlatform.TestHost; -using Sentry.SourceGenerators; -namespace Sentry.Tests; +namespace Sentry.SourceGenerators.Tests; public class BuildPropertySourceGeneratorTests { - [Fact] + [SkippableFact] public Task RunResult_Success() { + Skip.If(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + var driver = BuildDriver(typeof(Program).Assembly, ("PublishAot", "false"), ("OutputType", "exe")); var result = driver.GetRunResult().Results.FirstOrDefault(); result.Exception.Should().BeNull(); @@ -21,9 +22,11 @@ public Task RunResult_Success() } - [Fact] + [SkippableFact] public Task RunResult_BadStrings() { + Skip.If(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + // we're hijacking PublishAot to make life easy var driver = BuildDriver(typeof(Program).Assembly, ("My\\Key", "test\\test"), ("OutputType", "exe")); var result = driver.GetRunResult().Results.FirstOrDefault(); @@ -34,9 +37,11 @@ public Task RunResult_BadStrings() } - [Fact] + [SkippableFact] public Task RunResult_Publish_AotTrue() { + Skip.If(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + var driver = BuildDriver(typeof(Program).Assembly, ("PublishAot", "true"), ("OutputType", "exe")); var result = driver.GetRunResult().Results.FirstOrDefault(); result.Exception.Should().BeNull(); @@ -46,12 +51,14 @@ public Task RunResult_Publish_AotTrue() } - [Theory] + [SkippableTheory] [InlineData("no", true)] [InlineData("true", false)] [InlineData("false", true)] public void RunResult_SentryDisableSourceGenerator_Values(string value, bool sourceGenExpected) { + Skip.If(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + var driver = BuildDriver(typeof(Program).Assembly, ("SentryDisableSourceGenerator", value), ("OutputType", "exe")); var result = driver.GetRunResult().Results.FirstOrDefault(); result.Exception.Should().BeNull(); @@ -61,9 +68,11 @@ public void RunResult_SentryDisableSourceGenerator_Values(string value, bool sou } - [Fact] + [SkippableFact] public Task RunResult_Expect_None() { + Skip.If(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + var driver = BuildDriver(typeof(Program).Assembly, ("PublishAot", "false")); var result = driver.GetRunResult().Results.FirstOrDefault(); result.Exception.Should().BeNull(); From d374701a2f9ce381dde5a9808bdc78bf65d9ae6f Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 6 May 2025 21:22:19 -0400 Subject: [PATCH 29/30] Update generate-solution-filters-config.yaml --- scripts/generate-solution-filters-config.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/generate-solution-filters-config.yaml b/scripts/generate-solution-filters-config.yaml index d3f0701202..1b829b1c59 100644 --- a/scripts/generate-solution-filters-config.yaml +++ b/scripts/generate-solution-filters-config.yaml @@ -48,7 +48,6 @@ filterConfigs: - "**/*AndroidTestApp.csproj" - "**/*DeviceTests*.csproj" - "**/*Maui.Device.TestApp.csproj" - - "**/*SourceGen.csproj" - outputPath: Sentry-CI-Build-macOS.slnf include: @@ -64,7 +63,6 @@ filterConfigs: patterns: - "**/*AndroidTestApp.csproj" - "**/*DeviceTests*.csproj" - - "**/*SourceGen.csproj" - outputPath: Sentry-CI-Build-Windows.slnf include: @@ -84,7 +82,6 @@ filterConfigs: - "**/*Sentry.Maui.Device.TestApp.csproj" - "**/*Sentry.Samples.Android.csproj" - "**/*OpenTelemetry.AspNet.csproj" - - "**/*SourceGen.csproj" - outputPath: Sentry-CI-CodeQL.slnf include: From a953c46ba1f1e3d0a3949c7168a7509230075786 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Tue, 6 May 2025 21:22:21 -0400 Subject: [PATCH 30/30] Update AotHelper.cs --- src/Sentry/Internal/AotHelper.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Sentry/Internal/AotHelper.cs b/src/Sentry/Internal/AotHelper.cs index 83a500f9d5..a10449e6fe 100644 --- a/src/Sentry/Internal/AotHelper.cs +++ b/src/Sentry/Internal/AotHelper.cs @@ -17,24 +17,30 @@ static AotHelper() [UnconditionalSuppressMessage("Trimming", "IL2026: RequiresUnreferencedCode", Justification = AvoidAtRuntime)] private static bool CheckIsTrimmed() { - if (Check("publishtrimmed")) - return true; + if (TryGetBoolean("publishtrimmed", out var trimmed)) + { + return trimmed; + } - if (Check("publishaot")) - return true; + if (TryGetBoolean("publishaot", out var aot)) + { + return aot; + } // fallback check var stackTrace = new StackTrace(false); return stackTrace.GetFrame(0)?.GetMethod() is null; } - private static bool Check(string key) + private static bool TryGetBoolean(string key, out bool value) { + value = false; if (BuildProperties.Values?.TryGetValue(key, out var aotValue) ?? false) { if (bool.TryParse(aotValue, out var result)) { - return result; + value = result; + return true; } }