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> ();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-12 09:24:47 +03:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 01:39:38 +03:00
|
|
|
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> ();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-13 01:39:38 +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;
|
|
|
|
|
2020-05-07 09:37:17 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 09:37:17 +03:00
|
|
|
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;
|
|
|
|
|
2016-11-01 05:30:32 +03:00
|
|
|
assembly = SearchDirectory (aname, RootDirectory, ".exe");
|
|
|
|
if (assembly != null)
|
|
|
|
return assembly;
|
|
|
|
|
2016-04-21 15:58:45 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|