Skip to content

Pass generators to CSC during component discovery #25292

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

Merged
merged 3 commits into from
Aug 28, 2020

Conversation

chsienki
Copy link
Member

@chsienki chsienki commented Aug 26, 2020

  • Pass the @(Analyzer) item group to CSC during component discovery
  • Disable execution of analyzers

Addresses #24526

@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Aug 26, 2020
@chsienki
Copy link
Member Author

This will presumably need tests etc, but I'm pretty unfamiliar with the ASP.Net repo

@@ -231,6 +232,7 @@ Copyright (c) .NET Foundation. All rights reserved.
ResponseFiles="$(CompilerResponseFile)"
RuntimeMetadataVersion="$(RuntimeMetadataVersion)"
SharedCompilationId="$(SharedCompilationId)"
SkipAnalyzers="true"
Copy link
Member

Choose a reason for hiding this comment

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

Note: this will only work once they are using the RC1 SDK correct? This change in our targets didn't make P8 IIRC

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not 100% sure, but I just grabbed the preview8 SDK bits and it seems to be there in the targets.

Copy link
Member

Choose a reason for hiding this comment

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

Just verified myself and yes it made .NET P8.

@DamianEdwards
Copy link
Member

@mkArtakMSFT @pranavkm

@Pilchie
Copy link
Member

Pilchie commented Aug 26, 2020

Thanks @chsienki. Should we consider this for RC1 (in which case a retarget to release/5.0 would be in order)?

@pranavkm
Copy link
Contributor

pranavkm commented Aug 27, 2020

@chsienki could you rebase this change (or make this change) in the release/5.0 branch? We'd want to take this for the 5.0 release. master targets 6.0.

Just noticed @Pilchie's comment stating the same. Retargeting this PR would bring in random changes from the master branch, so rebasing would be the way to go.

@chsienki chsienki force-pushed the razor_source_generators branch from 2d845e4 to d959084 Compare August 27, 2020 01:09
@chsienki chsienki changed the base branch from master to release/5.0 August 27, 2020 01:09
@chsienki
Copy link
Member Author

Rebased and re-targeted onto release/5.0

@chsienki
Copy link
Member Author

Hmm, looks like 5.0 is on an earlier SDK version; we don't have access to SkipAnalyzers, which means Analyzers will get run as part of Component Discovery.

Unfortunately that means users would see double warnings from analyzers, as they'll be emitted as part of discovery and then again during compilation. Generally VS seems to hide the duplicates when they occur at the same location, which is true for general compiler warnings as they're #lined back to the original file. Analyzer warnings though seem to show duplicated because the .g. files aren't identical between the two phases.

@dougbu
Copy link
Contributor

dougbu commented Aug 27, 2020

Hmm, looks like 5.0 is on an earlier SDK version

Yes, we ran into too many problems attempting to update the SDK and gave up. A nicer way to say it is that we deferred the work to early in RC2.

Unfortunately that means users would see double warnings from analyzers

Would this affect anyone outside this repo❔ If it's just those changing code in VS, I suggest that's not great but is livable. CI builds run w/ warn-as-error in any case.

Which reminds me: The analyzers will run in command line (dotnet msbuild) builds, correct❔

@dougbu
Copy link
Contributor

dougbu commented Aug 27, 2020

BTW build should be using the 5.0.100-rc.1.20379.10 SDK in our release/5.0 and master branches. Surprised that doesn't contain fixes that made it into the preview.8 SDK.

@pranavkm
Copy link
Contributor

Would this affect anyone outside this repo❔ If it's just those changing code in VS, I suggest that's not great but is livable. CI builds run w/ warn-as-error in any case.

Yes, those targets are in the SDK and will affect RC1 users.

@@ -187,6 +187,7 @@ Copyright (c) .NET Foundation. All rights reserved.
AddModules="@(AddModules)"
AdditionalFiles="@(AdditionalFiles)"
AllowUnsafeBlocks="$(AllowUnsafeBlocks)"
Analyzers="@(Analyzer)"

Choose a reason for hiding this comment

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

@pranavkm couldn't we just remove the ANalyzers from this phase wholesale?

Copy link
Member

Choose a reason for hiding this comment

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

Source generators are also considered analyzers, and they need to happen in this phase.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, thats the problem, and why we added the new SkipAnalyzers argument.

Equally we're going to have this issue if a generator emits a warning too, so we might need to re-think the strategy a little bit? I wonder if we should just disable all wanings (-warn 0) for the component discovery phase? That way any warnings would only show up in the second phase, and errors in the first phase would stop the second running anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll give bumping up the SDK another try. If we get it updated to the latest and greatest, perhaps we get this change in as-is.

Choose a reason for hiding this comment

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

I wonder if we should just disable all wanings (-warn 0) for the component discovery phase? That way any warnings would only show up in the second phase, and errors in the first phase would stop the second running anyway.

ya I think that'd be best

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I've disabled warnings and removed the SkipAnalyzers param. Means that phase might be a little slower until you upgrade the SDK and can use it again, but everything should work as expected.

Copy link
Member

Choose a reason for hiding this comment

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

Should we file a follow up issue to move to SkipAnalyzers at some point in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'll open an issue to track.

@mkArtakMSFT
Copy link
Contributor

@chsienki are you able to merge this change or do you need help with it?

@chsienki
Copy link
Member Author

I don't have permission to do the actual merge :)

@mkArtakMSFT
Copy link
Contributor

@pranavkm, @jaredpar are additional feedback or are you happy with the change?

Copy link
Contributor

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

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

@chsienki could you file the follow up issue?

@chsienki
Copy link
Member Author

Filled #25365 to follow up.

@mkArtakMSFT mkArtakMSFT merged commit 4df35c7 into release/5.0 Aug 28, 2020
@mkArtakMSFT mkArtakMSFT deleted the razor_source_generators branch August 28, 2020 18:32
@mkArtakMSFT
Copy link
Contributor

Thanks @chsienki !

@mkArtakMSFT mkArtakMSFT linked an issue Aug 28, 2020 that may be closed by this pull request
@EdCharbeneau
Copy link

I'm having a similar issue to this and #24526

Where is the proper place to report the issue? @chsienki @jaredpar
EdCharbeneau/BlazorSize.CssGenerator#1

@ghost
Copy link

ghost commented Mar 25, 2021

Hi @EdCharbeneau. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Razor components break source generators
9 participants