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.
This commit is contained in:
Alexander Köplinger 2019-02-05 11:37:02 +01:00
Родитель c4052955a8
Коммит 1c97aba973
3 изменённых файлов: 66 добавлений и 5 удалений

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -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");
}

Просмотреть файл

@ -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 "$@"