xamarin-macios/tools/mtouch/AssemblyResolver.cs

113 строки
2.8 KiB
C#
Исходник Обычный вид История

2016-04-21 15:58:45 +03:00
//
// AssemblyResolver.cs
//
// Authors:
// Jb Evain (jbevain@novell.com)
// Sebastien Pouliot <sebastien@xamarin.com>
//
// (C) 2010 Novell, Inc.
// Copyright 2012-2014 Xamarin Inc. All rights reserved.
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Mono.Cecil;
using Mono.Tuner;
using Xamarin.Bundler;
namespace MonoTouch.Tuner {
public partial class MonoTouchManifestResolver : MonoTouchResolver {
internal List<Exception> list = new List<Exception> ();
2016-04-21 15:58:45 +03:00
public override AssemblyDefinition Load (string file)
{
if (EnableRepl && Profile.IsSdkAssembly (Path.GetFileNameWithoutExtension (file))) {
var fn = Path.Combine (Path.GetDirectoryName (file), "repl", Path.GetFileName (file));
if (File.Exists (fn))
file = fn;
}
return base.Load (file);
}
}
// recent cecil removed some overloads - https://github.com/mono/cecil/commit/42db79cc16f1cbe8dbab558904e188352dba2b41
public static class AssemblyResolverRocks {
static ReaderParameters defaults = new ReaderParameters ();
public static AssemblyDefinition Resolve (this IAssemblyResolver self, string fullName)
{
if (fullName == null)
throw new ArgumentNullException (nameof (fullName));
return self.Resolve (AssemblyNameReference.Parse (fullName), defaults);
}
}
public class MonoTouchResolver : CoreResolver {
2016-04-21 15:58:45 +03:00
public bool EnableRepl { get; set; }
public IEnumerable<AssemblyDefinition> GetAssemblies ()
{
return cache.Values.Cast<AssemblyDefinition> ();
}
[mtouch] Implement support for sharing code between app extensions and container apps. Implement support for sharing both code and resources between app extensions and their container app: * AOT-compiled code. Each shared assembly is only AOT-compiled once, and if the assembly is built to a framework or dynamic library, it will also only be included once in the final app (as a framework or dynamic library in the container app, referenced directly by the app extension). If the assemblies are built to static objects there won't be any size improvements in the app, but the build will be much faster, because the assemblies will only be AOT- compiled once. * Any resources related to managed assemblies (debug files, config files, satellite assemblies) will be put in the container app only. Since these improvements are significant, code sharing will be enabled by default. Test results ============ For an extreme test project with 7 extensions (embedded-frameworks)[1]: with code sharing cycle 9 difference build time 1m 47s 3m 33s -1m 46s = ~50% faster app size 26 MB 131 MB -105 MB = ~80% smaller For a more normal test project (MyTabbedApplication)[2] - this is a simple application with 1 extension: with code sharing cycle 9 difference build time 0m 44s 0m 48s -4s = ~ 8% faster app size 23 MB 37 MB -15 MB = ~40% smaller Another tvOS app with one extension also show similar gains (MyTVApp)[3]: with code sharing cycle 9 difference build time 0m 22s 0m 48s -26s = ~54% faster app size 22 MB 62 MB -40 MB = ~65% smaller [1]: https://github.com/rolfbjarne/embedded-frameworks [2]: https://github.com/xamarin/xamarin-macios/tree/cycle9/msbuild/tests/MyTabbedApplication [3]: https://github.com/xamarin/xamarin-macios/tree/cycle9/msbuild/tests/MyTVApp
2017-01-24 13:10:20 +03:00
public void Add (AssemblyDefinition assembly)
{
cache [Path.GetFileNameWithoutExtension (assembly.MainModule.FileName)] = assembly;
2016-04-21 15:58:45 +03:00
}
public override AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters)
2016-04-21 15:58:45 +03:00
{
var aname = name.Name;
AssemblyDefinition assembly;
if (cache.TryGetValue (aname, out assembly))
return assembly;
if (EnableRepl && FrameworkDirectory != null) {
2016-04-21 15:58:45 +03:00
var replDir = Path.Combine (FrameworkDirectory, "repl");
if (Directory.Exists (replDir)) {
assembly = SearchDirectory (aname, replDir);
if (assembly != null)
return assembly;
}
}
if (FrameworkDirectory != null) {
var facadeDir = Path.Combine (FrameworkDirectory, "Facades");
2016-04-21 15:58:45 +03:00
assembly = SearchDirectory (aname, facadeDir);
if (assembly != null)
return assembly;
}
if (ArchDirectory != null) {
assembly = SearchDirectory (aname, ArchDirectory);
if (assembly != null)
return assembly;
}
assembly = SearchDirectory (aname, FrameworkDirectory);
if (assembly != null)
return assembly;
assembly = SearchDirectory (aname, RootDirectory);
if (assembly != null)
return assembly;
assembly = SearchDirectory (aname, RootDirectory, ".exe");
if (assembly != null)
return assembly;
2016-04-21 15:58:45 +03:00
return null;
}
}
}