Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -153,6 +153,10 @@
<type fullname="System.Collections.Generic.ICollection`1" />
<type fullname="System.Collections.Generic.IEnumerable`1" />
<type fullname="System.Collections.Generic.IEnumerator`1" />
<type fullname="System.Collections.Generic.IReadOnlyList`1" />
<type fullname="System.Collections.Generic.IReadOnlyCollection`1" />
<type fullname="System.Collections.Generic.IList`1" />
<type fullname="System.Collections.Generic.GenericEqualityComparer`1">
<method name=".ctor" />
@@ -219,8 +223,6 @@
<type fullname="System.Reflection.MonoEventInfo" preserve="fields" />
<type fullname="System.Reflection.MonoField" preserve="fields" />
<type fullname="System.Reflection.MonoGenericClass" preserve="fields" />
<type fullname="System.Reflection.MonoGenericMethod" preserve="fields" />
<type fullname="System.Reflection.MonoGenericCMethod" preserve="fields" />
<type fullname="System.Reflection.MonoMethod" preserve="fields" />
<type fullname="System.Reflection.MonoMethodInfo" preserve="fields" />
<type fullname="System.Reflection.MonoPropertyInfo" preserve="fields" />
@@ -262,6 +264,7 @@
<type fullname="System.Reflection.Emit.MethodBuilder" preserve="fields" />
<type fullname="System.Reflection.Emit.ModuleBuilder" preserve="fields">
<method name="Mono_GetGuid" />
<method name="RuntimeResolve" />
</type>
<type fullname="System.Reflection.Emit.MonoResource" preserve="fields" />
<type fullname="System.Reflection.Emit.MonoWin32Resource" preserve="fields" />

View File

@@ -1,77 +0,0 @@
//
// BaseStep.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using Mono.Cecil;
namespace Mono.Linker.Steps {
public abstract class BaseStep : IStep {
private LinkContext _context;
public LinkContext Context {
get { return _context; }
}
public AnnotationStore Annotations {
get { return _context.Annotations; }
}
public void Process (LinkContext context)
{
_context = context;
if (!ConditionToProcess ())
return;
Process ();
foreach (AssemblyDefinition assembly in context.GetAssemblies ())
ProcessAssembly (assembly);
EndProcess ();
}
protected virtual bool ConditionToProcess ()
{
return true;
}
protected virtual void Process ()
{
}
protected virtual void EndProcess ()
{
}
protected virtual void ProcessAssembly (AssemblyDefinition assembly)
{
}
}
}

View File

@@ -1,132 +0,0 @@
//
// Blacklist.cs
//
// Author:
// Jb Evain (jb@nurv.fr)
//
// (C) 2007 Novell Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Linq;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.XPath;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class BlacklistStep : BaseStep {
protected override bool ConditionToProcess()
{
return Context.CoreAction == AssemblyAction.Link;
}
protected override void Process ()
{
foreach (string name in Assembly.GetExecutingAssembly ().GetManifestResourceNames ()) {
if (!name.EndsWith (".xml", StringComparison.OrdinalIgnoreCase) || !IsReferenced (GetAssemblyName (name)))
continue;
try {
if (Context.LogInternalExceptions)
Console.WriteLine ("Processing resource linker descriptor: {0}", name);
Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetResolveStep (name));
} catch (XmlException ex) {
/* This could happen if some broken XML file is included. */
if (Context.LogInternalExceptions)
Console.WriteLine ("Error processing {0}: {1}", name, ex);
}
}
foreach (var asm in Context.GetAssemblies ()) {
foreach (var rsc in asm.Modules
.SelectMany (mod => mod.Resources)
.Where (res => res.ResourceType == ResourceType.Embedded)
.Where (res => res.Name.EndsWith (".xml", StringComparison.OrdinalIgnoreCase))
.Where (res => IsReferenced (GetAssemblyName (res.Name)))
.Cast<EmbeddedResource> ()) {
try {
if (Context.LogInternalExceptions)
Console.WriteLine ("Processing embedded resource linker descriptor: {0}", rsc.Name);
Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetExternalResolveStep (rsc, asm));
} catch (XmlException ex) {
/* This could happen if some broken XML file is embedded. */
if (Context.LogInternalExceptions)
Console.WriteLine ("Error processing {0}: {1}", rsc.Name, ex);
}
}
}
}
static string GetAssemblyName (string descriptor)
{
int pos = descriptor.LastIndexOf ('.');
if (pos == -1)
return descriptor;
return descriptor.Substring (0, pos);
}
bool IsReferenced (string name)
{
foreach (AssemblyDefinition assembly in Context.GetAssemblies ())
if (assembly.Name.Name == name)
return true;
return false;
}
static ResolveFromXmlStep GetExternalResolveStep (EmbeddedResource resource, AssemblyDefinition assembly)
{
return new ResolveFromXmlStep (GetExternalDescriptor (resource), "resource " + resource.Name + " in " + assembly.FullName);
}
static ResolveFromXmlStep GetResolveStep (string descriptor)
{
return new ResolveFromXmlStep (GetDescriptor (descriptor), "descriptor " + descriptor + " from " + Assembly.GetExecutingAssembly ().FullName);
}
static XPathDocument GetExternalDescriptor (EmbeddedResource resource)
{
using (var sr = new StreamReader (resource.GetResourceStream ())) {
return new XPathDocument (new StringReader (sr.ReadToEnd ()));
}
}
static XPathDocument GetDescriptor (string descriptor)
{
using (StreamReader sr = new StreamReader (GetResource (descriptor))) {
return new XPathDocument (new StringReader (sr.ReadToEnd ()));
}
}
static Stream GetResource (string descriptor)
{
return Assembly.GetExecutingAssembly ().GetManifestResourceStream (descriptor);
}
}
}

View File

