Skip to content
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

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

mandel-macaque
Copy link
Member

@mandel-macaque mandel-macaque commented Jan 23, 2025

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:

[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 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

…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)
Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

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"], };
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@mandel-macaque mandel-macaque merged commit 7df9693 into main Jan 24, 2025
43 checks passed
@mandel-macaque mandel-macaque deleted the dev/mandel/transformer-flags branch January 24, 2025 00:29
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

.NET ( No breaking changes )

❗ API diff vs stable (Breaking changes)

.NET ( ❗ Breaking changes ❗ )

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Windows Integration Tests passed 💻

All Windows Integration Tests passed.

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [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
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 7df9693fdb980dd6e2b076e5a411b9cdb7d16882 [PR build]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants