[dotnet-linker] Improve error reporting by consolidating it in the LinkerConfiguration class. (#9992)

* Continue using our own error handling logic, and print our problems to stderr.
* Also use the linker's messaging facilities to report a more generic error,
  in case stderr doesn't show up for some reason.
This commit is contained in:
Rolf Bjarne Kvinge 2020-10-29 09:04:25 +01:00 коммит произвёл GitHub
Родитель 64edc26cb4
Коммит 42bd13cbdc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 36 добавлений и 10 удалений

Просмотреть файл

@ -37,7 +37,15 @@ namespace ObjCRuntime {
return new ProductException (code, false, innerException, message, args);
}
static void CollectExceptions (Exception ex, List<Exception> exceptions)
internal static IList<Exception> CollectExceptions (IEnumerable<Exception> exceptions)
{
var rv = new List<Exception> ();
foreach (var ex in exceptions)
CollectExceptions (ex, rv);
return rv;
}
internal static void CollectExceptions (Exception ex, List<Exception> exceptions)
{
AggregateException ae = ex as AggregateException;

Просмотреть файл

@ -272,12 +272,9 @@ namespace Xamarin.Bundler {
public static void Show (IEnumerable<Exception> list)
{
List<Exception> exceptions = new List<Exception> ();
var exceptions = CollectExceptions (list);
bool error = false;
foreach (var e in list)
CollectExceptions (e, exceptions);
foreach (var ex in exceptions)
error |= ShowInternal (ex);

Просмотреть файл

@ -283,6 +283,29 @@ namespace Xamarin.Linker {
document.Save (Path.Combine (ItemsDirectory, itemName + ".items"));
}
public void Report (params Exception [] exceptions)
{
Report ((IList<Exception>) exceptions);
}
public void Report (IList<Exception> exceptions)
{
// We can't really use the linker's reporting facilities and keep our own error codes, because we'll
// end up re-using the same error codes the linker already uses for its own purposes. So instead show
// a generic error using the linker's Context.LogMessage API, and then print our own errors to stderr.
// Since we print using a standard message format, msbuild will parse those error messages and show
// them as msbuild errors.
var list = ErrorHelper.CollectExceptions (exceptions);
var allWarnings = list.All (v => v is ProductException pe && !pe.Error);
if (!allWarnings) {
// Revisit the error code after https://github.com/mono/linker/issues/1596 has been fixed.
var msg = MessageContainer.CreateErrorMessage ("Failed to execute the custom steps.", 1999, Platform.ToString ());
Context.LogMessage (msg);
}
// ErrorHelper.Show will print our errors and warnings to stderr.
ErrorHelper.Show (list);
}
}
}

Просмотреть файл

@ -14,7 +14,7 @@ namespace Xamarin.Linker {
protected void Report (Exception exception)
{
ErrorHelper.Show (exception);
Configuration.Report (exception);
}
protected void Report (List<Exception> exceptions)

Просмотреть файл

@ -7,14 +7,12 @@ namespace Xamarin.Linker {
public abstract class ConfigurationAwareSubStep : ExceptionalSubStep {
protected override void Report (Exception exception)
{
ErrorHelper.Show (exception);
Configuration.Report (exception);
}
protected void Report (List<Exception> exceptions)
{
// Maybe there's a better way to show errors that integrates with the linker?
// We can't just throw an exception or exit here, since there might be only warnings in the list of exceptions.
ErrorHelper.Show (exceptions);
Configuration.Report (exceptions);
}
}
}