@@ -1,108 +0,0 @@
//
// CleanStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class CleanStep : BaseStep {
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) == AssemblyAction.Link)
CleanAssembly (assembly);
}
static void CleanAssembly (AssemblyDefinition asm)
{
foreach (TypeDefinition type in asm.MainModule.Types)
CleanType (type);
}
static void CleanType (TypeDefinition type)
{
if (type.HasProperties)
CleanProperties (type);
if (type.HasEvents)
CleanEvents (type);
if (type.HasNestedTypes)
foreach (var nested in type.NestedTypes)
CleanType (nested);
}
static MethodDefinition CheckMethod (TypeDefinition type, MethodDefinition method)
{
if (method == null)
return null;
return type.Methods.Contains (method) ? method : null;
}
static void CleanEvents (TypeDefinition type)
{
var events = type.Events;
for (int i = 0; i < events.Count; i++) {
var evt = events [i];
evt.AddMethod = CheckMethod (type, evt.AddMethod);
evt.InvokeMethod = CheckMethod (type, evt.InvokeMethod);
evt.RemoveMethod = CheckMethod (type, evt.RemoveMethod);
if (!IsEventUsed (evt))
events.RemoveAt (i--);
}
}
static bool IsEventUsed (EventDefinition evt)
{
return evt.AddMethod != null || evt.InvokeMethod != null || evt.RemoveMethod != null;
}
static void CleanProperties (TypeDefinition type)
{
var properties = type.Properties;
for (int i = 0; i < properties.Count; i++) {
var prop = properties [i];
prop.GetMethod = CheckMethod (type, prop.GetMethod);
prop.SetMethod = CheckMethod (type, prop.SetMethod);
if (!IsPropertyUsed (prop))
properties.RemoveAt (i--);
}
}
static bool IsPropertyUsed (PropertyDefinition prop)
{
return prop.GetMethod != null || prop.SetMethod != null;
}
}
}

View File

@@ -1,34 +0,0 @@
//
// IStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Linker.Steps {
public interface IStep {
void Process (LinkContext context);
}
}

View File

@@ -1,102 +0,0 @@
//
// LoadI18nAssemblies.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class LoadI18nAssemblies : BaseStep {
static readonly byte [] _pktoken = new byte [] {0x07, 0x38, 0xeb, 0x9f, 0x13, 0x2e, 0xd7, 0x56};
I18nAssemblies _assemblies;
public LoadI18nAssemblies (I18nAssemblies assemblies)
{
_assemblies = assemblies;
}
protected override bool ConditionToProcess ()
{
return _assemblies != I18nAssemblies.None &&
Type.GetType ("System.MonoType") != null;
}
protected override void Process()
{
LoadAssembly (GetAssemblyName (I18nAssemblies.Base));
LoadI18nAssembly (I18nAssemblies.CJK);
LoadI18nAssembly (I18nAssemblies.MidEast);
LoadI18nAssembly (I18nAssemblies.Other);
LoadI18nAssembly (I18nAssemblies.Rare);
LoadI18nAssembly (I18nAssemblies.West);
}
bool ShouldCopyAssembly (I18nAssemblies current)
{
return (current & _assemblies) != 0;
}
void LoadI18nAssembly (I18nAssemblies asm)
{
if (!ShouldCopyAssembly (asm))
return;
AssemblyNameReference name = GetAssemblyName (asm);
LoadAssembly (name);
}
void LoadAssembly (AssemblyNameReference name)
{
AssemblyDefinition assembly = Context.Resolve (name);
ResolveFromAssemblyStep.ProcessLibrary (Context, assembly);
}
AssemblyNameReference GetAssemblyName (I18nAssemblies assembly)
{
AssemblyNameReference name = new AssemblyNameReference ("I18N", GetCorlibVersion ());
if (assembly != I18nAssemblies.Base)
name.Name += "." + assembly;
name.PublicKeyToken = _pktoken;
return name;
}
Version GetCorlibVersion ()
{
foreach (AssemblyDefinition assembly in Context.GetAssemblies ())
if (assembly.Name.Name == "mscorlib")
return assembly.Name.Version;
return new Version ();
}
}
}

View File

@@ -1,55 +0,0 @@
//
// LoadReferencesStep.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class LoadReferencesStep : BaseStep {
IDictionary _references = new Hashtable ();
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
ProcessReferences (assembly);
}
void ProcessReferences (AssemblyDefinition assembly)
{
if (_references.Contains (assembly.Name))
return;
_references.Add (assembly.Name, assembly);
foreach (AssemblyNameReference reference in assembly.MainModule.AssemblyReferences)
ProcessReferences (Context.Resolve (reference));
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,159 +0,0 @@
//
// OutputStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace Mono.Linker.Steps {
public class OutputStep : BaseStep {
protected override void Process ()
{
CheckOutputDirectory ();
Annotations.SaveDependencies ();
}
void CheckOutputDirectory ()
{
if (Directory.Exists (Context.OutputDirectory))
return;
Directory.CreateDirectory (Context.OutputDirectory);
}
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
OutputAssembly (assembly);
}
void OutputAssembly (AssemblyDefinition assembly)
{
string directory = Context.OutputDirectory;
CopyConfigFileIfNeeded (assembly, directory);
switch (Annotations.GetAction (assembly)) {
case AssemblyAction.Save:
case AssemblyAction.Link:
Context.Annotations.AddDependency (assembly);
assembly.Write (GetAssemblyFileName (assembly, directory), SaveSymbols (assembly));
break;
case AssemblyAction.Copy:
Context.Annotations.AddDependency (assembly);
CloseSymbols (assembly);
CopyAssembly (GetOriginalAssemblyFileInfo (assembly), directory, Context.LinkSymbols);
break;
case AssemblyAction.Delete:
CloseSymbols (assembly);
var target = GetAssemblyFileName (assembly, directory);
if (File.Exists (target)) {
File.Delete (target);
File.Delete (target + ".mdb");
File.Delete (GetConfigFile (target));
}
break;
default:
CloseSymbols (assembly);
break;
}
}
void CloseSymbols (AssemblyDefinition assembly)
{
Annotations.CloseSymbolReader (assembly);
}
WriterParameters SaveSymbols (AssemblyDefinition assembly)
{
var parameters = new WriterParameters ();
if (!Context.LinkSymbols)
return parameters;
if (!assembly.MainModule.HasSymbols)
return parameters;
if (Context.SymbolWriterProvider != null)
parameters.SymbolWriterProvider = Context.SymbolWriterProvider;
else
parameters.WriteSymbols = true;
return parameters;
}
static void CopyConfigFileIfNeeded (AssemblyDefinition assembly, string directory)
{
string config = GetConfigFile (GetOriginalAssemblyFileInfo (assembly).FullName);
if (!File.Exists (config))
return;
string target = Path.GetFullPath (GetConfigFile (GetAssemblyFileName (assembly, directory)));
if (config == target)
return;
File.Copy (config, GetConfigFile (GetAssemblyFileName (assembly, directory)), true);
}
static string GetConfigFile (string assembly)
{
return assembly + ".config";
}
static FileInfo GetOriginalAssemblyFileInfo (AssemblyDefinition assembly)
{
return new FileInfo (assembly.MainModule.FileName);
}
static void CopyAssembly (FileInfo fi, string directory, bool symbols)
{
string target = Path.GetFullPath (Path.Combine (directory, fi.Name));
string source = fi.FullName;
if (source == target)
return;
File.Copy (source, target, true);
if (!symbols)
return;
source += ".mdb";
if (!File.Exists (source))
return;
File.Copy (source, target + ".mdb", true);
}
static string GetAssemblyFileName (AssemblyDefinition assembly, string directory)
{
string file = assembly.Name.Name + (assembly.MainModule.Kind == ModuleKind.Dll ? ".dll" : ".exe");
return Path.Combine (directory, file);
}
}
}

View File

@@ -1,48 +0,0 @@
//
// CleanStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class RegenerateGuidStep : BaseStep {
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) == AssemblyAction.Link)
RegenerateGuid (assembly);
}
static void RegenerateGuid (AssemblyDefinition asm)
{
asm.MainModule.Mvid = Guid.NewGuid ();
}
}
}

View File

@@ -1,137 +0,0 @@
//
// ResolveFromAssemblyStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class ResolveFromAssemblyStep : ResolveStep {
AssemblyDefinition _assembly;
string _file;
public ResolveFromAssemblyStep (string assembly)
{
_file = assembly;
}
public ResolveFromAssemblyStep (AssemblyDefinition assembly)
{
_assembly = assembly;
}
protected override void Process ()
{
if (_assembly != null)
Context.Resolver.CacheAssembly (_assembly);
AssemblyDefinition assembly = _assembly ?? Context.Resolve (_file);
switch (assembly.MainModule.Kind) {
case ModuleKind.Dll:
ProcessLibrary (Context, assembly);
break;
default:
ProcessExecutable (assembly);
break;
}
}
static void SetAction (LinkContext context, AssemblyDefinition assembly, AssemblyAction action)
{
TryReadSymbols (context, assembly);
context.Annotations.SetAction (assembly, action);
}
static void TryReadSymbols (LinkContext context, AssemblyDefinition assembly)
{
context.SafeReadSymbols (assembly);
}
public static void ProcessLibrary (LinkContext context, AssemblyDefinition assembly)
{
SetAction (context, assembly, AssemblyAction.Copy);
context.Annotations.Push (assembly);
foreach (TypeDefinition type in assembly.MainModule.Types)
MarkType (context, type);
context.Annotations.Pop ();
}
static void MarkType (LinkContext context, TypeDefinition type)
{
context.Annotations.Mark (type);
context.Annotations.Push (type);
if (type.HasFields)
MarkFields (context, type.Fields);
if (type.HasMethods)
MarkMethods (context, type.Methods);
if (type.HasNestedTypes)
foreach (var nested in type.NestedTypes)
MarkType (context, nested);
context.Annotations.Pop ();
}
void ProcessExecutable (AssemblyDefinition assembly)
{
SetAction (Context, assembly, AssemblyAction.Link);
Annotations.Push (assembly);
Annotations.Mark (assembly.EntryPoint.DeclaringType);
MarkMethod (Context, assembly.EntryPoint, MethodAction.Parse);
Annotations.Pop ();
}
static void MarkFields (LinkContext context, ICollection fields)
{
foreach (FieldDefinition field in fields)
context.Annotations.Mark (field);
}
static void MarkMethods (LinkContext context, ICollection methods)
{
foreach (MethodDefinition method in methods)
MarkMethod (context, method, MethodAction.ForceParse);
}
static void MarkMethod (LinkContext context, MethodDefinition method, MethodAction action)
{
context.Annotations.Mark (method);
context.Annotations.SetAction (method, action);
}
}
}

View File

@@ -1,139 +0,0 @@
//
// ResolveFromXApiStep.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Xml.XPath;
using Mono.Linker;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class ResolveFromXApiStep : ResolveStep, IXApiVisitor {
static readonly string _name = "name";
static readonly string _ns = string.Empty;
XPathDocument _document;
public ResolveFromXApiStep (XPathDocument document)
{
_document = document;
}
protected override void Process ()
{
XApiReader reader = new XApiReader (_document, this);
reader.Process (Context);
}
public void OnAssembly (XPathNavigator nav, AssemblyDefinition assembly)
{
}
public void OnAttribute (XPathNavigator nav)
{
string name = GetName (nav);
TypeDefinition type = Context.GetType (name);
if (type != null)
MarkType (type);
}
public void OnClass (XPathNavigator nav, TypeDefinition type)
{
MarkType (type);
}
public void OnInterface (XPathNavigator nav, TypeDefinition type)
{
MarkType (type);
}
public void OnField (XPathNavigator nav, FieldDefinition field)
{
MarkField (field);
}
public void OnMethod (XPathNavigator nav, MethodDefinition method)
{
MarkMethod (method);
}
public void OnConstructor (XPathNavigator nav, MethodDefinition method)
{
MarkMethod (method);
}
public void OnProperty (XPathNavigator nav, PropertyDefinition property)
{
}
public void OnEvent (XPathNavigator nav, EventDefinition evt)
{
if (evt.AddMethod != null)
MarkMethod (evt.AddMethod);
if (evt.InvokeMethod != null)
MarkMethod (evt.InvokeMethod);
if (evt.RemoveMethod != null)
MarkMethod (evt.RemoveMethod);
}
static string GetName (XPathNavigator nav)
{
return GetAttribute (nav, _name);
}
static string GetAttribute (XPathNavigator nav, string attribute)
{
return nav.GetAttribute (attribute, _ns);
}
void MarkType (TypeDefinition type)
{
InternalMark (type);
}
void MarkField (FieldDefinition field)
{
InternalMark (field);
}
void InternalMark (IMetadataTokenProvider provider)
{
Annotations.Mark (provider);
Annotations.SetPublic (provider);
}
void MarkMethod (MethodDefinition method)
{
InternalMark (method);
Annotations.SetAction (method, MethodAction.Parse);
}
}
}

View File

@@ -1,403 +0,0 @@
//
// ResolveFromXmlStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
// (C) 2007 Novell, Inc.
// Copyright 2013 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using SR = System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.XPath;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class XmlResolutionException : Exception {
public XmlResolutionException (string message, Exception innerException)
: base (message, innerException)
{
}
}
public class ResolveFromXmlStep : ResolveStep {
static readonly string _signature = "signature";
static readonly string _fullname = "fullname";
static readonly string _required = "required";
static readonly string _preserve = "preserve";
static readonly string _ns = string.Empty;
XPathDocument _document;
string _xmlDocumentLocation;
public ResolveFromXmlStep (XPathDocument document, string xmlDocumentLocation = "<unspecified>")
{
_document = document;
_xmlDocumentLocation = xmlDocumentLocation;
}
protected override void Process ()
{
XPathNavigator nav = _document.CreateNavigator ();
nav.MoveToFirstChild ();
// This step can be created with XML files that aren't necessarily
// linker descriptor files. So bail if we don't have a <linker> element.
if (nav.LocalName != "linker")
return;
try {
ProcessAssemblies (Context, nav.SelectChildren ("assembly", _ns));
} catch (Exception ex) {
throw new XmlResolutionException (string.Format ("Failed to process XML description: {0}", _xmlDocumentLocation), ex);
}
}
void ProcessAssemblies (LinkContext context, XPathNodeIterator iterator)
{
while (iterator.MoveNext ()) {
AssemblyDefinition assembly = GetAssembly (context, GetFullName (iterator.Current));
ProcessTypes (assembly, iterator.Current.SelectChildren ("type", _ns));
ProcessNamespaces (assembly, iterator.Current.SelectChildren ("namespace", _ns));
}
}
void ProcessNamespaces (AssemblyDefinition assembly, XPathNodeIterator iterator)
{
while (iterator.MoveNext ()) {
string fullname = GetFullName (iterator.Current);
foreach (TypeDefinition type in assembly.MainModule.Types) {
if (type.Namespace != fullname)
continue;
MarkAndPreserveAll (type);
}
}
}
void MarkAndPreserveAll (TypeDefinition type)
{
Annotations.Mark (type);
Annotations.SetPreserve (type, TypePreserve.All);
if (!type.HasNestedTypes)
return;
foreach (TypeDefinition nested in type.NestedTypes)
MarkAndPreserveAll (nested);
}
void ProcessTypes (AssemblyDefinition assembly, XPathNodeIterator iterator)
{
while (iterator.MoveNext ()) {
XPathNavigator nav = iterator.Current;
string fullname = GetFullName (nav);
if (IsTypePattern (fullname)) {
ProcessTypePattern (fullname, assembly, nav);
continue;
}
TypeDefinition type = assembly.MainModule.GetType (fullname);
if (type == null)
continue;
ProcessType (type, nav);
}
}
static bool IsTypePattern (string fullname)
{
return fullname.IndexOf ("*") != -1;
}
static Regex CreateRegexFromPattern (string pattern)
{
return new Regex (pattern.Replace(".", @"\.").Replace("*", "(.*)"));
}
void MatchType (TypeDefinition type, Regex regex, XPathNavigator nav)
{
if (regex.Match (type.FullName).Success)
ProcessType (type, nav);
if (!type.HasNestedTypes)
return;
foreach (var nt in type.NestedTypes)
MatchType (nt, regex, nav);
}
void ProcessTypePattern (string fullname, AssemblyDefinition assembly, XPathNavigator nav)
{
Regex regex = CreateRegexFromPattern (fullname);
foreach (TypeDefinition type in assembly.MainModule.Types) {
MatchType (type, regex, nav);
}
}
void ProcessType (TypeDefinition type, XPathNavigator nav)
{
TypePreserve preserve = GetTypePreserve (nav);
if (!IsRequired (nav)) {
Annotations.SetPreserve (type, preserve);
return;
}
Annotations.Mark (type);
if (type.IsNested) {
var parent = type;
while (parent.IsNested) {
parent = parent.DeclaringType;
Annotations.Mark (parent);
}
}
switch (preserve) {
case TypePreserve.Nothing:
if (!nav.HasChildren)
Annotations.SetPreserve (type, TypePreserve.All);
break;
default:
Annotations.SetPreserve (type, preserve);
break;
}
if (nav.HasChildren) {
MarkSelectedFields (nav, type);
MarkSelectedMethods (nav, type);
}
}
void MarkSelectedFields (XPathNavigator nav, TypeDefinition type)
{
XPathNodeIterator fields = nav.SelectChildren ("field", _ns);
if (fields.Count == 0)
return;
ProcessFields (type, fields);
}
void MarkSelectedMethods (XPathNavigator nav, TypeDefinition type)
{
XPathNodeIterator methods = nav.SelectChildren ("method", _ns);
if (methods.Count == 0)
return;
ProcessMethods (type, methods);
}
static TypePreserve GetTypePreserve (XPathNavigator nav)
{
string attribute = GetAttribute (nav, _preserve);
if (attribute == null || attribute.Length == 0)
return TypePreserve.Nothing;
try {
return (TypePreserve) Enum.Parse (typeof (TypePreserve), attribute, true);
} catch {
return TypePreserve.Nothing;
}
}
void ProcessFields (TypeDefinition type, XPathNodeIterator iterator)
{
while (iterator.MoveNext ()) {
string value = GetSignature (iterator.Current);
if (!String.IsNullOrEmpty (value))
ProcessFieldSignature (type, value);
value = GetAttribute (iterator.Current, "name");
if (!String.IsNullOrEmpty (value))
ProcessFieldName (type, value);
}
}
void ProcessFieldSignature (TypeDefinition type, string signature)
{
FieldDefinition field = GetField (type, signature);
MarkField (type, field, signature);
}
void MarkField (TypeDefinition type, FieldDefinition field, string signature)
{
if (field != null)
Annotations.Mark (field);
else
AddUnresolveMarker (string.Format ("T: {0}; F: {1}", type, signature));
}
void ProcessFieldName (TypeDefinition type, string name)
{
if (!type.HasFields)
return;
foreach (FieldDefinition field in type.Fields)
if (field.Name == name)
MarkField (type, field, name);
}
static FieldDefinition GetField (TypeDefinition type, string signature)
{
if (!type.HasFields)
return null;
foreach (FieldDefinition field in type.Fields)
if (signature == GetFieldSignature (field))
return field;
return null;
}
static string GetFieldSignature (FieldDefinition field)
{
return field.FieldType.FullName + " " + field.Name;
}
void ProcessMethods (TypeDefinition type, XPathNodeIterator iterator)
{
while (iterator.MoveNext()) {
string value = GetSignature (iterator.Current);
if (!String.IsNullOrEmpty (value))
ProcessMethodSignature (type, value);
value = GetAttribute (iterator.Current, "name");
if (!String.IsNullOrEmpty (value))
ProcessMethodName (type, value);
}
}
void ProcessMethodSignature (TypeDefinition type, string signature)
{
MethodDefinition meth = GetMethod (type, signature);
MarkMethod (type, meth, signature);
}
void MarkMethod (TypeDefinition type, MethodDefinition method, string signature)
{
if (method != null) {
Annotations.Mark (method);
Annotations.SetAction (method, MethodAction.Parse);
} else
AddUnresolveMarker (string.Format ("T: {0}; M: {1}", type, signature));
}
void ProcessMethodName (TypeDefinition type, string name)
{
if (!type.HasMethods)
return;
foreach (MethodDefinition method in type.Methods)
if (name == method.Name)
MarkMethod (type, method, name);
}
static MethodDefinition GetMethod (TypeDefinition type, string signature)
{
if (type.HasMethods)
foreach (MethodDefinition meth in type.Methods)
if (signature == GetMethodSignature (meth))
return meth;
return null;
}
static string GetMethodSignature (MethodDefinition meth)
{
StringBuilder sb = new StringBuilder ();
sb.Append (meth.ReturnType.FullName);
sb.Append (" ");
sb.Append (meth.Name);
sb.Append ("(");
if (meth.HasParameters) {
for (int i = 0; i < meth.Parameters.Count; i++) {
if (i > 0)
sb.Append (",");
sb.Append (meth.Parameters [i].ParameterType.FullName);
}
}
sb.Append (")");
return sb.ToString ();
}
static AssemblyDefinition GetAssembly (LinkContext context, string assemblyName)
{
AssemblyNameReference reference = AssemblyNameReference.Parse (assemblyName);
AssemblyDefinition assembly;
assembly = context.Resolve (reference);
ProcessReferences (assembly, context);
return assembly;
}
static void ProcessReferences (AssemblyDefinition assembly, LinkContext context)
{
foreach (AssemblyNameReference name in assembly.MainModule.AssemblyReferences)
context.Resolve (name);
}
static bool IsRequired (XPathNavigator nav)
{
string attribute = GetAttribute (nav, _required);
if (attribute == null || attribute.Length == 0)
return true;
return TryParseBool (attribute);
}
static bool TryParseBool (string s)
{
try {
return bool.Parse (s);
} catch {
return false;
}
}
static string GetSignature (XPathNavigator nav)
{
return GetAttribute (nav, _signature);
}
static string GetFullName (XPathNavigator nav)
{
return GetAttribute (nav, _fullname);
}
static string GetAttribute (XPathNavigator nav, string attribute)
{
return nav.GetAttribute (attribute, _ns);
}
}
}

