Skip to content

Commit

Permalink
[ci] Set $(TreatWarningsAsErrors) = true for CI builds. (#9689)
Browse files Browse the repository at this point in the history
Modern best practices for software development recommend treating
warnings as errors.  Although the majority of warnings are benign,
warnings for any potential actual issues will be lost in the sea of
benign warnings and will not be caught.

However, having to fix warnings during the development process can be
annoying as code is often in a temporary state.  As a balance, we
only error on warnings when building on CI.  This way local
development isn't hindered, but CI will protect us from committing
new warnings.

Developers can opt-in to the errors locally by setting
`$(_AndroidTreatWarningsAsErrors)` to `true`.

There are several projects that have warnings today.  For now, we
will simply grandfather those projects in, allowing us to move
forward with protecting the rest of the projects from new warnings.
With time, we should endeavor to fix these projects' warnings and
remove them from this list.  (Our build currently has ~170 warnings
spread across these projects.)
  • Loading branch information
jpobst authored Jan 27, 2025
1 parent 5b0d78b commit d3cde47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,30 @@
<HumanizerVersion>2.14.1</HumanizerVersion>
<MdocPackageVersion Condition=" '$(MdocPackageVersion)' == '' ">5.9.3</MdocPackageVersion>
</PropertyGroup>

<PropertyGroup>
<!--
Use $(TreatWarningsAsErrors) for CI builds. We have grandfathered some projects that have existing warnings,
but we would like to go ahead and prevent any other projects from getting new warnings.
This can be opted into locally with $(_AndroidTreatWarningsAsErrors) = true.
-->
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'assembly-store-reader.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'decompress-assemblies.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'jnienv-gen.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Microsoft.Android.Sdk.ILLink.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Microsoft.Android.Templates.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Mono.Android.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Mono.Android.NET-Tests.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'MSBuildDeviceIntegration.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'NativeAOT.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'TestRunner.Core.NET.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.Build.Tasks.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.Build.Tests.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.JcwGen-Tests.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.NUnitLite.NET.csproj' ">true</_AllowProjectWarnings>
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.ProjectTools.csproj' ">true</_AllowProjectWarnings>
<TreatWarningsAsErrors Condition=" ('$(RunningOnCI)' == 'true' OR '$(_AndroidTreatWarningsAsErrors)' == 'true') AND '$(_AllowProjectWarnings)' != 'true' ">true</TreatWarningsAsErrors>
</PropertyGroup>

</Project>
1 change: 0 additions & 1 deletion samples/HelloWorld/HelloLibrary/LibraryActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ protected override void OnCreate(Bundle bundle)

#if __ANDROID_8__
public class MyBackupAgent : BackupAgent {
[Preserve]
public MyBackupAgent ()
{
}
Expand Down

0 comments on commit d3cde47

Please sign in to comment.