From 3c6c1ecf66ed7e9b147e977dcd425b531e3e463e Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Wed, 25 Apr 2018 17:38:31 -0700 Subject: [PATCH] Link the BCL Enable the Link option for BCL assemblies. Mscorlib is excluded because the CSLA library wasn't working when it gets linked. Fixes #89 --- Ooui.Wasm.Build.Tasks/BuildDistTask.cs | 51 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/Ooui.Wasm.Build.Tasks/BuildDistTask.cs b/Ooui.Wasm.Build.Tasks/BuildDistTask.cs index cc2bff1..c889e0a 100644 --- a/Ooui.Wasm.Build.Tasks/BuildDistTask.cs +++ b/Ooui.Wasm.Build.Tasks/BuildDistTask.cs @@ -41,7 +41,7 @@ namespace Ooui.Wasm.Build.Tasks return ok; } catch (Exception ex) { - Console.WriteLine (ex); + //Console.WriteLine (ex); Log.LogErrorFromException (ex); return false; } @@ -227,11 +227,14 @@ namespace Ooui.Wasm.Build.Tasks Pipeline GetLinkerPipeline () { + IEnumerable bclNames = bclAssemblies.Values.Select (Path.GetFileNameWithoutExtension); + var p = new Pipeline (); p.AppendStep (new DontLinkExeStep ()); p.AppendStep (new LoadReferencesStep ()); - p.AppendStep (new PreserveUsingAttributesStep (bclAssemblies.Values.Select (Path.GetFileNameWithoutExtension))); + p.AppendStep (new PreserveUsingAttributesStep (bclNames)); p.AppendStep (new BlacklistStep ()); + p.AppendStep (new LinkBclStep (bclNames)); p.AppendStep (new TypeMapStep ()); p.AppendStep (new MarkStepWithUnresolvedLogging (this)); p.AppendStep (new SweepStep ()); @@ -251,6 +254,48 @@ namespace Ooui.Wasm.Build.Tasks } } + class LinkBclStep : BaseStep + { + HashSet bclNames; + List> preserveTypeNames; + + public LinkBclStep (IEnumerable bclNames) + { + // CSLA cannot tolerate mscorlib being linked (uses reflection over types it doesn't reference) + this.bclNames = new HashSet (bclNames.Where(x => x != "mscorlib")); + preserveTypeNames = new List> { + Tuple.Create ("System", "System.ComponentModel.IEditableObject"), + Tuple.Create ("System", "System.ComponentModel.IDataErrorInfo"), + }; + } + + protected override void Process () + { + var asms = Context.GetAssemblies (); + + foreach (var a in asms) { + if (bclNames.Contains (a.Name.Name)) { + Annotations.SetAction (a, AssemblyAction.Link); + } + } + + foreach (var p in preserveTypeNames) { + var asm = asms.FirstOrDefault (x => x.Name.Name == p.Item1); + if (asm == null) + throw new Exception ($"Could not find assembly {p.Item1}"); + var t = asm.MainModule.GetType (p.Item2); + if (t == null) + throw new Exception ($"Could not find type {p.Item2} in {p.Item1}"); + Annotations.SetPreserve (t, TypePreserve.All); + } + + //foreach (var a in asms) { + // var act = Annotations.GetAction (a); + // Console.WriteLine ($"{act} {a.Name.Name}"); + //} + } + } + class MarkStepWithUnresolvedLogging : MarkStep { BuildDistTask task; @@ -376,8 +421,6 @@ namespace Ooui.Wasm.Build.Tasks class LinkerMetadataResolver : MetadataResolver { - LinkerAssemblyResolver resolver; - readonly AssemblyNameReference mscorlibScope = new AssemblyNameReference ("mscorlib", new Version (1, 0)); public LinkerMetadataResolver (LinkerAssemblyResolver asmResolver)