diff --git a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs index 8a88408c42d..a08447e838f 100644 --- a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs +++ b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixLegacyResourceDesignerStep.cs @@ -21,20 +21,8 @@ public class FixLegacyResourceDesignerStep : LinkDesignerBase { internal const string DesignerAssemblyName = "_Microsoft.Android.Resource.Designer"; internal const string DesignerAssemblyNamespace = "Microsoft.Android.Resource.Designer"; -#if ILLINK - protected override void Process () - { - cache = Context; - } -#else // ILLINK - public FixLegacyResourceDesignerStep (IMetadataResolver cache) - { - this.cache = cache; - } - readonly -#endif // ILLINK - IMetadataResolver cache; + bool designerLoaded = false; AssemblyDefinition designerAssembly = null; TypeDefinition designerType = null; Dictionary lookup; @@ -49,35 +37,34 @@ protected override void EndProcess () protected override void LoadDesigner () { - if (designerAssembly != null) + if (designerLoaded) return; - var designerNameAssembly = AssemblyNameReference.Parse ($"{DesignerAssemblyName}, Version=1.0.0.0"); try { - designerAssembly = Resolve (designerNameAssembly); - } catch (Mono.Cecil.AssemblyResolutionException) { - LogMessage ($" Could not resolve assembly {DesignerAssemblyName}."); - } catch (System.IO.FileNotFoundException) { - LogMessage ($" Assembly {DesignerAssemblyName} did not exist."); - } - if (designerAssembly == null) { - return; - } - designerType = designerAssembly.MainModule.GetTypes ().FirstOrDefault (x => x.FullName == $"{DesignerAssemblyNamespace}.Resource"); - if (designerType == null) { - LogMessage ($" Did not find {DesignerAssemblyNamespace}.Resource type. It was probably linked out."); - return; + var designerNameAssembly = AssemblyNameReference.Parse ($"{DesignerAssemblyName}, Version=1.0.0.0"); + try { + designerAssembly = Resolve (designerNameAssembly); + LogMessage ($" Loaded {designerNameAssembly}"); + } catch (Mono.Cecil.AssemblyResolutionException) { + LogMessage ($" Could not resolve assembly {DesignerAssemblyName}."); + } catch (System.IO.FileNotFoundException) { + LogMessage ($" Assembly {DesignerAssemblyName} did not exist."); + } + if (designerAssembly == null) { + return; + } + designerType = designerAssembly.MainModule.GetTypes ().FirstOrDefault (x => x.FullName == $"{DesignerAssemblyNamespace}.Resource"); + if (designerType == null) { + LogMessage ($" Did not find {DesignerAssemblyNamespace}.Resource type. It was probably linked out."); + return; + } + lookup = BuildResourceDesignerPropertyLookup (designerType); + } finally { + designerLoaded = true; } - lookup = BuildResourceDesignerPropertyLookup (designerType); - return; } internal override bool ProcessAssemblyDesigner (AssemblyDefinition assembly) { - if (designerAssembly == null || designerType == null) { - LogMessage ($" Not using {DesignerAssemblyName}"); - return false; - } - if (!FindResourceDesigner (assembly, mainApplication: false, out TypeDefinition designer, out CustomAttribute designerAttribute)) { LogMessage ($" {assembly.Name.Name} has no designer. "); return false; @@ -90,6 +77,15 @@ internal override bool ProcessAssemblyDesigner (AssemblyDefinition assembly) return false; } + // This is expected for the first call, in + if (!designerLoaded) + LoadDesigner (); + + if (designerAssembly == null || designerType == null) { + LogMessage ($" Not using {DesignerAssemblyName}"); + return false; + } + LogMessage ($" Adding reference {designerAssembly.Name.Name}."); assembly.MainModule.AssemblyReferences.Add (designerAssembly.Name); var importedDesignerType = assembly.MainModule.ImportReference (designerType.Resolve ()); @@ -114,9 +110,10 @@ Dictionary BuildResourceDesignerPropertyLookup (TypeDe foreach (PropertyDefinition property in definition.Properties) { string key = $"{definition.Name}::{property.Name}"; - if (!output.ContainsKey (key)) { - LogMessage ($" Adding {key}"); - output.Add(key, property.GetMethod); + if (output.ContainsKey (key)) { + LogMessage ($" Found duplicate {key}"); + } else { + output.Add (key, property.GetMethod); } } } diff --git a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/Linker.cs b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/Linker.cs index 45c3a3feeb3..a7a2c864c9f 100644 --- a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/Linker.cs +++ b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/Linker.cs @@ -112,7 +112,7 @@ static Pipeline CreatePipeline (LinkerOptions options) // end monodroid specific if (options.UseDesignerAssembly) - pipeline.AppendStep (new FixLegacyResourceDesignerStep (cache)); + pipeline.AppendStep (new FixLegacyResourceDesignerStep ()); pipeline.AppendStep (new FixAbstractMethodsStep (cache)); pipeline.AppendStep (new MonoDroidMarkStep (cache)); pipeline.AppendStep (new SweepStep ()); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs b/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs index 5d4c65c8509..78804fcf315 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs @@ -66,9 +66,7 @@ public override bool RunTask () var cache = new TypeDefinitionCache (); var fixAbstractMethodsStep = new FixAbstractMethodsStep (resolver, cache, Log); var addKeepAliveStep = new AddKeepAlivesStep (resolver, cache, Log, UsingAndroidNETSdk); - var fixLegacyResourceDesignerStep = new FixLegacyResourceDesignerStep (resolver, cache, Log); - if (UseDesignerAssembly) - fixLegacyResourceDesignerStep.Load (); + var fixLegacyResourceDesignerStep = new FixLegacyResourceDesignerStep (resolver, Log); for (int i = 0; i < SourceFiles.Length; i++) { var source = SourceFiles [i]; var destination = DestinationFiles [i]; @@ -133,17 +131,12 @@ class FixLegacyResourceDesignerStep : MonoDroid.Tuner.FixLegacyResourceDesignerS readonly DirectoryAssemblyResolver resolver; readonly TaskLoggingHelper logger; - public FixLegacyResourceDesignerStep (DirectoryAssemblyResolver resolver, TypeDefinitionCache cache, TaskLoggingHelper logger) - : base (cache) + public FixLegacyResourceDesignerStep (DirectoryAssemblyResolver resolver, TaskLoggingHelper logger) { this.resolver = resolver; this.logger = logger; } - public void Load () { - LoadDesigner (); - } - public override void LogMessage (string message) { logger.LogDebugMessage ("{0}", message);