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] Share DataModel between the generator and the transformer. #22015

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

mandel-macaque
Copy link
Member

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

In this change we are making the necesary changes to share the data model code between the generator and the transformer.

When we talk about sharing code in C# the average dotnet developer would create a csproj with the shared code and would reference it. In normal circumtances this is not a bad option, but our case is different and here are some of the reasons we cannot take that path:

  1. Roslyn code generators with more than one dll are problematic to distribute. You can already see how bad it is by looking at the dll shared between the code generator and the analyzer. The shared library has to be added as an analyzer so that it loads with the generator. We want to keep the number of dlls to a minimun.
  2. While the data models are similar, they are not identical. The attributes used by the code generator and the old api defintions are different. We would around this by splitting the definitions in 2 files:
    a - A common file with all date that does not depend on the attributes.
    b - A application specific file that contains the properties needed by the common parts BUT that uses structures specific for the application. An example is the ExportData. The ExportData is a generic in the generator (which contains flags) while it is not in the transformer. We also split the TryCreate and Constructor methods since those need to init the application specific parths.

In this commit we do not implement the transformer parts since that would make the diff hader. We are only moving code around and adding dummy implementations for the transformer project to compile.

In this change we are making the necesary changes to share the data
model code between the generator and the transformer.

When we talk about sharing code in C# the average dotnet developer
would create a csproj with the shared code and would reference it. In
normal circumtances this is not a bad option, but our case is different
and here are some of the reasons we cannot take that path:

1. Roslyn code generators with more than one dll are problematic to
   distribute. You can already see how bad it is by looking at the dll
   shared between the code generator and the analyzer. The shared
   library has to be added as an analyzer so that it loads with the
   generator. We want to keep the number of dlls to a minimun.
2. While the data models are similar, they are not identical. The
   attributes used by the code generator and the old api defintions are
   different. We would around this by splitting the definitions in 2
   files:
   a - A common file with all date that does not depend on the
   attributes.
   b - A application specific file that contains the properties needed
   by the common parts BUT that uses structures specific for the
   application. An example is the ExportData. The ExportData is a
   generic in the generator (which contains flags) while it is not in
   the transformer. We also split the TryCreate and Constructor methods
   since those need to init the application specific parths.

In this commit we do not implement the transformer parts since that
would make the diff hader. We are only moving code around and adding
dummy implementations for the transformer project to compile.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 12 out of 27 changed files in this pull request and generated 2 comments.

Files not reviewed (15)
  • src/rgen/Microsoft.Macios.Generator/DataModel/Method.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.Generator.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/Property.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/Property.Generator.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/Constructor.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/Event.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/EnumMember.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/Accessor.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Transformer/DataModel/Accessor.Transformer.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Transformer/Attributes/FieldData.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/EnumMember.Generator.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/Accessor.Generator.cs: Evaluated as low risk
  • src/rgen/Microsoft.Macios.Generator/DataModel/Method.Generator.cs: Evaluated as low risk
Comments suppressed due to low confidence (4)

src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.Generator.cs:1

  • The word 'necesary' is misspelled. It should be 'necessary'.
// In this change we are making the necesary changes to share the data model code between the generator and the transformer.

src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.Generator.cs:1

  • The word 'minimun' is misspelled. It should be 'minimum'.
// We want to keep the number of dlls to a minimun.

src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.Generator.cs:29

  • The variable 'isNSObject' should follow camelCase naming convention. It should be renamed to 'isNSObject'.
isNSObject: out isNSObject,

src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.Generator.cs:30

  • The variable 'isINativeObject' should follow camelCase naming convention. It should be renamed to 'isNativeObject'.
isNativeObject: out isINativeObject,

/// <inheritdoc />
public bool Equals (BindingInfo other)
{
throw new NotImplementedException();
Copy link
Preview

Copilot AI Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Equals method should not throw NotImplementedException. It should compare the relevant fields of the BindingInfo struct.

Suggested change
throw new NotImplementedException();
// Implement comparison logic here

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
/// <inheritdoc />
public override int GetHashCode ()
{
throw new NotImplementedException ();
Copy link
Preview

Copilot AI Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetHashCode method should not throw NotImplementedException. It should return a hash code based on the relevant fields of the BindingInfo struct.

Suggested change
throw new NotImplementedException ();
// Implement the hash code generation logic here

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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).

@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.

Copy link
Member

@dalexsoto dalexsoto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good approach as it allows us to both share code but also when needed have specific DataModel code files for each project without #if's everywhere so it ends up being cleaner

@vs-mobiletools-engineering-service2

This comment has been minimized.

@mandel-macaque mandel-macaque merged commit 05a3831 into main Jan 20, 2025
43 checks passed
@mandel-macaque mandel-macaque deleted the dev/mandel/transformer-datamodel branch January 20, 2025 15:56
@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Pipeline on Agent
Hash: 05a3831d8aabf0691a319372590430c2852acc16 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Pipeline on Agent
Hash: 05a3831d8aabf0691a319372590430c2852acc16 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Pipeline on Agent
Hash: 05a3831d8aabf0691a319372590430c2852acc16 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Windows Integration Tests passed 💻

All Windows Integration Tests passed.

Pipeline on Agent
Hash: 05a3831d8aabf0691a319372590430c2852acc16 [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: 05a3831d8aabf0691a319372590430c2852acc16 [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: 05a3831d8aabf0691a319372590430c2852acc16 [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: 05a3831d8aabf0691a319372590430c2852acc16 [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: 05a3831d8aabf0691a319372590430c2852acc16 [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: 05a3831d8aabf0691a319372590430c2852acc16 [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, 111 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 4 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: 05a3831d8aabf0691a319372590430c2852acc16 [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.

3 participants