View File

@@ -1,57 +0,0 @@
//
// ResolveStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Linker.Steps {
using System.Collections;
public abstract class ResolveStep : BaseStep {
ArrayList _unResolved;
internal ResolveStep ()
{
_unResolved = new ArrayList ();
}
public bool AllMarkerResolved
{
get { return _unResolved.Count == 0; }
}
public string [] GetUnresolvedMarkers ()
{
return _unResolved.ToArray (typeof (string)) as string [];
}
protected void AddUnresolveMarker (string signature)
{
_unResolved.Add (signature);
}
}
}

View File

@@ -1,229 +0,0 @@
//
// SweepStep.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Collections.Generic;
using Mono.Cecil;
using Mono.Collections.Generic;
namespace Mono.Linker.Steps {
public class SweepStep : BaseStep {
AssemblyDefinition [] assemblies;
HashSet<AssemblyDefinition> resolvedTypeReferences;
protected override void Process ()
{
assemblies = Context.GetAssemblies ();
foreach (var assembly in assemblies) {
SweepAssembly (assembly);
if (Annotations.GetAction (assembly) == AssemblyAction.Copy) {
// Copy assemblies can still contain Type references with
// type forwarders from Delete assemblies
// thus try to resolve all the type references and see
// if some changed the scope. if yes change the action to Save
if (ResolveAllTypeReferences (assembly))
Annotations.SetAction (assembly, AssemblyAction.Save);
}
}
}
void SweepAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
if (!IsMarkedAssembly (assembly)) {
RemoveAssembly (assembly);
return;
}
var types = new List<TypeDefinition> ();
foreach (TypeDefinition type in assembly.MainModule.Types) {
if (Annotations.IsMarked (type)) {
SweepType (type);
types.Add (type);
continue;
}
if (type.Name == "<Module>")
types.Add (type);
}
assembly.MainModule.Types.Clear ();
foreach (TypeDefinition type in types)
assembly.MainModule.Types.Add (type);
}
bool IsMarkedAssembly (AssemblyDefinition assembly)
{
return Annotations.IsMarked (assembly.MainModule);
}
void RemoveAssembly (AssemblyDefinition assembly)
{
Annotations.SetAction (assembly, AssemblyAction.Delete);
SweepReferences (assembly);
}
void SweepReferences (AssemblyDefinition target)
{
foreach (var assembly in assemblies)
SweepReferences (assembly, target);
}
void SweepReferences (AssemblyDefinition assembly, AssemblyDefinition target)
{
if (assembly == target)
return;
var references = assembly.MainModule.AssemblyReferences;
for (int i = 0; i < references.Count; i++) {
var reference = references [i];
var r = Context.Resolver.Resolve (reference);
if (!AreSameReference (r.Name, target.Name))
continue;
references.RemoveAt (i);
// Removing the reference does not mean it will be saved back to disk!
// That depends on the AssemblyAction set for the `assembly`
switch (Annotations.GetAction (assembly)) {
case AssemblyAction.Copy:
// Copy means even if "unlinked" we still want that assembly to be saved back
// to disk (OutputStep) without the (removed) reference
Annotations.SetAction (assembly, AssemblyAction.Save);
ResolveAllTypeReferences (assembly);
break;
case AssemblyAction.Save:
case AssemblyAction.Link:
ResolveAllTypeReferences (assembly);
break;
}
return;
}
}
bool ResolveAllTypeReferences (AssemblyDefinition assembly)
{
if (resolvedTypeReferences == null)
resolvedTypeReferences = new HashSet<AssemblyDefinition> ();
if (resolvedTypeReferences.Contains (assembly))
return false;
resolvedTypeReferences.Add (assembly);
var hash = new Dictionary<TypeReference,IMetadataScope> ();
bool changes = false;
foreach (TypeReference tr in assembly.MainModule.GetTypeReferences ()) {
if (hash.ContainsKey (tr))
continue;
var td = tr.Resolve ();
IMetadataScope scope = tr.Scope;
// at this stage reference might include things that can't be resolved
// and if it is (resolved) it needs to be kept only if marked (#16213)
if ((td != null) && Annotations.IsMarked (td)) {
scope = assembly.MainModule.ImportReference (td).Scope;
if (tr.Scope != scope)
changes = true;
hash.Add (tr, scope);
}
}
if (assembly.MainModule.HasExportedTypes) {
foreach (var et in assembly.MainModule.ExportedTypes) {
var td = et.Resolve ();
IMetadataScope scope = et.Scope;
if ((td != null) && Annotations.IsMarked (td)) {
scope = assembly.MainModule.ImportReference (td).Scope;
hash.Add (td, scope);
et.Scope = scope;
}
}
}
// Resolve everything first before updating scopes.
// If we set the scope to null, then calling Resolve() on any of its
// nested types would crash.
foreach (var e in hash) {
e.Key.Scope = e.Value;
}
return changes;
}
void SweepType (TypeDefinition type)
{
if (type.HasFields)
SweepCollection (type.Fields);
if (type.HasMethods)
SweepCollection (type.Methods);
if (type.HasNestedTypes)
SweepNestedTypes (type);
}
void SweepNestedTypes (TypeDefinition type)
{
for (int i = 0; i < type.NestedTypes.Count; i++) {
var nested = type.NestedTypes [i];
if (Annotations.IsMarked (nested)) {
SweepType (nested);
} else {
type.NestedTypes.RemoveAt (i--);
}
}
}
void SweepCollection (IList list)
{
for (int i = 0; i < list.Count; i++)
if (!Annotations.IsMarked ((IMetadataTokenProvider) list [i]))
list.RemoveAt (i--);
}
static bool AreSameReference (AssemblyNameReference a, AssemblyNameReference b)
{
if (a == b)
return true;
if (a.Name != b.Name)
return false;
if (a.Version > b.Version)
return false;
return true;
}
}
}

View File

@@ -1,307 +0,0 @@
//
// TypeMapStep.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using Mono.Cecil;
namespace Mono.Linker.Steps {
public class TypeMapStep : BaseStep {
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
foreach (TypeDefinition type in assembly.MainModule.Types)
MapType (type);
}
protected virtual void MapType (TypeDefinition type)
{
MapVirtualMethods (type);
MapInterfaceMethodsInTypeHierarchy (type);
if (!type.HasNestedTypes)
return;
foreach (var nested in type.NestedTypes)
MapType (nested);
}
void MapInterfaceMethodsInTypeHierarchy (TypeDefinition type)
{
if (!type.HasInterfaces)
return;
foreach (var @interface in type.Interfaces) {
var iface = @interface.InterfaceType.Resolve ();
if (iface == null || !iface.HasMethods)
continue;
foreach (MethodDefinition method in iface.Methods) {
if (TryMatchMethod (type, method) != null)
continue;
var @base = GetBaseMethodInTypeHierarchy (type, method);
if (@base == null)
continue;
Annotations.AddPreservedMethod (type, @base);
}
}
}
void MapVirtualMethods (TypeDefinition type)
{
if (!type.HasMethods)
return;
foreach (MethodDefinition method in type.Methods) {
if (!method.IsVirtual)
continue;
MapVirtualMethod (method);
if (method.HasOverrides)
MapOverrides (method);
}
}
void MapVirtualMethod (MethodDefinition method)
{
MapVirtualBaseMethod (method);
MapVirtualInterfaceMethod (method);
}
void MapVirtualBaseMethod (MethodDefinition method)
{
MethodDefinition @base = GetBaseMethodInTypeHierarchy (method);
if (@base == null)
return;
AnnotateMethods (@base, method);
}
void MapVirtualInterfaceMethod (MethodDefinition method)
{
foreach (MethodDefinition @base in GetBaseMethodsInInterfaceHierarchy (method))
AnnotateMethods (@base, method);
}
void MapOverrides (MethodDefinition method)
{
foreach (MethodReference override_ref in method.Overrides) {
MethodDefinition @override = override_ref.Resolve ();
if (@override == null)
continue;
AnnotateMethods (@override, method);
}
}
void AnnotateMethods (MethodDefinition @base, MethodDefinition @override)
{
Annotations.AddBaseMethod (@override, @base);
Annotations.AddOverride (@base, @override);
}
static MethodDefinition GetBaseMethodInTypeHierarchy (MethodDefinition method)
{
return GetBaseMethodInTypeHierarchy (method.DeclaringType, method);
}
static MethodDefinition GetBaseMethodInTypeHierarchy (TypeDefinition type, MethodDefinition method)
{
TypeDefinition @base = GetBaseType (type);
while (@base != null) {
MethodDefinition base_method = TryMatchMethod (@base, method);
if (base_method != null)
return base_method;
@base = GetBaseType (@base);
}
return null;
}
static IEnumerable<MethodDefinition> GetBaseMethodsInInterfaceHierarchy (MethodDefinition method)
{
return GetBaseMethodsInInterfaceHierarchy (method.DeclaringType, method);
}
static IEnumerable<MethodDefinition> GetBaseMethodsInInterfaceHierarchy (TypeDefinition type, MethodDefinition method)
{
if (!type.HasInterfaces)
yield break;
foreach (var interface_ref in type.Interfaces) {
TypeDefinition @interface = interface_ref.InterfaceType.Resolve ();
if (@interface == null)
continue;
MethodDefinition base_method = TryMatchMethod (@interface, method);
if (base_method != null)
yield return base_method;
foreach (MethodDefinition @base in GetBaseMethodsInInterfaceHierarchy (@interface, method))
yield return @base;
}
}
static MethodDefinition TryMatchMethod (TypeDefinition type, MethodDefinition method)
{
if (!type.HasMethods)
return null;
Dictionary<string,string> gp = null;
foreach (MethodDefinition candidate in type.Methods) {
if (MethodMatch (candidate, method, ref gp))
return candidate;
if (gp != null)
gp.Clear ();
}
return null;
}
static bool MethodMatch (MethodDefinition candidate, MethodDefinition method, ref Dictionary<string,string> genericParameters)
{
if (!candidate.IsVirtual)
return false;
if (candidate.HasParameters != method.HasParameters)
return false;
if (candidate.Name != method.Name)
return false;
if (candidate.HasGenericParameters != method.HasGenericParameters)
return false;
// we need to track what the generic parameter represent - as we cannot allow it to
// differ between the return type or any parameter
if (!TypeMatch (candidate.ReturnType, method.ReturnType, ref genericParameters))
return false;
if (!candidate.HasParameters)
return true;
var cp = candidate.Parameters;
var mp = method.Parameters;
if (cp.Count != mp.Count)
return false;
for (int i = 0; i < cp.Count; i++) {
if (!TypeMatch (cp [i].ParameterType, mp [i].ParameterType, ref genericParameters))
return false;
}
return true;
}
static bool TypeMatch (IModifierType a, IModifierType b, ref Dictionary<string,string> gp)
{
if (!TypeMatch (a.ModifierType, b.ModifierType, ref gp))
return false;
return TypeMatch (a.ElementType, b.ElementType, ref gp);
}
static bool TypeMatch (TypeSpecification a, TypeSpecification b, ref Dictionary<string,string> gp)
{
var gita = a as GenericInstanceType;
if (gita != null)
return TypeMatch (gita, (GenericInstanceType) b, ref gp);
var mta = a as IModifierType;
if (mta != null)
return TypeMatch (mta, (IModifierType) b, ref gp);
return TypeMatch (a.ElementType, b.ElementType, ref gp);
}
static bool TypeMatch (GenericInstanceType a, GenericInstanceType b, ref Dictionary<string,string> gp)
{
if (!TypeMatch (a.ElementType, b.ElementType, ref gp))
return false;
if (a.HasGenericArguments != b.HasGenericArguments)
return false;
if (!a.HasGenericArguments)
return true;
var gaa = a.GenericArguments;
var gab = b.GenericArguments;
if (gaa.Count != gab.Count)
return false;
for (int i = 0; i < gaa.Count; i++) {
if (!TypeMatch (gaa [i], gab [i], ref gp))
return false;
}
return true;
}
static bool TypeMatch (TypeReference a, TypeReference b, ref Dictionary<string,string> gp)
{
var gpa = a as GenericParameter;
if (gpa != null) {
if (gp == null)
gp = new Dictionary<string, string> ();
string match;
if (!gp.TryGetValue (gpa.FullName, out match)) {
// first use, we assume it will always be used this way
gp.Add (gpa.FullName, b.ToString ());
return true;
}
// re-use, it should match the previous usage
return match == b.ToString ();
}
if (a is TypeSpecification || b is TypeSpecification) {
if (a.GetType () != b.GetType ())
return false;
return TypeMatch ((TypeSpecification) a, (TypeSpecification) b, ref gp);
}
return a.FullName == b.FullName;
}
static TypeDefinition GetBaseType (TypeDefinition type)
{
if (type == null || type.BaseType == null)
return null;
return type.BaseType.Resolve ();
}
}
}

View File

@@ -1,329 +0,0 @@
//
// Annotations.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace Mono.Linker {
public class AnnotationStore {
readonly Dictionary<AssemblyDefinition, AssemblyAction> assembly_actions = new Dictionary<AssemblyDefinition, AssemblyAction> ();
readonly Dictionary<MethodDefinition, MethodAction> method_actions = new Dictionary<MethodDefinition, MethodAction> ();
readonly HashSet<IMetadataTokenProvider> marked = new HashSet<IMetadataTokenProvider> ();
readonly HashSet<IMetadataTokenProvider> processed = new HashSet<IMetadataTokenProvider> ();
readonly Dictionary<TypeDefinition, TypePreserve> preserved_types = new Dictionary<TypeDefinition, TypePreserve> ();
readonly Dictionary<IMemberDefinition, List<MethodDefinition>> preserved_methods = new Dictionary<IMemberDefinition, List<MethodDefinition>> ();
readonly HashSet<IMetadataTokenProvider> public_api = new HashSet<IMetadataTokenProvider> ();
readonly Dictionary<MethodDefinition, List<MethodDefinition>> override_methods = new Dictionary<MethodDefinition, List<MethodDefinition>> ();
readonly Dictionary<MethodDefinition, List<MethodDefinition>> base_methods = new Dictionary<MethodDefinition, List<MethodDefinition>> ();
readonly Dictionary<AssemblyDefinition, ISymbolReader> symbol_readers = new Dictionary<AssemblyDefinition, ISymbolReader> ();
readonly Dictionary<object, Dictionary<IMetadataTokenProvider, object>> custom_annotations = new Dictionary<object, Dictionary<IMetadataTokenProvider, object>> ();
Stack<object> dependency_stack;
System.Xml.XmlWriter writer;
GZipStream zipStream;
public void PrepareDependenciesDump ()
{
PrepareDependenciesDump ("linker-dependencies.xml.gz");
}
public void PrepareDependenciesDump (string filename)
{
dependency_stack = new Stack<object> ();
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
var depsFile = File.OpenWrite (filename);
zipStream = new GZipStream (depsFile, CompressionMode.Compress);
writer = System.Xml.XmlWriter.Create (zipStream, settings);
writer.WriteStartDocument ();
writer.WriteStartElement ("dependencies");
writer.WriteStartAttribute ("version");
writer.WriteString ("1.0");
writer.WriteEndAttribute ();
}
public AssemblyAction GetAction (AssemblyDefinition assembly)
{
AssemblyAction action;
if (assembly_actions.TryGetValue (assembly, out action))
return action;
throw new NotSupportedException ();
}
public MethodAction GetAction (MethodDefinition method)
{
MethodAction action;
if (method_actions.TryGetValue (method, out action))
return action;
return MethodAction.Nothing;
}
public void SetAction (AssemblyDefinition assembly, AssemblyAction action)
{
assembly_actions [assembly] = action;
}
public bool HasAction (AssemblyDefinition assembly)
{
return assembly_actions.ContainsKey (assembly);
}
public void SetAction (MethodDefinition method, MethodAction action)
{
method_actions [method] = action;
}
public void Mark (IMetadataTokenProvider provider)
{
marked.Add (provider);
AddDependency (provider);
}
public bool IsMarked (IMetadataTokenProvider provider)
{
return marked.Contains (provider);
}
public void Processed (IMetadataTokenProvider provider)
{
processed.Add (provider);
}
public bool IsProcessed (IMetadataTokenProvider provider)
{
return processed.Contains (provider);
}
public bool IsPreserved (TypeDefinition type)
{
return preserved_types.ContainsKey (type);
}
public void SetPreserve (TypeDefinition type, TypePreserve preserve)
{
preserved_types [type] = preserve;
}
public TypePreserve GetPreserve (TypeDefinition type)
{
TypePreserve preserve;
if (preserved_types.TryGetValue (type, out preserve))
return preserve;
throw new NotSupportedException ();
}
public void SetPublic (IMetadataTokenProvider provider)
{
public_api.Add (provider);
}
public bool IsPublic (IMetadataTokenProvider provider)
{
return public_api.Contains (provider);
}
public void AddOverride (MethodDefinition @base, MethodDefinition @override)
{
var methods = GetOverrides (@base);
if (methods == null) {
methods = new List<MethodDefinition> ();
override_methods [@base] = methods;
}
methods.Add (@override);
}
public List<MethodDefinition> GetOverrides (MethodDefinition method)
{
List<MethodDefinition> overrides;
if (override_methods.TryGetValue (method, out overrides))
return overrides;
return null;
}
public void AddBaseMethod (MethodDefinition method, MethodDefinition @base)
{
var methods = GetBaseMethods (method);
if (methods == null) {
methods = new List<MethodDefinition> ();
base_methods [method] = methods;
}
methods.Add (@base);
}
public List<MethodDefinition> GetBaseMethods (MethodDefinition method)
{
List<MethodDefinition> bases;
if (base_methods.TryGetValue (method, out bases))
return bases;
return null;
}
public List<MethodDefinition> GetPreservedMethods (TypeDefinition type)
{
return GetPreservedMethods (type as IMemberDefinition);
}
public void AddPreservedMethod (TypeDefinition type, MethodDefinition method)
{
AddPreservedMethod (type as IMemberDefinition, method);
}
public List<MethodDefinition> GetPreservedMethods (MethodDefinition method)
{
return GetPreservedMethods (method as IMemberDefinition);
}
public void AddPreservedMethod (MethodDefinition key, MethodDefinition method)
{
AddPreservedMethod (key as IMemberDefinition, method);
}
List<MethodDefinition> GetPreservedMethods (IMemberDefinition definition)
{
List<MethodDefinition> preserved;
if (preserved_methods.TryGetValue (definition, out preserved))
return preserved;
return null;
}
void AddPreservedMethod (IMemberDefinition definition, MethodDefinition method)
{
var methods = GetPreservedMethods (definition);
if (methods == null) {
methods = new List<MethodDefinition> ();
preserved_methods [definition] = methods;
}
methods.Add (method);
}
public void AddSymbolReader (AssemblyDefinition assembly, ISymbolReader symbolReader)
{
symbol_readers [assembly] = symbolReader;
}
public void CloseSymbolReader (AssemblyDefinition assembly)
{
ISymbolReader symbolReader;
if (!symbol_readers.TryGetValue (assembly, out symbolReader))
return;
symbol_readers.Remove (assembly);
symbolReader.Dispose ();
}
public Dictionary<IMetadataTokenProvider, object> GetCustomAnnotations (object key)
{
Dictionary<IMetadataTokenProvider, object> slots;
if (custom_annotations.TryGetValue (key, out slots))
return slots;
slots = new Dictionary<IMetadataTokenProvider, object> ();
custom_annotations.Add (key, slots);
return slots;
}
public void AddDependency (object o)
{
if (writer == null)
return;
KeyValuePair<object, object> pair = new KeyValuePair<object, object> (dependency_stack.Count > 0 ? dependency_stack.Peek () : null, o);
writer.WriteStartElement ("edge");
writer.WriteAttributeString ("b", TokenString (pair.Key));
writer.WriteAttributeString ("e", TokenString (pair.Value));
writer.WriteEndElement ();
}
public void Push (object o)
{
if (writer == null)
return;
if (dependency_stack.Count > 0)
AddDependency (o);
dependency_stack.Push (o);
}
public void Pop ()
{
if (writer == null)
return;
dependency_stack.Pop ();
}
string TokenString (object o)
{
if (o == null)
return "N:null";
if (o is IMetadataTokenProvider)
return (o as IMetadataTokenProvider).MetadataToken.TokenType + ":" + o;
return "Other:" + o;
}
public void SaveDependencies ()
{
if (writer == null)
return;
writer.WriteEndElement ();
writer.WriteEndDocument ();
writer.Flush ();
writer.Close ();
zipStream.Close ();
writer.Dispose ();
zipStream.Dispose ();
writer = null;
zipStream = null;
dependency_stack = null;
}
}
}

