-
Notifications
You must be signed in to change notification settings - Fork 518
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
[Rgen] Use a roslyn code generator to help generate the flag parsing of all attributes. #22032
Conversation
…of all attributes. The old Xamarin API used A LOT of attributes as flags to indicate different generating methods. All this attributes do not have any data and can be used as a feature flag. For example, if we wanted to generated a static class we can do: ```csharp [Static] interface MyStaticClass {} ``` In this commit we are relaying in a custom roslyn code generator that parses an attribute and generates the flag properties for our data model. All the code is very repetitive and specially error prone. The generator allows use just to focus on the name of the attribute and the targets to which the attribute can be applied. When you do the review you'll notice that the targets used in the AttributeNames in the transformer do not match the ones in the bgen/Attributes.cs file. The mismatch is because people back in the day were careless and used the default flag, which is All. That is a mistake, so I went throgh the trouble of using the correct target and add a document string explaining the use of the flag and therefore the reasoning of the updated target. A sample of the generated code can be found [here](https://gist.github.com/mandel-macaque/ed4277457a3afa6606af0f78ee9bf07e)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 11 changed files in this pull request and generated no comments.
Files not reviewed (6)
- src/rgen/.gitignore: Language not supported
- src/rgen/Microsoft.Macios.Transformer.Generator/Microsoft.Macios.Transformer.Generator/Microsoft.Macios.Transformer.Generator.csproj: Language not supported
- src/rgen/Microsoft.Macios.Transformer.Generator/Microsoft.Macios.Transformer.Generator/Properties/launchSettings.json: Language not supported
- src/rgen/Microsoft.Macios.Transformer/Microsoft.Macios.Transformer.csproj: Language not supported
- src/rgen/rgen.sln: Language not supported
- src/rgen/Microsoft.Macios.Generator/TabbedStringBuilder.cs: Evaluated as low risk
Comments suppressed due to low confidence (1)
src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.cs:20
- The array initialization is incorrect. It should be corrected to
Parents = new[] { "System.ValueType", "object" }
.
public static TypeInfo Void = new ("void", SpecialType.System_Void) { Parents = ["System.ValueType", "object"], };
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build] Build passed (Build packages) ✅Pipeline on Agent |
✅ [CI Build] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ [CI Build] Build passed (Build macOS tests) ✅Pipeline on Agent |
✅ API diff for current PR / commit.NET ( No breaking changes )❗ API diff vs stable (Breaking changes).NET ( ❗ Breaking changes ❗ )ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
💻 [CI Build] Windows Integration Tests passed 💻✅ All Windows Integration Tests passed. Pipeline on Agent |
💻 [CI Build] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
🔥 [CI Build] Test results 🔥Test results❌ Tests failed on VSTS: test results 1 tests crashed, 0 tests failed, 113 tests passed. Failures❌ dotnettests tests (MacCatalyst)🔥 Failed catastrophically on VSTS: test results - dotnettests_maccatalyst (no summary found). Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
The old Xamarin API used A LOT of attributes as flags to indicate different generating methods. All this attributes do not have any data and can be used as a feature flag.
For example, if we wanted to generated a static class we can do:
In this commit we are relaying in a custom roslyn code generator that parses an attribute and generates the flag properties for our data model. All the code is very repetitive and specially error prone. The generator allows us just to focus on the name of the attribute and the targets to which the attribute can be applied.
When you do the review you'll notice that the targets used in the AttributeNames in the transformer do not match the ones in the bgen/Attributes.cs file. The mismatch is because people back in the day were careless and used the default flag, which is All. That is a mistake, I went through the trouble of using the correct target and add a document string explaining the use of the flag and therefore the reasoning of the updated target.
A sample of the generated code can be found
here