You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tooling and app should compile and run when no components are found #32
The tooling was created in Toolkit Labs, and was created using CanvasLayout as our testing ground. The tooling has only ever been used with at least one component present.
Problem
The tooling fails in some places when no components are found. This manifests in various forms.
Solution
This issue documents and tracks the various problems we've found when no components are present. See comments below.
51a666f is a general tooling fix which was introduced in #27 and reverted in #31:
Fixed compiler error that occurs when the only component in the solution doesn't support all MultiTargets.
Would also happen if no component in the solution supported a MultiTarget you had loaded (e.g. if you decided to exclude Android altogether but still generated the Android head).
Why this was added
We found this by removing WASM on the Converters component in a repo where it was the first thing being ported. This caused WASM to compile without any components and caused the build to fail, while the UWP and WinAppSDK heads had the Converters and compiled fine.
This fix was a quick thing to move us towards allow compiling the app without components, and to get CommunityToolkit/Windows#1 out the door.
Error Message:
Test method CommunityToolkit.Tooling.SampleGen.Tests.ToolkitSampleMetadataTests.PaneOption_GeneratesTitleProperty threw exception:
System.InvalidOperationException: Sequence contains no matching element
Stack Trace:
at System.Linq.ThrowHelper.ThrowNoMatchException()
at CommunityToolkit.Tooling.SampleGen.Tests.ToolkitSampleMetadataTests.VerifyGenerateSources(String assemblyName, String source, IIncrementalGenerator[] generators, Boolean ignoreDiagnostics, ValueTuple`2[] results) in /_/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.cs:line 533
at CommunityToolkit.Tooling.SampleGen.Tests.ToolkitSampleMetadataTests.PaneOption_GeneratesTitleProperty() in /_/CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.cs:line 91
Investigation notes
The source generator will generate the correct output, but then it runs again and overwrites it with an empty registry. This is what the test picked up and tried to use.
We're executing the generator twice. Once for running diagnostics on referenced assemblies, one for running actually generating a registry:
We also execute twice inside Execute method. Once for diagnostics, once for creating the registry. Registry generation has a special code path dedicated to tests, which may be the root of the issue.
This is only a problem for the PaneOption_GeneratesTitleProperty test, because it's the only test which checks a hardcoded string against the generated output. All other tests simply check the diagnostic.
This noteworthy for investigating, but also - we should not be it doing this way. Instead, we should check the compilation object and look for the specific property we want.
What's next?
This is where my investigation ended. Once we fix this underlying bug, we can add this back and enable compiling heads even if they don't reference a component.
Additionally, while there are notes in the code, the code is a bit messy and hard to understand.
Since we already need to pull it apart in order to understand and change it, we should rename things to make the intent explicitly clear from how we use it. This source generator is doing too much to fall behind in this area.
Activity
Arlodotexe commentedon Mar 21, 2023
Generating an empty sample registry
Summary
51a666f is a general tooling fix which was introduced in #27 and reverted in #31:
Fixed compiler error that occurs when the only component in the solution doesn't support all MultiTargets.Would also happen if no component in the solution supported a MultiTarget you had loaded (e.g. if you decided to exclude Android altogether but still generated the Android head).
Why this was added
We found this by removing WASM on the Converters component in a repo where it was the first thing being ported. This caused WASM to compile without any components and caused the build to fail, while the UWP and WinAppSDK heads had the Converters and compiled fine.
This fix was a quick thing to move us towards allow compiling the app without components, and to get CommunityToolkit/Windows#1 out the door.
Why this was removed
This caused the CI to fail here.
Investigation notes
Executemethod. Once for diagnostics, once for creating the registry. Registry generation has a special code path dedicated to tests, which may be the root of the issue.PaneOption_GeneratesTitlePropertytest, because it's the only test which checks a hardcoded string against the generated output. All other tests simply check the diagnostic.What's next?
This is where my investigation ended. Once we fix this underlying bug, we can add this back and enable compiling heads even if they don't reference a component.
Additionally, while there are notes in the code, the code is a bit messy and hard to understand.
Since we already need to pull it apart in order to understand and change it, we should rename things to make the intent explicitly clear from how we use it. This source generator is doing too much to fall behind in this area.