View File

@@ -1,46 +0,0 @@
//
// AssemblyAction.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Linker {
public enum AssemblyAction {
// Ignore the assembly
Skip,
// Copy the existing files, assembly and symbols, into the output destination. E.g. .dll and .mdb
// The linker still analyze the assemblies (to know what they require) but does not modify them
Copy,
// Link the assembly
Link,
// Remove the assembly from the output
Delete,
// Save the assembly/symbols in memory without linking it.
// E.g. useful to remove unneeded assembly references (as done in SweepStep),
// resolving [TypeForwardedTo] attributes (like PCL) to their final location
Save
}
}

View File

@@ -1,43 +0,0 @@
//
// AssemblyInfo.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// (C) 2006 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Linker")]
[assembly: AssemblyDescription ("Mono CIL Linker")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("(C) 2006, Jb Evain")]
[assembly: AssemblyCulture ("")]
[assembly: CLSCompliant (false)]
[assembly: ComVisible (false)]
[assembly: AssemblyVersion ("0.2.0.0")]

View File

@@ -1,71 +0,0 @@
//
// AssemblyResolver.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.IO;
using Mono.Cecil;
namespace Mono.Linker {
public class AssemblyResolver : BaseAssemblyResolver {
IDictionary _assemblies;
public IDictionary AssemblyCache {
get { return _assemblies; }
}
public AssemblyResolver ()
: this (new Hashtable ())
{
}
public AssemblyResolver (IDictionary assembly_cache)
{
_assemblies = assembly_cache;
}
public override AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters)
{
AssemblyDefinition asm = (AssemblyDefinition) _assemblies [name.Name];
if (asm == null) {
asm = base.Resolve (name, parameters);
_assemblies [name.Name] = asm;
}
return asm;
}
public void CacheAssembly (AssemblyDefinition assembly)
{
_assemblies [assembly.Name.Name] = assembly;
base.AddSearchDirectory (Path.GetDirectoryName (assembly.MainModule.FileName));
}
}
}

Some files were not shown because too many files have changed in this diff Show More