[tests][intro] Add test for simlauncher [weak] frameworks. Fixes #6951 (#6957)

We ship a default, pre-built, simlauncher for iOS simulator applications.
This speeds up compilation for the default (non linked) simulator builds
quite a lot (no call to `clang` is needed). However it force us to keep
track of frameworks manually - `mtouch` can track them but requires
calling clang/ld to finish things up (killing the optimization).

It's easy to forget some (new) frameworks since they can be loaded
dynamically (on demand) _most_ of the time. Sadly there are a few cases
where doing so cause (hard to diagnose) problems - so we can't depend
on them being loaded, correctly for us.

The new test case loads the `otool -L` output (make when we build
simlauncher[32|64]-sgen) and compares it with mtouch's GetFramework
logic *and* with our namespaces (which is pretty close, with a few
exceptions, to the framework names). This will make it harder to
forget [weak] frameworks when adding new bindings :)

Fixes https://github.com/xamarin/xamarin-macios/issues/6951
This commit is contained in:
Sebastien Pouliot 2019-09-10 09:02:27 -04:00 коммит произвёл GitHub
Родитель 6488fcb8f9
Коммит 62018fdab4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 68 добавлений и 4 удалений

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

@ -1,6 +1,7 @@
#if __UNIFIED__
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using NUnit.Framework;
@ -137,6 +138,67 @@ namespace Introspection {
}
AssertIfErrors ($"{Errors} unknown frameworks found:\n{ErrorData}");
}
#if __IOS__
[Test]
public void Simlauncher ()
{
if (Runtime.Arch != Arch.SIMULATOR)
Assert.Ignore ("Only needed on simulator");
var all = GetFrameworks ();
var namespaces = new HashSet<string> (StringComparer.OrdinalIgnoreCase);
foreach (Type t in Assembly.GetTypes ()) {
if (!t.IsPublic)
continue;
namespaces.Add (t.Namespace);
}
foreach (var line in File.ReadAllLines ("simlauncher64-sgen.frameworks")) {
var c = line.IndexOf (" (compatibility");
if (c < 0)
continue;
var path = line.Substring (1, c - 1);
if (!path.StartsWith ("/System/Library/Frameworks/", StringComparison.Ordinal))
continue;
var fx = Path.GetFileNameWithoutExtension (path);
// match with mtouch framework list
if (!all.TryGetValue (fx, out var framework)) {
// special cases
switch (fx) {
case "CoreAudio": // AudioToolbox, AVFoundation...
case "CoreFoundation": // implied (always linked)
case "CFNetwork": // implied (StartWWAN) and included (mostly) in CoreServices
case "OpenAL": // part of OpenTK
break;
case "CoreMIDI":
// CoreMidi (case) in the fx list
break;
default:
ReportError ($"{fx} is not part of mtouch's GetFrameworks");
break;
}
}
// match with Xamarin.iOS.dll namespaces
if (!namespaces.Contains (fx)) {
// special cases
switch (fx) {
case "CoreAudio": // AudioToolbox, AVFoundation...
case "CFNetwork": // implied (StartWWAN) and included (mostly) in CoreServices
case "OpenAL": // part of OpenTK
break;
default:
ReportError ($"{fx} is not part of mtouch's GetFrameworks");
break;
}
}
}
}
#endif
}
}
#endif

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

@ -248,6 +248,9 @@
<BundleResource Include="..\xamarin1.png">
<Link>xamarin1.png</Link>
</BundleResource>
<BundleResource Include="..\..\..\tools\mtouch\simlauncher64-sgen.frameworks">
<Link>simlauncher64-sgen.frameworks</Link>
</BundleResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project>

2
tools/mtouch/.gitignore поставляемый
Просмотреть файл

@ -9,4 +9,4 @@ simlauncher32-sgen
simlauncher64-sgen
*.stamp
mtouch.csproj.inc
*.frameworks

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

@ -60,7 +60,6 @@ SIMLAUNCHER_FRAMEWORKS = \
-framework CoreText \
-framework ExternalAccessory \
-framework GameKit \
-framework IOKit \
-framework MapKit \
-framework MediaPlayer \
-framework MessageUI \
@ -184,7 +183,7 @@ simlauncher$(5)$(1): simlauncher.m $(TOP)/runtime/.libs/ios/libxamarin.a $(BUILD
$(TOP)/runtime/.libs/ios/libapp.a \
-Wl,-w \
-lz -liconv $(TOP)/runtime/.libs/ios/libxamarin-debug.a simlauncher.m $(SIMLAUNCHER_FRAMEWORKS) $(SIMULATOR$(4)_OBJC_CFLAGS) -o $$@
$(Q) xcrun otool -L simlauncher$(5)$(1) > simlauncher$(5)$(1).frameworks
endef
$(eval $(call SimlauncherTemplate,-sgen,$(BUILD_DESTDIR)/simulator86/lib/libmono-profiler-log.a -u _mono_profiler_init_log -DXAMCORE_2_0 Xamarin.iOS.registrar.ios.a,sgen,86,32))