Skip to content

Commit

Permalink
Merge pull request #54143 from mavasani/SkipAnalyzersOnIndirectBuild
Browse files Browse the repository at this point in the history
Add functionality to enable skipping analyzers for implicitly trigger…
  • Loading branch information
mavasani authored Jun 18, 2021
2 parents 0983302 + 864d774 commit 296cdd2
Show file tree
Hide file tree
Showing 17 changed files with 279 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Compilers/Core/MSBuildTask/ErrorString.resx
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,7 @@
<data name="General_UnableToReadFile" xml:space="preserve">
<value>File "{0}" could not be read: {1}</value>
</data>
<data name="ImplicitlySkipAnalyzersMessage" xml:space="preserve">
<value>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.</value>
</data>
</root>
46 changes: 45 additions & 1 deletion src/Compilers/Core/MSBuildTask/Microsoft.Managed.Core.targets
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@
</PropertyGroup>
</Target>

<!--
========================
SkipAnalyzers Support
========================
-->
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.ShowMessageForImplicitlySkipAnalyzers" AssemblyFile="$(MSBuildThisFileDirectory)Microsoft.Build.Tasks.CodeAnalysis.dll" />

<Target Name="_ComputeSkipAnalyzers" BeforeTargets="CoreCompile">
<!-- First, force clear non-user facing property '_SkipAnalyzers'. -->
<!-- First, force clear non-user facing properties '_SkipAnalyzers' and '_ImplicitlySkipAnalyzers'. -->
<PropertyGroup>
<_SkipAnalyzers></_SkipAnalyzers>
<_ImplicitlySkipAnalyzers></_ImplicitlySkipAnalyzers>
</PropertyGroup>

<!--
Expand All @@ -70,6 +79,41 @@
('$(RunAnalyzers)' == '' and '$(RunAnalyzersDuringBuild)' == 'false')">
<_SkipAnalyzers>true</_SkipAnalyzers>
</PropertyGroup>

<!-- PERF: For builds which are indirectly triggered inside Visual Studio from commands
such as from 'Run Tests' or 'Start Debugging', we implicitly skip analyzers to speed up the build.
We only do so by default when 'TreatWarningsAsErrors' is not 'true'. For the scenario where
'TreatWarningsAsErrors' is 'true', users can explicitly enable this functionality by setting
'OptimizeImplicitlyTriggeredBuild' to 'true'.
-->
<PropertyGroup Condition="'$(_SkipAnalyzers)' == '' and
'$(IsImplicitlyTriggeredBuild)' == 'true' and
('$(TreatWarningsAsErrors)' != 'true' or '$(OptimizeImplicitlyTriggeredBuild)' == 'true')">
<_ImplicitlySkipAnalyzers>true</_ImplicitlySkipAnalyzers>
<_SkipAnalyzers>true</_SkipAnalyzers>
</PropertyGroup>

<!-- Display a message to inform the users about us implicitly skipping analyzers for speeding up indirect builds. -->
<ShowMessageForImplicitlySkipAnalyzers Condition="'$(_ImplicitlySkipAnalyzers)' == 'true'"/>

<!-- Semaphore file to indicate the time stamp for last build with skipAnalyzers flag. -->
<PropertyGroup>
<_LastBuildWithSkipAnalyzers>$(IntermediateOutputPath)$(MSBuildProjectFile).BuildWithSkipAnalyzers</_LastBuildWithSkipAnalyzers>
</PropertyGroup>

<!-- '_LastBuildWithSkipAnalyzers' semaphore file, if exists, is passed as custom additional file input to builds without skipAnalyzers flag to ensure correct incremental builds.
Additionally, we need to pass this file as an 'UpToDateCheckInput' item with 'Kind = ImplicitBuild' for project system's fast-upto-date check to work correctly.
See https://github.com/dotnet/project-system/issues/7290 for details.
-->
<ItemGroup Condition="Exists('$(_LastBuildWithSkipAnalyzers)')">
<CustomAdditionalCompileInputs Include="$(_LastBuildWithSkipAnalyzers)" Condition="'$(_SkipAnalyzers)' != 'true'"/>
<UpToDateCheckInput Include="$(_LastBuildWithSkipAnalyzers)" Kind="ImplicitBuild"/>
</ItemGroup>
</Target>

<!-- We touch and create a semaphore file after build to indicate the time stamp for last build with skipAnalyzers flag. -->
<Target Name="_TouchLastBuildWithSkipAnalyzers" Condition="'$(_SkipAnalyzers)' == 'true'" AfterTargets="CoreCompile">
<Touch AlwaysCreate="true" Files="$(_LastBuildWithSkipAnalyzers)"/>
</Target>

<!--
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.BuildTasks
{
/// <summary>
/// Logs a localizable message for implicitly skipping analyzers for implicitly triggered builds.
/// </summary>
public sealed class ShowMessageForImplicitlySkipAnalyzers : Task
{
public override bool Execute()
{
Log.LogMessage(MessageImportance.High, ErrorString.ImplicitlySkipAnalyzersMessage);
return true;
}
}
}
5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/Core/MSBuildTask/xlf/ErrorString.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 296cdd2

Please sign in to comment.