From 02b738101662bf46fa560e117a38eaa747d58d92 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 1 Jul 2024 14:24:46 +0200 Subject: [PATCH] [tools] Ignore a few warnings by default. Fixes #20670. Ignore a few warnings by default, when reporting about types that we couldn't register because they're deprecated/removed. Also add a way to re-enable these warnings. Fixes https://github.com/xamarin/xamarin-macios/issues/20670. --- dotnet/targets/Xamarin.Shared.Sdk.targets | 1 + .../Tasks/ParseBundlerArguments.cs | 12 ++++++++++++ msbuild/Xamarin.Shared/Xamarin.Shared.targets | 1 + tools/common/Application.cs | 13 +++++++++++++ tools/common/Driver.cs | 7 +++++++ tools/dotnet-linker/LinkerConfiguration.cs | 7 +++++++ 6 files changed, 41 insertions(+) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index ddae59a13225..be60333c6f41 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -613,6 +613,7 @@ TargetFramework=$(_ComputedTargetFrameworkMoniker) UseLlvm=$(MtouchUseLlvm) Verbosity=$(_BundlerVerbosity) + Warn=$(_BundlerWarn) WarnAsError=$(_BundlerWarnAsError) XamarinNativeLibraryDirectory=$(_XamarinNativeLibraryDirectory) XamarinRuntime=$(_XamarinRuntime) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/ParseBundlerArguments.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/ParseBundlerArguments.cs index 189667609d66..8306fb77c447 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/ParseBundlerArguments.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/ParseBundlerArguments.cs @@ -67,6 +67,9 @@ public class ParseBundlerArguments : XamarinTask { [Output] public int Verbosity { get; set; } + [Output] + public string Warn { get; set; } + [Output] public string WarnAsError { get; set; } @@ -233,6 +236,15 @@ public override bool Execute () NoWarn += "," + value; } break; + case "warn": + if (!hasValue) + value = "-1"; // all warnings + if (string.IsNullOrEmpty (Warn)) { + Warn = value; + } else { + Warn += "," + value; + } + break; default: // Handle arguments like -vvv and -qqqq if (value.Length == 0 && name.Length > 1 && name.All (ch => ch == name [0])) { diff --git a/msbuild/Xamarin.Shared/Xamarin.Shared.targets b/msbuild/Xamarin.Shared/Xamarin.Shared.targets index f6139afd5347..eaf8166ea2f4 100644 --- a/msbuild/Xamarin.Shared/Xamarin.Shared.targets +++ b/msbuild/Xamarin.Shared/Xamarin.Shared.targets @@ -2039,6 +2039,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. + diff --git a/tools/common/Application.cs b/tools/common/Application.cs index d46dc5cc10e2..1ac9e9f1e9b1 100644 --- a/tools/common/Application.cs +++ b/tools/common/Application.cs @@ -1797,5 +1797,18 @@ public bool VerifyDynamicFramework (string framework_path) return dynamic; } + + static Application () + { + SetDefaultHiddenWarnings (); + } + + public static void SetDefaultHiddenWarnings () + { + // People don't like these warnings (#20670), and they also complicate our tests, so ignore them. + ErrorHelper.ParseWarningLevel (ErrorHelper.WarningLevel.Disable, "4178"); // The class '{0}' will not be registered because the {1} framework has been removed from the {2} SDK. + ErrorHelper.ParseWarningLevel (ErrorHelper.WarningLevel.Disable, "4189"); // The class '{0}' will not be registered because it has been removed from the {1} SDK. + ErrorHelper.ParseWarningLevel (ErrorHelper.WarningLevel.Disable, "4190"); // The class '{0}' will not be registered because the {1} framework has been deprecated from the {2} SDK. + } } } diff --git a/tools/common/Driver.cs b/tools/common/Driver.cs index 578d5f34ad68..d532e81c10a4 100644 --- a/tools/common/Driver.cs +++ b/tools/common/Driver.cs @@ -129,6 +129,13 @@ static bool ParseOptions (Application app, Mono.Options.OptionSet options, strin throw ErrorHelper.CreateError (26, ex, Errors.MX0026, "--nowarn", ex.Message); } }); + options.Add ("warn:", "An optional comma-separated list of warning codes to report as warnings (if no warnings are specified all warnings reported).", v => { + try { + ErrorHelper.ParseWarningLevel (ErrorHelper.WarningLevel.Warning, v); + } catch (Exception ex) { + throw ErrorHelper.CreateError (26, ex, Errors.MX0026, "--warn", ex.Message); + } + }); options.Add ("coop:", "If the GC should run in cooperative mode.", v => { app.EnableCoopGC = ParseBool (v, "coop"); }, hidden: true); options.Add ("sgen-conc", "Enable the *experimental* concurrent garbage collector.", v => { app.EnableSGenConc = true; }); options.Add ("marshal-objectivec-exceptions:", "Specify how Objective-C exceptions should be marshalled. Valid values: default, unwindmanagedcode, throwmanagedexception, abort and disable. The default depends on the target platform (on watchOS the default is 'throwmanagedexception', while on all other platforms it's 'disable').", v => { diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 5fe71596e981..b8a427f6f268 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -351,6 +351,13 @@ public static LinkerConfiguration GetInstance (LinkContext context) throw new InvalidOperationException ($"Invalid Verbosity '{value}' in {linker_file}"); Driver.Verbosity += verbosity; break; + case "Warn": + try { + ErrorHelper.ParseWarningLevel (ErrorHelper.WarningLevel.Warning, value); + } catch (Exception ex) { + throw new InvalidOperationException ($"Invalid Warn '{value}' in {linker_file}", ex); + } + break; case "WarnAsError": try { ErrorHelper.ParseWarningLevel (ErrorHelper.WarningLevel.Error, value);