Skip to content

Tooling and app should compile and run when no components are found #32

Open

Description

@Arlodotexe

Background

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.

Activity

  1. added
    bug 🐛Something isn't working
    enhancementNew feature or request
    dev loop ➰For issues that impact the core dev-loop of building experiments
    on Mar 21, 2023
  2. Arlodotexe commented on Mar 21, 2023

    @Arlodotexe
    MemberAuthor

    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.

    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.
    • The (now reverted) commit from Fixed sample not picking up source-defined MultiTarget value, fixed compiler error #27 was made to allow generating empty registries, and an empty registry is being incorrectly generated when running from the test project. The commit has exposed an underlying bug, which now needs to be fixed first.
    • We're executing the generator twice. Once for running diagnostics on referenced assemblies, one for running actually generating a registry:
      • image
    • 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.
      • image
    • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't workingdev loop ➰For issues that impact the core dev-loop of building experimentsenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions