-
-
Notifications
You must be signed in to change notification settings - Fork 226
Build Variables Source Generator #4101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
6826c9f
Initial commit
aritchie a3d3a16
Update CHANGELOG.md
aritchie 48860aa
Updates path refs
aritchie 94800bb
Format code
getsentry-bot fe82638
Merge branch 'main' into pr/4101
jamescrosswell d79cf1f
Merge branch 'main' into 2927-aot_buildvars_sourcegen
aritchie 7c9f1e2
Package analyzer with sentry nuget
aritchie 5320e8a
add tests - having tooling issues lighting this up - trying in CI
aritchie c034685
Format code
getsentry-bot 09fba9e
Updates
aritchie f59f230
Merge branch '2927-aot_buildvars_sourcegen' of https://github.com/get…
aritchie a9ca3d2
Format code
getsentry-bot f5ea7a2
code review fix
aritchie 194041f
Update Sentry.SourceGenerators.csproj
aritchie 4ebc989
Update for unit tests
aritchie bc99a75
Fixes and name alignments
aritchie 4547af6
Fix bad bot changes
aritchie ca53bc4
Add disable sentry changes per code review as well as unit tests for it
aritchie 6a03323
Merge branch 'main' into 2927-aot_buildvars_sourcegen
aritchie 800c7bf
Try to revert bad bot
aritchie 214abda
Format code
getsentry-bot 852c4ca
Done
aritchie 1c436bf
Update CHANGELOG.md
aritchie 6f71d50
Update SentrySdk.cs
aritchie ab5aa3a
Merge branch '2927-aot_buildvars_sourcegen' of https://github.com/get…
aritchie 9daa168
Merge branch 'main' into 2927-aot_buildvars_sourcegen
aritchie a21c92c
Update slnf as stated in CI :|
aritchie f82ee97
update verify tests
aritchie 15f244e
Finally forced these to update
aritchie 86d8f4b
Ensure source generator isn't included as reference
aritchie 79f185f
Moving to its own project
aritchie 5c7927d
Update slnf
aritchie d9da82d
Update solution filters
aritchie 1fb5ec4
Merge branch 'main' into 2927-aot_buildvars_sourcegen
aritchie 8e2e8e7
Fixes - Skip tests on windows for now
aritchie d374701
Update generate-solution-filters-config.yaml
aritchie a953c46
Update AotHelper.cs
aritchie 5c114d7
Merge branch 'main' into 2927-aot_buildvars_sourcegen
aritchie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aritchie marked this conversation as resolved.
Show resolved
Hide resolved
|
Submodule sentry-native
updated
33 files
| +7 −1 | .editorconfig | |
| +10 −0 | CHANGELOG.md | |
| +31 −2 | CMakeLists.txt | |
| +2 −1 | CONTRIBUTING.md | |
| +42 −19 | README.md | |
| +15 −15 | cmake/utils.cmake | |
| +6 −0 | examples/example.c | |
| +125 −125 | external/CMakeLists.txt | |
| +49 −1 | include/sentry.h | |
| +1 −1 | ndk/gradle.properties | |
| +5 −5 | ndk/lib/CMakeLists.txt | |
| +2 −2 | ndk/sample/CMakeLists.txt | |
| +28 −0 | scripts/run_formatters.ps1 | |
| +15 −15 | sentry-config.cmake.in | |
| +6 −3 | src/backends/sentry_backend_breakpad.cpp | |
| +3 −2 | src/backends/sentry_backend_crashpad.cpp | |
| +5 −2 | src/backends/sentry_backend_inproc.c | |
| +32 −4 | src/sentry_core.c | |
| +6 −0 | src/sentry_core.h | |
| +38 −4 | src/sentry_options.c | |
| +10 −1 | src/sentry_options.h | |
| +136 −25 | src/sentry_os.c | |
| +2 −2 | src/sentry_os.h | |
| +39 −4 | tests/assertions.py | |
| +14 −0 | tests/fixtures/view-hierarchy.json | |
| +49 −8 | tests/test_integration_crashpad.py | |
| +8 −4 | tests/test_integration_http.py | |
| +45 −9 | tests/test_integration_stdout.py | |
| +2 −2 | tests/unit/CMakeLists.txt | |
| +179 −0 | tests/unit/test_os.c | |
| +2 −0 | tests/unit/tests.inc | |
| +1 −1 | tests/win_utils.py | |
| +21 −21 | toolchains/msys2.cmake |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/Sentry.SourceGenerators/BuildVariableSourceGenerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using Microsoft.CodeAnalysis; | ||
|
|
||
| namespace Sentry.SourceGenerators; | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Generates the necessary msbuild variables | ||
| /// </summary> | ||
| [Generator(LanguageNames.CSharp)] | ||
| public class BuildPropertySourceGenerator : ISourceGenerator | ||
| { | ||
| /// <summary> | ||
| /// Initialize the source gen | ||
| /// </summary> | ||
| public void Initialize(GeneratorInitializationContext context) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Execute the source gen | ||
| /// </summary> | ||
| 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)) | ||
aritchie marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Debugger.Break(); | ||
|
|
||
| // 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("#if NET8_0_OR_GREATER") | ||
aritchie marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .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<string, string> {"); | ||
|
|
||
| foreach (var property in properties) | ||
| { | ||
| if (opts.TryGetValue(property, out var value)) | ||
| { | ||
| var pn = EscapeString(property.Replace("build_property.", "")); | ||
| var ev = EscapeString(value); | ||
| sb | ||
| .Append("\t\t\t{") | ||
| .Append($"\"{pn}\", \"{ev}\"") | ||
| .Append("},\r\n"); | ||
| } | ||
| } | ||
|
|
||
| sb | ||
| .AppendLine("\t\t});") // close dictionary | ||
| .AppendLine("\t}") | ||
| .AppendLine("}") | ||
| .AppendLine("#endif"); | ||
|
|
||
| context.AddSource("__BuildVariables.g.cs", sb.ToString()); | ||
| } | ||
|
|
||
|
|
||
| private static string EscapeString(string value) => value.Replace("\\", "\\\\"); | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
src/Sentry.SourceGenerators/Sentry.SourceGenerators.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <IsPackable>false</IsPackable> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>false</ImplicitUsings> | ||
|
|
||
| <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | ||
| <IsRoslynComponent>true</IsRoslynComponent> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" PrivateAssets="all"/> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0" PrivateAssets="all"/> | ||
aritchie marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Remove="System.Text.Json" /> | ||
| <Using Remove="System.Text.Json.Serialization" /> | ||
| </ItemGroup> | ||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <Project> | ||
| <ItemGroup> | ||
| <CompilerVisibleProperty Include="PublishAot" /> | ||
| <CompilerVisibleProperty Include="UseDotNetNativeToolchain" /> | ||
| <CompilerVisibleProperty Include="PublishTrimmed" /> | ||
| <CompilerVisibleProperty Include="DisableSentrySourceGenerator" /> | ||
| <CompilerVisibleProperty Include="Configuration" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.