From 47dc0f26c9e7398151a62850f028662351fc3623 Mon Sep 17 00:00:00 2001 From: Chris Hamons Date: Wed, 25 May 2016 16:29:33 -0400 Subject: [PATCH] Mmp readonly fix (#82) * [XM] Teach XM's mmp tool to handle read only assemblies/native libs - https://bugzilla.xamarin.com/show_bug.cgi?id=41037 - mmp should also promote any install_name_tool errors to "real" errors * Bump maccore --- mk/xamarin.mk | 2 +- tools/mmp/driver.cs | 29 +++++++++++++++++++++++------ tools/mmp/error.cs | 1 + tools/mtouch/error.cs | 1 + 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/mk/xamarin.mk b/mk/xamarin.mk index 07a022b0029c..1824ae881288 100644 --- a/mk/xamarin.mk +++ b/mk/xamarin.mk @@ -1,5 +1,5 @@ ifdef ENABLE_XAMARIN -NEEDED_MACCORE_VERSION := 855d6e7f077b198bad6fecf236c9c58570116cfa +NEEDED_MACCORE_VERSION := eb56c7d348ae7495bfccc85af7abba8b73006413 NEEDED_MACCORE_BRANCH := master MACCORE_DIRECTORY := maccore diff --git a/tools/mmp/driver.cs b/tools/mmp/driver.cs index 306393d03116..a916884bed35 100644 --- a/tools/mmp/driver.cs +++ b/tools/mmp/driver.cs @@ -1222,7 +1222,9 @@ static void CopyDependencies (IDictionary> librar string libName = Path.GetFileName (linkWith); string finalLibPath = Path.Combine (mmp_dir, libName); Application.UpdateFile (linkWith, finalLibPath); - XcodeRun ("install_name_tool -id", string.Format ("{0} {1}", Quote("@executable_path/../" + BundleName + "/" + libName), finalLibPath)); + int ret = XcodeRun ("install_name_tool -id", string.Format ("{0} {1}", Quote("@executable_path/../" + BundleName + "/" + libName), finalLibPath)); + if (ret != 0) + throw new MonoMacException (5310, true, "install_name_tool failed with an error code '{0}'. Check build log for details.", ret); native_libraries_copied_in.Add (libName); } } @@ -1249,7 +1251,9 @@ static void CopyDependencies (IDictionary> librar // if required update the paths inside the .dylib that was copied if (sb.Length > 0) { sb.Append (' ').Append (Quote (library)); - XcodeRun ("install_name_tool", sb.ToString ()); + int ret = XcodeRun ("install_name_tool", sb.ToString ()); + if (ret != 0) + throw new MonoMacException (5310, true, "install_name_tool failed with an error code '{0}'. Check build log for details.", ret); sb.Clear (); } } @@ -1373,13 +1377,17 @@ static void ProcessNativeLibrary (HashSet processed, string library, Lis Console.WriteLine ("Dependency {0} was already at destination, skipping.", Path.GetFileName (real_src)); } else { - File.Copy (real_src, dest, true); + // install_name_tool gets angry if you copy in a read only native library + CopyFileAndRemoveReadOnly (real_src, dest); } bool isStaticLib = real_src.EndsWith (".a"); if (native_references.Contains (real_src)) { - if (!isStaticLib) - XcodeRun ("install_name_tool -id", string.Format ("{0} {1}", Quote("@executable_path/../" + BundleName + "/" + name), dest)); + if (!isStaticLib) { + int ret = XcodeRun ("install_name_tool -id", string.Format ("{0} {1}", Quote("@executable_path/../" + BundleName + "/" + name), dest)); + if (ret != 0) + throw new MonoMacException (5310, true, "install_name_tool failed with an error code '{0}'. Check build log for details.", ret); + } native_libraries_copied_in.Add (name); } @@ -1483,13 +1491,22 @@ static void CopyI18nAssemblies (I18nAssemblies i18n) resolved_assemblies.Add (Path.Combine (fx_dir, "I18N.West.dll")); } + static void CopyFileAndRemoveReadOnly (string src, string dest) { + File.Copy (src, dest, true); + + FileAttributes attrs = File.GetAttributes (dest); + if ((attrs & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) + File.SetAttributes (dest, attrs & ~FileAttributes.ReadOnly); + } + static void CopyAssemblies () { foreach (string asm in resolved_assemblies) { var mdbfile = string.Format ("{0}.mdb", asm); var configfile = string.Format ("{0}.config", asm); string filename = Path.GetFileName (asm); - File.Copy (asm, Path.Combine (mmp_dir, filename), true); + // The linker later gets angry if you copy in a read only assembly + CopyFileAndRemoveReadOnly (asm, Path.Combine (mmp_dir, filename)); if (verbose > 0) Console.WriteLine ("Added assembly {0}", asm); diff --git a/tools/mmp/error.cs b/tools/mmp/error.cs index 6211489ba6d5..cbc85b672537 100644 --- a/tools/mmp/error.cs +++ b/tools/mmp/error.cs @@ -96,6 +96,7 @@ namespace Xamarin.Bundler { // MM5306 Missing dependencies. Please install Xcode 'Command-Line Tools' component // MM5308 Xcode license agreement may not have been accepted. Please launch Xcode. // MM5309 Native linking failed with error code 1. Check build log for details. + // MT5310 install_name_tool failed with an error code '{0}'. Check build log for details. // MM6xxx mmp internal tools // MM7xxx reserved // MM8xxx runtime diff --git a/tools/mtouch/error.cs b/tools/mtouch/error.cs index 756f22f21794..343d97207163 100644 --- a/tools/mtouch/error.cs +++ b/tools/mtouch/error.cs @@ -305,6 +305,7 @@ namespace Xamarin.Bundler { // MT5307 Failed to sign the executable. Please review the build log. // MT5308 ** reserved Xamarin.Mac ** // MT5309 ** reserved Xamarin.Mac ** + // MT5310 ** reserved Xamarin.Mac ** // MT6xxx mtouch internal tools // MT600x Stripper // MT6001 Running version of Cecil doesn't support assembly stripping