From 1c97aba9731e73a0759818fb937b0cd9f0ce26ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Tue, 5 Feb 2019 11:37:02 +0100 Subject: [PATCH] Fix mono native copying when no linkcontext is available When we're using cached linker output we can't access LinkContext. Instead we need to cache the required values ourselves. --- tools/mtouch/Application.cs | 4 +-- tools/mtouch/Target.cs | 65 +++++++++++++++++++++++++++++++++++-- tools/mtouch/mtouch.in | 2 +- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/tools/mtouch/Application.cs b/tools/mtouch/Application.cs index 6f56882ecb..3337dfca5a 100644 --- a/tools/mtouch/Application.cs +++ b/tools/mtouch/Application.cs @@ -1631,7 +1631,7 @@ namespace Xamarin.Bundler { // Collect files to bundle from every target if (Targets.Count == 1) { bundle_files = Targets [0].BundleFiles; - require_mono_native = Targets[0].LinkContext?.RequireMonoNative ?? true; + require_mono_native = Targets[0].MonoNative.RequireMonoNative; } else { foreach (var target in Targets) { foreach (var kvp in target.BundleFiles) { @@ -1640,7 +1640,7 @@ namespace Xamarin.Bundler { bundle_files [kvp.Key] = info = new BundleFileInfo () { DylibToFramework = kvp.Value.DylibToFramework }; info.Sources.UnionWith (kvp.Value.Sources); } - require_mono_native |= target.LinkContext?.RequireMonoNative ?? true; + require_mono_native |= target.MonoNative.RequireMonoNative; } } diff --git a/tools/mtouch/Target.cs b/tools/mtouch/Target.cs index 159bfbc532..2ac64a0f1a 100644 --- a/tools/mtouch/Target.cs +++ b/tools/mtouch/Target.cs @@ -1550,11 +1550,72 @@ namespace Xamarin.Bundler build_tasks.Add (link_task); } + public class MonoNativeInfo + { + public bool RequireMonoNative { get; set; } + public bool RequireGss { get; set; } + + public void Load (string filename) + { + using (var reader = new StreamReader (filename)) { + string line; + while ((line = reader.ReadLine ()) != null) { + if (line.Length == 0) + continue; + var eq = line.IndexOf ('='); + var typestr = line.Substring (0, eq); + var valstr = line.Substring (eq + 1); + bool value = Convert.ToBoolean (valstr); + switch (typestr) { + case "RequireMonoNative": + RequireMonoNative = value; + break; + case "RequireGss": + RequireGss = value; + break; + default: + throw ErrorHelper.CreateError (99, $"Internal error: invalid type string while loading cached Mono.Native info: {typestr}. Please file a bug report with a test case (https://github.com/xamarin/xamarin-macios/issues/new)."); + } + } + } + } + + public void Save (string filename) + { + using (var writer = new StreamWriter (filename)) { + writer.WriteLine ("RequireMonoNative={0}", RequireMonoNative); + writer.WriteLine ("RequireGss={0}", RequireGss); + } + } + } + + MonoNativeInfo mono_native_info; + + public MonoNativeInfo MonoNative + { + get { + if (mono_native_info != null) + return mono_native_info; + + mono_native_info = new MonoNativeInfo (); + var cache_location = Path.Combine (App.Cache.Location, "mono-native-info.txt"); + if (cached_link) { + mono_native_info.Load (cache_location); + } else { + mono_native_info.RequireMonoNative = LinkContext?.RequireMonoNative ?? true; + mono_native_info.RequireGss = LinkContext?.RequireGss ?? true; + mono_native_info.Save (cache_location); + } + + return mono_native_info; + } + } + void HandleMonoNative (Application app, CompilerFlags compiler_flags) { if (app.MonoNativeMode == MonoNativeMode.None) return; - if (LinkContext != null && !LinkContext.RequireMonoNative) + if (!MonoNative.RequireMonoNative) return; var libnative = app.GetLibNativeName (); var libdir = Driver.GetMonoTouchLibDirectory (app); @@ -1569,7 +1630,7 @@ namespace Xamarin.Bundler compiler_flags.AddLinkWith (libnative); switch (app.Platform) { case ApplePlatform.iOS: - if (LinkContext?.RequireGss ?? false) { + if (MonoNative.RequireGss) { Driver.Log (3, "Adding GSS framework reference."); compiler_flags.AddFramework ("GSS"); } diff --git a/tools/mtouch/mtouch.in b/tools/mtouch/mtouch.in index 29e5827562..fb7b1ba034 100644 --- a/tools/mtouch/mtouch.in +++ b/tools/mtouch/mtouch.in @@ -1,3 +1,3 @@ #!/bin/sh -exec /Library/Frameworks/Mono.framework/Commands/mono64 --debug @MONOTOUCH_PREFIX@/lib/mtouch/mtouch.exe "$@" +exec /Library/Frameworks/Mono.framework/Commands/mono64 --debug --debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:55555 @MONOTOUCH_PREFIX@/lib/mtouch/mtouch.exe "$@"