diff --git a/tools/dotnet-linker/SetupStep.cs b/tools/dotnet-linker/SetupStep.cs index 3e5d13f98d..0281906cba 100644 --- a/tools/dotnet-linker/SetupStep.cs +++ b/tools/dotnet-linker/SetupStep.cs @@ -13,6 +13,8 @@ using Xamarin.Linker.Steps; namespace Xamarin { public class SetupStep : ConfigurationAwareStep { + protected override string Name { get; } = "Setup"; + protected override int ErrorCode { get; } = 2300; List _steps; public List Steps { @@ -47,7 +49,7 @@ namespace Xamarin { throw new InvalidOperationException ($"Could not insert {step} after {stepName} because {stepName} wasn't found."); } - protected override void Process () + protected override void TryProcess () { // Don't use --custom-step to load each step, because this assembly // is loaded into the current process once per --custom-step, diff --git a/tools/dotnet-linker/Steps/CollectAssembliesStep.cs b/tools/dotnet-linker/Steps/CollectAssembliesStep.cs index 413cce2b1a..8c0cde6ce3 100644 --- a/tools/dotnet-linker/Steps/CollectAssembliesStep.cs +++ b/tools/dotnet-linker/Steps/CollectAssembliesStep.cs @@ -2,9 +2,12 @@ using Mono.Cecil; namespace Xamarin.Linker { public class CollectAssembliesStep : ConfigurationAwareStep { - protected override void ProcessAssembly (AssemblyDefinition assembly) + protected override string Name { get; } = "Collect Assemblies"; + protected override int ErrorCode { get; } = 2330; + + protected override void TryProcessAssembly (AssemblyDefinition assembly) { - base.ProcessAssembly (assembly); + base.TryProcessAssembly (assembly); Configuration.Assemblies.Add (assembly); } diff --git a/tools/dotnet-linker/Steps/CollectUnmarkedMembers.cs b/tools/dotnet-linker/Steps/CollectUnmarkedMembers.cs index 73ab545d9b..ca3a82162a 100644 --- a/tools/dotnet-linker/Steps/CollectUnmarkedMembers.cs +++ b/tools/dotnet-linker/Steps/CollectUnmarkedMembers.cs @@ -10,13 +10,16 @@ namespace Xamarin.Linker { public class CollectUnmarkedMembersSubStep : ConfigurationAwareSubStep { Dictionary> ProtocolImplementations => Configuration.DerivedLinkContext.ProtocolImplementations; + protected override string Name { get; } = "Collect Unmarked Members"; + protected override int ErrorCode { get; } = 2230; + public override SubStepTargets Targets { get { return SubStepTargets.Type; } } - public override void ProcessType (TypeDefinition type) + protected override void Process (TypeDefinition type) { if (!Annotations.IsMarked (type)) LinkContext.AddLinkedAwayType (type); diff --git a/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs b/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs index 8ea1de93a1..4f1cfa582f 100644 --- a/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs +++ b/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; + +using Mono.Cecil; using Mono.Linker.Steps; using Xamarin.Bundler; @@ -21,5 +23,69 @@ namespace Xamarin.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); } + + protected sealed override void Process () + { + try { + TryProcess (); + } catch (Exception e) { + Report (Fail (e)); + } + } + + protected sealed override void ProcessAssembly (AssemblyDefinition assembly) + { + try { + TryProcessAssembly (assembly); + } catch (Exception e) { + Report (Fail (assembly, e)); + } + } + + protected sealed override void EndProcess () + { + try { + TryEndProcess (); + } catch (Exception e) { + Report (FailEnd (e)); + } + } + + // state-aware versions to be subclassed + protected virtual void TryProcess () + { + } + + protected virtual void TryProcessAssembly (AssemblyDefinition assembly) + { + } + + protected virtual void TryEndProcess () + { + } + + // failure overrides, with defaults + + protected virtual Exception Fail (AssemblyDefinition assembly, Exception e) + { + /* Re-use MX_ExceptionalSubSteps here, it works just fine */ + return ErrorHelper.CreateError (ErrorCode, e, Errors.MX_ExceptionalSubSteps, Name, assembly?.FullName); + } + + protected virtual Exception Fail (Exception e) + { + return ErrorHelper.CreateError (ErrorCode | 1, e, Errors.MX_ConfigurationAwareStep, Name); + } + + protected virtual Exception FailEnd (Exception e) + { + return ErrorHelper.CreateError (ErrorCode | 2, e, Errors.MX_ConfigurationAwareStep, Name); + } + + // abstracts + + protected abstract string Name { get; } + + protected abstract int ErrorCode { get; } } } diff --git a/tools/dotnet-linker/Steps/ConfigurationAwareSubStep.cs b/tools/dotnet-linker/Steps/ConfigurationAwareSubStep.cs index 60d1b2dc54..5d7e0bf050 100644 --- a/tools/dotnet-linker/Steps/ConfigurationAwareSubStep.cs +++ b/tools/dotnet-linker/Steps/ConfigurationAwareSubStep.cs @@ -1,27 +1,11 @@ using System; using System.Collections.Generic; -using Mono.Linker; -using Mono.Linker.Steps; using Xamarin.Bundler; -using Xamarin.Tuner; namespace Xamarin.Linker { - public abstract class ConfigurationAwareSubStep : BaseSubStep { - public LinkerConfiguration Configuration { get; private set; } - - public DerivedLinkContext LinkContext { - get { return Configuration.DerivedLinkContext; } - } - - public override sealed void Initialize (LinkContext context) - { - base.Initialize (context); - - Configuration = LinkerConfiguration.GetInstance (context); - } - - protected void Report (Exception exception) + public abstract class ConfigurationAwareSubStep : ExceptionalSubStep { + protected override void Report (Exception exception) { ErrorHelper.Show (exception); } @@ -34,4 +18,3 @@ namespace Xamarin.Linker { } } } - diff --git a/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs b/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs index 0327986f07..709efaeab6 100644 --- a/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs +++ b/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs @@ -4,10 +4,11 @@ using System.Collections.Generic; namespace Xamarin.Linker { public class ExtractBindingLibrariesStep : ConfigurationAwareStep { - protected override void EndProcess () - { - base.EndProcess (); + protected override string Name { get; } = "Extract Binding Libraries"; + protected override int ErrorCode { get; } = 2340; + protected override void TryEndProcess () + { // No attributes are currently linked away, which means we don't need to worry about linked away LinkWith attributes. // Ref: https://github.com/mono/linker/issues/952 (still open as of this writing). var exceptions = new List (); diff --git a/tools/dotnet-linker/Steps/GatherFrameworksStep.cs b/tools/dotnet-linker/Steps/GatherFrameworksStep.cs index 676c995089..d9ec7be159 100644 --- a/tools/dotnet-linker/Steps/GatherFrameworksStep.cs +++ b/tools/dotnet-linker/Steps/GatherFrameworksStep.cs @@ -8,12 +8,15 @@ using Xamarin.Linker; namespace Xamarin { public class GatherFrameworksStep : ConfigurationAwareStep { + protected override string Name { get; } = "Gather Frameworks"; + protected override int ErrorCode { get; } = 2310; + HashSet Frameworks = new HashSet (); HashSet WeakFrameworks = new HashSet (); - protected override void ProcessAssembly (AssemblyDefinition assembly) + protected override void TryProcessAssembly (AssemblyDefinition assembly) { - base.ProcessAssembly (assembly); + base.TryProcessAssembly (assembly); if (Configuration.PlatformAssembly != assembly.Name.Name) return; @@ -21,10 +24,8 @@ namespace Xamarin { global::Frameworks.Gather (Configuration.Application, assembly, Frameworks, WeakFrameworks); } - protected override void EndProcess () + protected override void TryEndProcess () { - base.EndProcess (); - // Remove duplicates. WeakFrameworks takes precedence Frameworks.ExceptWith (WeakFrameworks); diff --git a/tools/dotnet-linker/Steps/GenerateMainStep.cs b/tools/dotnet-linker/Steps/GenerateMainStep.cs index bd0fec8c38..7fdff7c92e 100644 --- a/tools/dotnet-linker/Steps/GenerateMainStep.cs +++ b/tools/dotnet-linker/Steps/GenerateMainStep.cs @@ -7,9 +7,12 @@ using Xamarin.Linker; namespace Xamarin { public class GenerateMainStep : ConfigurationAwareStep { - protected override void EndProcess () + protected override string Name { get; } = "Generate Main"; + protected override int ErrorCode { get; } = 2320; + + protected override void TryEndProcess () { - base.EndProcess (); + base.TryEndProcess (); var registration_methods = new List (Configuration.RegistrationMethods); var items = new List (); diff --git a/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs b/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs index a6a7d99054..67d1ba03bf 100644 --- a/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs +++ b/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs @@ -6,10 +6,12 @@ using Mono.Linker; namespace Xamarin.Linker { // List all the assemblies we care about (i.e. the ones that have not been linked away) public class LoadNonSkippedAssembliesStep : ConfigurationAwareStep { + protected override string Name { get; } = "Load Non Skipped Assemblies"; + protected override int ErrorCode { get; } = 2350; - protected override void ProcessAssembly (AssemblyDefinition assembly) + protected override void TryProcessAssembly (AssemblyDefinition assembly) { - base.ProcessAssembly (assembly); + base.TryProcessAssembly (assembly); // Figure out if an assembly is linked away or not if (Context.Annotations.HasAction (assembly)) { diff --git a/tools/dotnet-linker/Steps/PreserveBlockCodeSubStep.cs b/tools/dotnet-linker/Steps/PreserveBlockCodeSubStep.cs index d7e9b1b5cb..4af7179d61 100644 --- a/tools/dotnet-linker/Steps/PreserveBlockCodeSubStep.cs +++ b/tools/dotnet-linker/Steps/PreserveBlockCodeSubStep.cs @@ -13,6 +13,9 @@ namespace Xamarin.Linker.Steps { MethodDefinition ctor_string_def; MethodReference ctor_string_ref; + protected override string Name { get; } = "Preserve Block Code"; + protected override int ErrorCode { get; } = 2240; + public override SubStepTargets Targets { get { return SubStepTargets.Assembly | @@ -53,18 +56,14 @@ namespace Xamarin.Linker.Steps { return ctor_string_ref; } - public override void ProcessAssembly (AssemblyDefinition assembly) + protected override void Process (AssemblyDefinition assembly) { // Clear out the method reference we have, so that we import the method definition again ctor_string_ref = null; - - base.ProcessAssembly (assembly); } - public override void ProcessField (FieldDefinition field) + protected override void Process (FieldDefinition field) { - base.ProcessField (field); - PreserveBlockField (field); } diff --git a/tools/dotnet-linker/Steps/RegistrarStep.cs b/tools/dotnet-linker/Steps/RegistrarStep.cs index 0b34d62c5d..a25ff7fda2 100644 --- a/tools/dotnet-linker/Steps/RegistrarStep.cs +++ b/tools/dotnet-linker/Steps/RegistrarStep.cs @@ -6,10 +6,11 @@ using Xamarin.Utils; namespace Xamarin.Linker { public class RegistrarStep : ConfigurationAwareStep { - protected override void EndProcess () - { - base.EndProcess (); + protected override string Name { get; } = "Registrar"; + protected override int ErrorCode { get; } = 2360; + protected override void TryEndProcess () + { var app = Configuration.Application; app.SelectRegistrar (); diff --git a/tools/linker/ExceptionalSubStep.cs b/tools/linker/ExceptionalSubStep.cs index 2ec443becf..ef1ee32703 100644 --- a/tools/linker/ExceptionalSubStep.cs +++ b/tools/linker/ExceptionalSubStep.cs @@ -47,7 +47,7 @@ namespace Xamarin.Linker { try { Process (assembly); } catch (Exception e) { - throw Fail (assembly, e); + Report (Fail (assembly, e)); } } @@ -56,7 +56,7 @@ namespace Xamarin.Linker { try { Process (type); } catch (Exception e) { - throw Fail (type, e); + Report (Fail (type, e)); } } @@ -65,7 +65,7 @@ namespace Xamarin.Linker { try { Process (field); } catch (Exception e) { - throw Fail (field, e); + Report (Fail (field, e)); } } @@ -74,7 +74,7 @@ namespace Xamarin.Linker { try { Process (method); } catch (Exception e) { - throw Fail (method, e); + Report (Fail (method, e)); } } @@ -83,7 +83,7 @@ namespace Xamarin.Linker { try { Process (property); } catch (Exception e) { - throw Fail (property, e); + Report (Fail (property, e)); } } @@ -92,7 +92,7 @@ namespace Xamarin.Linker { try { Process (@event); } catch (Exception e) { - throw Fail (@event, e); + Report (Fail (@event, e)); } } @@ -154,6 +154,11 @@ namespace Xamarin.Linker { return ErrorHelper.CreateError (ErrorCode | 5, e, Errors.MX_ExceptionalSubSteps, Name, @event?.FullName); } + protected virtual void Report (Exception e) + { + throw e; + } + // abstracts protected abstract string Name { get; } diff --git a/tools/mtouch/Errors.designer.cs b/tools/mtouch/Errors.designer.cs index 2f7c1af927..4fc32d4992 100644 --- a/tools/mtouch/Errors.designer.cs +++ b/tools/mtouch/Errors.designer.cs @@ -1523,6 +1523,12 @@ namespace Xamarin.Bundler { } } + internal static string MX_ConfigurationAwareStep { + get { + return ResourceManager.GetString("MX_ConfigurationAwareStep", resourceCulture); + } + } + internal static string MX3001 { get { return ResourceManager.GetString("MX3001", resourceCulture); diff --git a/tools/mtouch/Errors.resx b/tools/mtouch/Errors.resx index 68fc05ae6b..26d9cbc9ef 100644 --- a/tools/mtouch/Errors.resx +++ b/tools/mtouch/Errors.resx @@ -1295,7 +1295,26 @@ + + + + + + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + + + + + + + + + + Could not {0} the assembly '{1}' diff --git a/tools/mtouch/xlf/Errors.cs.xlf b/tools/mtouch/xlf/Errors.cs.xlf index 5eccd3082c..898da95b57 100644 --- a/tools/mtouch/xlf/Errors.cs.xlf +++ b/tools/mtouch/xlf/Errors.cs.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.de.xlf b/tools/mtouch/xlf/Errors.de.xlf index 2849579f3b..ec5d6d3585 100644 --- a/tools/mtouch/xlf/Errors.de.xlf +++ b/tools/mtouch/xlf/Errors.de.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.es.xlf b/tools/mtouch/xlf/Errors.es.xlf index dfd4dc41f3..725ec64436 100644 --- a/tools/mtouch/xlf/Errors.es.xlf +++ b/tools/mtouch/xlf/Errors.es.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.fr.xlf b/tools/mtouch/xlf/Errors.fr.xlf index c25d8c5172..ec20c6e4c7 100644 --- a/tools/mtouch/xlf/Errors.fr.xlf +++ b/tools/mtouch/xlf/Errors.fr.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.it.xlf b/tools/mtouch/xlf/Errors.it.xlf index 30f72bd83a..9a5a462992 100644 --- a/tools/mtouch/xlf/Errors.it.xlf +++ b/tools/mtouch/xlf/Errors.it.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.ja.xlf b/tools/mtouch/xlf/Errors.ja.xlf index 22d70d86a3..659caacb14 100644 --- a/tools/mtouch/xlf/Errors.ja.xlf +++ b/tools/mtouch/xlf/Errors.ja.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.ko.xlf b/tools/mtouch/xlf/Errors.ko.xlf index 9f527d82a1..e980a98462 100644 --- a/tools/mtouch/xlf/Errors.ko.xlf +++ b/tools/mtouch/xlf/Errors.ko.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.pl.xlf b/tools/mtouch/xlf/Errors.pl.xlf index 302a94928f..0d3685aaf5 100644 --- a/tools/mtouch/xlf/Errors.pl.xlf +++ b/tools/mtouch/xlf/Errors.pl.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.pt-BR.xlf b/tools/mtouch/xlf/Errors.pt-BR.xlf index 424b2b1121..b0b31a3b8b 100644 --- a/tools/mtouch/xlf/Errors.pt-BR.xlf +++ b/tools/mtouch/xlf/Errors.pt-BR.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.ru.xlf b/tools/mtouch/xlf/Errors.ru.xlf index 95c3af6286..50dee78e32 100644 --- a/tools/mtouch/xlf/Errors.ru.xlf +++ b/tools/mtouch/xlf/Errors.ru.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.tr.xlf b/tools/mtouch/xlf/Errors.tr.xlf index c2036d0f45..36c57bc7b3 100644 --- a/tools/mtouch/xlf/Errors.tr.xlf +++ b/tools/mtouch/xlf/Errors.tr.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.zh-Hans.xlf b/tools/mtouch/xlf/Errors.zh-Hans.xlf index dcbd108ca6..318a4940fe 100644 --- a/tools/mtouch/xlf/Errors.zh-Hans.xlf +++ b/tools/mtouch/xlf/Errors.zh-Hans.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`. diff --git a/tools/mtouch/xlf/Errors.zh-Hant.xlf b/tools/mtouch/xlf/Errors.zh-Hant.xlf index aba0264dbf..61739037b0 100644 --- a/tools/mtouch/xlf/Errors.zh-Hant.xlf +++ b/tools/mtouch/xlf/Errors.zh-Hant.xlf @@ -2768,6 +2768,13 @@ + + The linker step '{0}' failed during processing. + The linker step '{0}' failed during processing. + This is a message when processing fails in the linker. + {0} - The name of the step that fails. + + The linker step '{0}' failed processing `{1}`. The linker step '{0}' failed processing `{1}`.