From d537db2cce4f2bdbb150990322d2aa7482263223 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Wed, 21 Sep 2016 16:31:13 +0200 Subject: [PATCH] write the stripped assemblies to new file and then move it - it looks like with newer mono (or cecil?) we cannot write to the opened stream for reading, otherwise we will get sharing violation exception - this should fix part of #44529, other Tasks might need similar change --- .../Tasks/StripEmbeddedLibraries.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/StripEmbeddedLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/StripEmbeddedLibraries.cs index a79f8328af7..95054b2889b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/StripEmbeddedLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/StripEmbeddedLibraries.cs @@ -32,6 +32,7 @@ public override bool Execute () foreach (var assembly in Assemblies) res.Load (Path.GetFullPath (assembly.ItemSpec)); + var strippedAssemblies = new Dictionary (); foreach (var assemblyName in Assemblies) { var suffix = assemblyName.ItemSpec.EndsWith (".dll") ? String.Empty : ".dll"; string hintPath = assemblyName.GetMetadata ("HintPath").Replace (Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); @@ -68,7 +69,8 @@ public override bool Execute () } } if (assembly_modified) { - Log.LogDebugMessage (" The stripped library is saved as {0}", assemblyPath); + var strippedPath = assemblyPath + ".stripped"; + Log.LogDebugMessage (" The stripped library is saved as {0}", strippedPath); // Output assembly needs to regenerate symbol file even if no IL/metadata was touched // because Cecil still rewrites all assembly types in Cecil order (type A, nested types of A, type B, etc) @@ -77,9 +79,19 @@ public override bool Execute () WriteSymbols = assembly.MainModule.HasSymbols }; - assembly.Write (assemblyPath, wp); + assembly.Write (strippedPath, wp); + strippedAssemblies [assemblyPath] = strippedPath; } } + + res.Dispose (); + + foreach (var pair in strippedAssemblies) { + File.Delete (pair.Key); + File.Move (pair.Value, pair.Key); + Log.LogDebugMessage (" The stripped library {0} is moved back to {1}", pair.Value, pair.Key); + } + return true; } }