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

[release/6.0.3xx] [NET Attribute Conversion][generator] Generate NET style attributes #14877

Conversation

vs-mobiletools-engineering-service2
Copy link
Collaborator

?? the final large piece of the saga that is #10170

We won't know until landing this and testing the result but it's the last known hole.....

Summary

This PR teaches our code generator to generate .NET 6 style availability attributes, adds a 4th Cecil test to verify our generated attributes, and a metric ton of API changes to satisfy that test.

Details

The generator work is the core of this PR, and includes:

  • Hacking out chunks of generator.cs that "helpfully" remove duplicate attributes, which are no longer duplicate in the new order that NET6 attributes force upon us. See changes in FilterMinimumVersion and PrintPlatformAttributes
  • Prevent a crash when the generator processes availability attributes with no version included (example: introduced on iOS but no version). See Is64BitiOSOnly.
  • The meat, GetPlatformAttributesToPrint, which synthesizes many attributes "out of thing air" from:
    • The parent context
    • Implied introduced just because the class exists on a given framework at all
    • Implied Catalyst because iOS exists
  • A few cludgy hacks PrintPlatformAttributesNoDuplicates and GenerateProperty because the existing PrintPlatformAttributes did not pass down parent context down, and the refactor was dangerous/too time consuming given time pressure.

There are two intended API changes introduced by the reviews in this PR:

  • GetCurrentInputDevice was obviously intended by availability attributes to exist on Catalyst but due to define confusion was excluded. It is an addition in Microsoft.MacCatalyst.dll only.
  • The NEAppRule constructors were mis-marked on platforms, and were showing up incorrectly on Mac/Catalyst. I corrected the Catalyst one unconditionally, as we have not shipped Catalyst yet, but Mac is only fixed in NET6.

Known API changes

image

image

Limitations

I could spend another week or two polishing this, at minimum. It is being landed in this state due to time pressure.

There are bugs in the generated attributes:

  • Major: Protocols with one set of attributes [TV (9,0)] inlined in types that differ [NoTV] currently unconditionally use the attributes from the protocol, which is wrong. This has always been wrong, but never noticed given how few of them we generated in legacy due to the de-duplication logic and lack of tests. This was deemed too difficult to fix in time since the calls to GetPlatformAttributesToPrint did not pass the "target" type, and I'd have to do wider surgery to wire it through.
  • Major: Obsolete attributes prevent the "implied introduced" attribute from being created, causing some enums to not generate correct attributes.
  • Minor: Protocols that are conditionally included with defines don't have the right attributes. Example: if we include NSItemProviderReading only on iOS those inlined protocols don't have [NoTV] equivalents.
  • Minor: Attributes that are conditionally set as Abstract also don't set the right attributes.

Each of these has cases hit that are Ignored in test code (see IgnoreElementsThatDoNotExistInThatAssembly).

Other things to note (and forgive) include:

  • The gross #if hacks in generator.cs, which are signs that my hacked in code did not gel well with the existing logic. I should in theory extend each check to better handle the NET6 availability attribute reality and then remove logic from GetPlatformAttributesToPrint.
  • GetPlatformAttributesToPrint is a god-function that does too much. It is well documented and calls into child functions where possible, but I could do better with more time.
  • There are zero tests outside of the integration Cecil tests.

Despite this, given time pressure and test coverage I think it is ready to go in.

I've filed #14802 to track the cleanup work from this PR.

Backport of #14779

chamons and others added 19 commits May 3, 2022 13:42
- The integration with the existing generator code is not ideal in this
commit, but given time pressures it will hopefully be improved in the future.
- GetPlatformAttributesToPrint is repeating some of the logic that is #if !NET'ed out
in places such as PrintPlatformAttributes because those checks were not robust enough
for the NET6 attribute logic (we generate many more 'duplicate' attributes now)
…remove now unnecessary ignores on other tests
- This is an actual API inclusion, not just attribute change.
- All of the other defines, and attributes imply that GetCurrentInputDevice()
was expected to be on catalyst, but the define on 433 did not include it
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
…re lower cased in one place but not another)
- Generate Obsolete/Advice and Unsupported pairs for Deprecated/Obsoleted instead of a single attribute
- A number of generator improvements and test/binding fixes
…mespaceNotIncluded always assuming we're core
@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

📋 [PR Build] API Diff 📋

API Current PR diff

ℹ️ API Diff (from PR only) (please review changes)

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Generator diff

ℹ️ Generator Diff (please review changes)

Pipeline on Agent XAMBOT-1030.Monterey'
Hash: 30ea4ae71a0bf54927fc37208ce74eebb8692b2d

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1103.Monterey
Hash: 30ea4ae71a0bf54927fc37208ce74eebb8692b2d

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

❌ [PR Build] Tests on macOS Mac Catalina (10.15) failed ❌

Failed tests are:

  • introspection

Pipeline on Agent
Hash: 30ea4ae71a0bf54927fc37208ce74eebb8692b2d

@vs-mobiletools-engineering-service2
Copy link
Collaborator Author

✅ [CI Build] Tests passed on VSTS: simulator tests iOS. ✅

Tests passed on VSTS: simulator tests iOS.

🎉 All 150 tests passed 🎉

Pipeline on Agent XAMBOT-1036.Monterey'
Merge 30ea4ae into 3f73ae0

@chamons
Copy link
Contributor

chamons commented May 4, 2022

I just tested this against 4 NET ported sames TJ pointed out had warnings and the largest MAUI sample (https://github.com/microsoft/dotnet-podcasts) and there were no spurious availability warnings.

This is good enough to go in.

@chamons chamons removed the do-not-merge Do not merge this pull request label May 4, 2022
@chamons chamons merged commit 2ad0c24 into xamarin:release/6.0.3xx May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported not-notes-worthy Ignore for release notes run-dotnet-tests Run all the .NET tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants