From b43812161dea5d390bd584d5aa8ed6890ca861f2 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Thu, 20 Oct 2016 16:03:30 -0400 Subject: [PATCH 1/3] [msbuild] Fix how UnpackLibraryResources handles mscorlib.dll (and potentially other framework assemblies) Target _UnpackLibraryResources: Task "UnpackLibraryResources" Using task UnpackLibraryResources from Xamarin.MacDev.Tasks.UnpackLibraryResources, Xamarin.MacDev.Tasks, Version=1.0.6128.15885, Culture=neutral, PublicKeyToken=null UnpackLibraryResources Task Prefix: monotouch IntermediateOutputPath: obj/iPhone/Debug/ NoOverwrite: obj/iPhone/Debug/ibtool-link/LaunchScreen.storyboardc/01J-lp-oVM-view-Ze5-6b-2t3.nib obj/iPhone/Debug/ibtool-link/LaunchScreen.storyboardc/Info.plist obj/iPhone/Debug/ibtool-link/LaunchScreen.storyboardc/UIViewController-01J-lp-oVM.nib obj/iPhone/Debug/ibtool-link/Main.storyboardc/BYZ-38-t0r-view-8bC-Xf-vdC.nib obj/iPhone/Debug/ibtool-link/Main.storyboardc/Info.plist obj/iPhone/Debug/ibtool-link/Main.storyboardc/UIViewController-BYZ-38-t0r.nib ReferencedLibraries: /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.dll /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Xml.dll /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Core.dll /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll /Users/poupou/Downloads/LinkingTest-2/RMSDKWrapper/bin/Debug//RMSDKWrapper.dll /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS//mscorlib.dll /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS//mscorlib.dll Skipping framework assembly: /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.dll Skipping framework assembly: /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Xml.dll Skipping framework assembly: /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Core.dll Skipping framework assembly: /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll Inspecting assembly: /Users/poupou/Downloads/LinkingTest-2/RMSDKWrapper/bin/Debug//RMSDKWrapper.dll Inspecting assembly: /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS//mscorlib.dll Inspecting assembly: /Users/poupou/git/xamarin/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS//mscorlib.dll Done executing task "UnpackLibraryResources" Done building target "_UnpackLibraryResources" in project "/Users/poupou/Downloads/LinkingTest-2/LinkingTest/LinkingTest.csproj". The above log excerpt shows two issues: 1. mscorlib.dll is needlessly inspected as it's **not** considered a "framework" assembly. The current check was checking *how* it was resolved and not *where* it was resolved to. The later is the most important as it's possible for other assemblies to have direct paths references and we do not want to process them. This is fixed by comparing each assembly path with the (now) provided `TargetFrameworkDirectory` 2. mscorlib.dll is inspected twice That's because it's present two times in the task's input. That issue is upstream (not sure why) of the current task but it makes #1 twice as costly. The fix for #1 indirectly fix that too. Future ------ It's worth investigating to move that logic into `mtouch`. The later must already load all assemblies and is in charge of removing other embedded data (e.g. native code from bindings) from the assemblies (so they are not shipped both inside and outside the .dll in the final .app). This makes this task seems extraneous work. Considering that my current test case, `RMSDKWrapper.dll`, is 1.3GB in size it's easy to see that the extra load (which has nothing to be extracted wrt resources*) is quite visible in build time. > 3268.201 ms UnpackLibraryResources 1 calls * it has for bindings but that's already handled by mtouch --- .../Tasks/UnpackLibraryResourcesTaskBase.cs | 17 ++++++++++++++++- .../Xamarin.iOS.Common.targets | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/UnpackLibraryResourcesTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/UnpackLibraryResourcesTaskBase.cs index ab19ba3d2601..0d8ffa90bba3 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/UnpackLibraryResourcesTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/UnpackLibraryResourcesTaskBase.cs @@ -26,6 +26,9 @@ public abstract class UnpackLibraryResourcesTaskBase : Task [Required] public ITaskItem[] ReferencedLibraries { get; set; } + [Required] + public ITaskItem[] TargetFrameworkDirectory { get; set; } + #endregion #region Outputs @@ -42,6 +45,7 @@ public override bool Execute () Log.LogTaskProperty ("IntermediateOutputPath", IntermediateOutputPath); Log.LogTaskProperty ("NoOverwrite", NoOverwrite); Log.LogTaskProperty ("ReferencedLibraries", ReferencedLibraries); + Log.LogTaskProperty ("TargetFrameworkDirectory", TargetFrameworkDirectory); // TODO: give each assembly its own intermediate output directory // TODO: use list file to avoid re-extracting assemblies but allow FileWrites to work @@ -49,7 +53,9 @@ public override bool Execute () HashSet ignore = null; foreach (var asm in ReferencedLibraries) { - if (asm.GetMetadata ("ResolvedFrom") == "{TargetFrameworkDirectory}") { + // mscorlib.dll was not coming out with ResolvedFrom == {TargetFrameworkDirectory} + // and what we really care is where it comes from, not how it was resolved + if (IsFrameworkAssembly (asm)) { Log.LogMessage (MessageImportance.Low, " Skipping framework assembly: {0}", asm.ItemSpec); } else { var extracted = ExtractContentAssembly (asm.ItemSpec, IntermediateOutputPath); @@ -83,6 +89,15 @@ public override bool Execute () return !Log.HasLoggedErrors; } + bool IsFrameworkAssembly (ITaskItem asm) + { + foreach (var dir in TargetFrameworkDirectory) { + if (asm.ItemSpec.StartsWith (dir.ItemSpec, StringComparison.Ordinal)) + return true; + } + return false; + } + IEnumerable ExtractContentAssembly (string assembly, string intermediatePath) { Log.LogMessage (MessageImportance.Low, " Inspecting assembly: {0}", assembly); diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets index 021308248d3b..986f4f56a1af 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets @@ -531,6 +531,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. Prefix="monotouch" NoOverwrite="@(_BundleResourceWithLogicalName)" IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)" + TargetFrameworkDirectory="$(TargetFrameworkDirectory)" ReferencedLibraries="@(ReferencePath);@(ReferenceDependencyPaths)"> From 9dcebe3c26bc78bc4ffbbc80cf579e88741596db Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Mon, 9 Jan 2017 21:20:53 -0500 Subject: [PATCH 2/3] Add TargetFrameworkDirectory for XM too (should fix the build issue on bots) --- msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets index 4e2d278372f7..cbafbb1d4063 100644 --- a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets +++ b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets @@ -432,6 +432,7 @@ Copyright (C) 2014 Xamarin. All rights reserved. Prefix="xammac" NoOverwrite="@(_BundleResourceWithLogicalName)" IntermediateOutputPath="$(IntermediateOutputPath)" + TargetFrameworkDirectory="$(TargetFrameworkDirectory)" ReferencedLibraries="@(ResolvedFiles)"> From 68c2df10165ee7572924000990bf787ab90254f7 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Tue, 10 Jan 2017 08:40:49 -0500 Subject: [PATCH 3/3] [msbuild] Use FullPath to detect assemblies inside the framework directories --- .../Tasks/UnpackLibraryResourcesTaskBase.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/UnpackLibraryResourcesTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/UnpackLibraryResourcesTaskBase.cs index 0d8ffa90bba3..87d3772eb617 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/UnpackLibraryResourcesTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/UnpackLibraryResourcesTaskBase.cs @@ -91,8 +91,9 @@ public override bool Execute () bool IsFrameworkAssembly (ITaskItem asm) { + var asm_path = asm.GetMetadata ("FullPath"); foreach (var dir in TargetFrameworkDirectory) { - if (asm.ItemSpec.StartsWith (dir.ItemSpec, StringComparison.Ordinal)) + if (asm_path.StartsWith (dir.GetMetadata ("FullPath"), StringComparison.OrdinalIgnoreCase)) return true; } return false;