Skip to content

Commit

Permalink
Mmp readonly fix (#82)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
chamons committed May 25, 2016
1 parent 0d184bb commit 47dc0f2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mk/xamarin.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ifdef ENABLE_XAMARIN
NEEDED_MACCORE_VERSION := 855d6e7f077b198bad6fecf236c9c58570116cfa
NEEDED_MACCORE_VERSION := eb56c7d348ae7495bfccc85af7abba8b73006413
NEEDED_MACCORE_BRANCH := master

MACCORE_DIRECTORY := maccore
Expand Down
29 changes: 23 additions & 6 deletions tools/mmp/driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,9 @@ static void CopyDependencies (IDictionary<string, List<MethodDefinition>> 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);
}
}
Expand All @@ -1249,7 +1251,9 @@ static void CopyDependencies (IDictionary<string, List<MethodDefinition>> 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 ();
}
}
Expand Down Expand Up @@ -1373,13 +1377,17 @@ static void ProcessNativeLibrary (HashSet<string> 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);
}

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions tools/mmp/error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tools/mtouch/error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47dc0f2

Please sign in to comment.