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

[trimming] TrimMode=full in debug mode, should enable analyzers #9320

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Sep 24, 2024

For NativeAOT scenarios, projects would set:

<PublishAot>true</PublishAot>

For both Debug and Release, this allows you to get the same set of analyzers in both configurations. You'd want to see the same warnings for both.

For Android, the project template is currently doing:

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TrimMode>Full</TrimMode>
</PropertyGroup>

But this would result in a different set of warnings between Debug and Release mode!

Instead, we can do:

<PropertyGroup>
    <TrimMode>Full</TrimMode>
</PropertyGroup>

And then add a new default, such as:

<EnableTrimAnalyzer Condition="'$(EnableTrimAnalyzer)' == '' and '$(TrimMode)' == 'full'">true</EnableTrimAnalyzer>

TrimMode=Full does not enable the trimmer, so other defaults in Debug should remain unchanged.

So, the new behavior is:

  • Configuration=Debug
  • PublishTrimmed=false (default, no trimmer)
  • TrimMode=Full (project template)
  • EnableTrimAnalyzer=true (new default)
  • You get the same warnings in Debug and Release mode.

I also reworded the commend in the project template slightly, to mention it enables analyzers.

Comment on lines -272 to 273
[TestCase ("TrimMode=full", new string [0], false)]
[TestCase ("TrimMode=full", new string [] { "IL2055" }, false, 1)]
[TestCase ("TrimMode=full", new string [] { "IL2055" }, true, 2)]
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that you will get 2x warnings in Release, one from the trimmer and one from the Roslyn analyzer. This is "by design", and we shouldn't try to hide them or anything.

@jonathanpeppers

This comment was marked as outdated.

@jonathanpeppers jonathanpeppers marked this pull request as ready for review September 24, 2024 21:03
For AOT scenarios, projects would set:

    <PublishAot>true</PublishAot>

For both `Debug` and `Release`, this allows you to get the same set of
analyzers in both configurations. You'd want to see the same warnings
for both.

For Android, the project template is currently doing:

    <PropertyGroup Condition="'$(Configuration)' == 'Release'">
        <TrimMode>Full</TrimMode>
    </PropertyGroup>

But this would result in a *different* set of warnings between `Debug`
and `Release` mode!

Instead, we can do:

    <PropertyGroup>
        <TrimMode>Full</TrimMode>
    </PropertyGroup>

And then add a new default, such as:

    <EnableTrimAnalyzer Condition="'$(EnableTrimAnalyzer)' == '' and '$(TrimMode)' == 'full'">true</EnableTrimAnalyzer>

`TrimMode=Full` does *not* enable the trimmer, so other defaults in
`Debug` should remain unchanged.

So, the new behavior is:

    * `Configuration=Debug`
    * `PublishTrimmed=false` (default, no trimmer)
    * `TrimMode=Full` (project template)
    * `EnableTrimAnalyzer=true` (new default)
    * You get the same warnings in `Debug` and `Release` mode.

I also reworded the commend in the project template slightly, to
mention it enables analyzers.
@jonpryor
Copy link
Member

Draft commit message:

For AOT scenarios, projects would set:

	<PublishAot>true</PublishAot>

For both `Debug` and `Release`, this allows you to get the same set
of analyzers in both configurations.  You'd want to see the same
warnings for both.

For Android, the project template is currently doing:

	<PropertyGroup Condition="'$(Configuration)' == 'Release'">
	  <TrimMode>Full</TrimMode>
	</PropertyGroup>

but this would result in a *different* set of warnings between
`Debug` and `Release` configuration builds!

Instead, we can do:

	<PropertyGroup>
	  <TrimMode>Full</TrimMode>
	</PropertyGroup>

And then add a new default, such as:

	<EnableTrimAnalyzer
	    Condition=" '$(EnableTrimAnalyzer)' == '' and '$(TrimMode)' == 'full' "
	>true</EnableTrimAnalyzer>

`$(TrimMode)=Full` does *not* enable the trimmer, so other defaults
in the `Debug` configuration build should remain unchanged.

So, the new behavior is:

  * `$(Configuration)=Debug`
  * `$(PublishTrimmed)=false` (default, no trimmer)
  * `$(TrimMode)=Full` (project template)
  * `$(EnableTrimAnalyzer)=true` (new default)
  * You get the same set of warnings in `Debug` and `Release`
    configuration builds.

I also reworded the comment in the project template slightly, to
mention it enables analyzers.

@jonathanpeppers : one question about that commit message: you say:

So, the new behavior is:

  • $(Configuration)=Debug`

"new behavior" implies a change in behavior. The default $(Configuration) hasn't changed. Am I misinterpreting?

@jonathanpeppers
Copy link
Member Author

I think I just missed the word “for” like: For Configuration=Debug

@jonathanpeppers jonathanpeppers merged commit 118e894 into dotnet:main Sep 26, 2024
55 of 57 checks passed
@jonathanpeppers jonathanpeppers deleted the TrimModeFullDebug branch September 26, 2024 13:29
@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants