Allow overriding WarningsAsErrors policy with an env variable (#81402)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Tue, 31 Jan 2023 16:25:08 +0000 (01:25 +0900)
committerGitHub <noreply@github.com>
Tue, 31 Jan 2023 16:25:08 +0000 (11:25 -0500)
* Allow overriding WarningsAsErrors policy with an env variable

Placing `WarningsAsErrors=false` in an environment variable will disable the repo policy to waste people's time with frivolous warnings in their inner dev loop.

* Update build.sh

Directory.Build.props
eng/build.ps1
eng/build.sh
src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
src/coreclr/nativeaot/Directory.Build.props
src/coreclr/tools/aot/ILCompiler/repro/repro.csproj
src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj

index f3f56ce..9e8b408 100644 (file)
     <LangVersion Condition="'$(MSBuildProjectExtension)' == '.vbproj'">latest</LangVersion>
     <!-- Enables Strict mode for Roslyn compiler -->
     <Features>strict;nullablePublicOnly</Features>
-    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+    <TreatWarningsAsErrors Condition="'$(TreatWarningsAsErrors)' == ''">true</TreatWarningsAsErrors>
     <!-- Warnings to always disable -->
     <NoWarn>$(NoWarn),CS8969</NoWarn>
     <!-- Always pass portable to override arcade sdk which uses embedded for local builds -->
index a6a3941..aed36f5 100644 (file)
@@ -267,6 +267,10 @@ foreach ($argument in $PSBoundParameters.Keys)
   }
 }
 
+if ($env:TreatWarningsAsErrors -eq 'false') {
+  $arguments += " -warnAsError 0"
+}
+
 # Disable targeting pack caching as we reference a partially constructed targeting pack and update it later.
 # The later changes are ignored when using the cache.
 $env:DOTNETSDK_ALLOW_TARGETING_PACK_CACHING=0
index 215d93f..1147ec2 100755 (executable)
@@ -512,6 +512,10 @@ if [[ "$os" == "wasi" ]]; then
     arch=wasm
 fi
 
+if [[ "${TreatWarningsAsErrors:-}" == "false" ]]; then
+    arguments="$arguments -warnAsError 0"
+fi
+
 initDistroRid $os $arch $crossBuild $portableBuild
 
 # Disable targeting pack caching as we reference a partially constructed targeting pack and update it later.
index 1671023..5ee434a 100644 (file)
@@ -46,7 +46,6 @@
     <!-- Override InformationalVersion during servicing as it's returned via public api. -->
     <InformationalVersion Condition="'$(PreReleaseVersionLabel)' == 'servicing'">$(ProductVersion)</InformationalVersion>
     <InformationalVersion Condition="'$(StabilizePackageVersion)' == 'true'">$(ProductVersion)</InformationalVersion>
-    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <NoWarn>$(NoWarn),0419,0649,CA2249,CA1830</NoWarn>
     <Nullable>enable</Nullable>
 
index 94ee136..275f039 100644 (file)
@@ -25,7 +25,6 @@
     <!-- This prevents the default MsBuild targets from referencing System.Core.dll -->
     <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
     <RuntimeMetadataVersion>v4.0.30319</RuntimeMetadataVersion>
-    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <NoWarn>$(NoWarn),0419,0649,CA2249,CA1830</NoWarn>
 
     <!-- Disable nullability-related warnings -->
index f2d7f5c..48b2709 100644 (file)
@@ -9,7 +9,6 @@
     <RuntimeIdentifiers>linux-x64;win-x64;osx-x64;freebsd-x64</RuntimeIdentifiers>
     <Configurations>Debug;Release;Checked</Configurations>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
     <RunAnalyzers>false</RunAnalyzers>
   </PropertyGroup>
 
index fd6ada4..db2a7d2 100644 (file)
@@ -33,7 +33,6 @@
     <!-- Override InformationalVersion during servicing as it's returned via public api. -->
     <InformationalVersion Condition="'$(PreReleaseVersionLabel)' == 'servicing'">$(ProductVersion)</InformationalVersion>
     <InformationalVersion Condition="'$(StabilizePackageVersion)' == 'true'">$(ProductVersion)</InformationalVersion>
-    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <NoWarn>$(NoWarn),0419,0649</NoWarn>
     <Nullable>enable</Nullable>