You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@@ -312,6 +312,7 @@
|
||||
<type fullname="System.Threading.ExecutionContext" />
|
||||
<type fullname="System.Threading.Interlocked">
|
||||
<method name="CompareExchange" />
|
||||
<method name="Exchange" />
|
||||
</type>
|
||||
<type fullname="System.Threading.Monitor">
|
||||
<method name="Enter" />
|
||||
|
@@ -47,7 +47,7 @@ namespace Mono.Linker.Steps {
|
||||
protected override void Process ()
|
||||
{
|
||||
foreach (string name in Assembly.GetExecutingAssembly ().GetManifestResourceNames ()) {
|
||||
if (Path.GetExtension (name) != ".xml" || !IsReferenced (GetAssemblyName (name)))
|
||||
if (!name.EndsWith (".xml", StringComparison.OrdinalIgnoreCase) || !IsReferenced (GetAssemblyName (name)))
|
||||
continue;
|
||||
|
||||
try {
|
||||
@@ -61,22 +61,23 @@ namespace Mono.Linker.Steps {
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var rsc in Context.GetAssemblies ()
|
||||
.SelectMany (asm => asm.Modules)
|
||||
.SelectMany (mod => mod.Resources)
|
||||
.Where (res => res.ResourceType == ResourceType.Embedded)
|
||||
.Where (res => Path.GetExtension (res.Name) == ".xml")
|
||||
.Where (res => IsReferenced (GetAssemblyName (res.Name)))
|
||||
.Cast<EmbeddedResource> ()) {
|
||||
try {
|
||||
if (Context.LogInternalExceptions)
|
||||
Console.WriteLine ("Processing embedded resource linker descriptor: {0}", rsc.Name);
|
||||
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));
|
||||
} 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,14 +100,14 @@ namespace Mono.Linker.Steps {
|
||||
return false;
|
||||
}
|
||||
|
||||
static ResolveFromXmlStep GetExternalResolveStep (EmbeddedResource resource)
|
||||
static ResolveFromXmlStep GetExternalResolveStep (EmbeddedResource resource, AssemblyDefinition assembly)
|
||||
{
|
||||
return new ResolveFromXmlStep (GetExternalDescriptor (resource));
|
||||
return new ResolveFromXmlStep (GetExternalDescriptor (resource), "resource " + resource.Name + " in " + assembly.FullName);
|
||||
}
|
||||
|
||||
static ResolveFromXmlStep GetResolveStep (string descriptor)
|
||||
{
|
||||
return new ResolveFromXmlStep (GetDescriptor (descriptor));
|
||||
return new ResolveFromXmlStep (GetDescriptor (descriptor), "descriptor " + descriptor + " from " + Assembly.GetExecutingAssembly ().FullName);
|
||||
}
|
||||
|
||||
static XPathDocument GetExternalDescriptor (EmbeddedResource resource)
|
||||
|
@@ -123,7 +123,9 @@ namespace Mono.Linker.Steps {
|
||||
{
|
||||
while (!QueueIsEmpty ()) {
|
||||
MethodDefinition method = (MethodDefinition) _methods.Dequeue ();
|
||||
Annotations.Push (method);
|
||||
ProcessMethod (method);
|
||||
Annotations.Pop ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,6 +487,8 @@ namespace Mono.Linker.Steps {
|
||||
if (CheckProcessed (type))
|
||||
return null;
|
||||
|
||||
Annotations.Push (type);
|
||||
|
||||
MarkScope (type.Scope);
|
||||
MarkType (type.BaseType);
|
||||
MarkType (type.DeclaringType);
|
||||
@@ -518,6 +522,8 @@ namespace Mono.Linker.Steps {
|
||||
|
||||
DoAdditionalTypeProcessing (type);
|
||||
|
||||
Annotations.Pop ();
|
||||
|
||||
Annotations.Mark (type);
|
||||
|
||||
ApplyPreserveInfo (type);
|
||||
@@ -880,6 +886,7 @@ namespace Mono.Linker.Steps {
|
||||
if (reference.DeclaringType is ArrayType)
|
||||
return null;
|
||||
|
||||
Annotations.Push (reference);
|
||||
if (reference.DeclaringType is GenericInstanceType)
|
||||
MarkType (reference.DeclaringType);
|
||||
|
||||
@@ -888,13 +895,18 @@ namespace Mono.Linker.Steps {
|
||||
|
||||
MethodDefinition method = ResolveMethodDefinition (reference);
|
||||
|
||||
if (method == null)
|
||||
if (method == null) {
|
||||
Annotations.Pop ();
|
||||
throw new ResolutionException (reference);
|
||||
}
|
||||
|
||||
if (Annotations.GetAction (method) == MethodAction.Nothing)
|
||||
Annotations.SetAction (method, MethodAction.Parse);
|
||||
|
||||
EnqueueMethod (method);
|
||||
|
||||
Annotations.Pop ();
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,7 @@ namespace Mono.Linker.Steps {
|
||||
protected override void Process ()
|
||||
{
|
||||
CheckOutputDirectory ();
|
||||
Annotations.SaveDependencies ();
|
||||
}
|
||||
|
||||
void CheckOutputDirectory ()
|
||||
@@ -63,9 +64,11 @@ namespace Mono.Linker.Steps {
|
||||
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;
|
||||
|
@@ -56,10 +56,10 @@ namespace Mono.Linker.Steps {
|
||||
switch (assembly.MainModule.Kind) {
|
||||
case ModuleKind.Dll:
|
||||
ProcessLibrary (Context, assembly);
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
ProcessExecutable (assembly);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,14 +79,20 @@ namespace Mono.Linker.Steps {
|
||||
{
|
||||
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)
|
||||
@@ -94,14 +100,20 @@ namespace Mono.Linker.Steps {
|
||||
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)
|
||||
|
@@ -38,6 +38,13 @@ 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";
|
||||
@@ -47,10 +54,12 @@ namespace Mono.Linker.Steps {
|
||||
static readonly string _ns = string.Empty;
|
||||
|
||||
XPathDocument _document;
|
||||
string _xmlDocumentLocation;
|
||||
|
||||
public ResolveFromXmlStep (XPathDocument document)
|
||||
public ResolveFromXmlStep (XPathDocument document, string xmlDocumentLocation = "<unspecified>")
|
||||
{
|
||||
_document = document;
|
||||
_xmlDocumentLocation = xmlDocumentLocation;
|
||||
}
|
||||
|
||||
protected override void Process ()
|
||||
@@ -63,7 +72,11 @@ namespace Mono.Linker.Steps {
|
||||
if (nav.LocalName != "linker")
|
||||
return;
|
||||
|
||||
ProcessAssemblies (Context, nav.SelectChildren ("assembly", _ns));
|
||||
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)
|
||||
|
@@ -155,8 +155,8 @@ namespace Mono.Linker.Steps {
|
||||
scope = assembly.MainModule.Import (td).Scope;
|
||||
if (tr.Scope != scope)
|
||||
changes = true;
|
||||
hash.Add (tr, scope);
|
||||
}
|
||||
hash.Add (tr, scope);
|
||||
}
|
||||
if (assembly.MainModule.HasExportedTypes) {
|
||||
foreach (var et in assembly.MainModule.ExportedTypes) {
|
||||
|
@@ -29,6 +29,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
@@ -50,6 +52,32 @@ namespace Mono.Linker {
|
||||
|
||||
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;
|
||||
@@ -86,6 +114,7 @@ namespace Mono.Linker {
|
||||
public void Mark (IMetadataTokenProvider provider)
|
||||
{
|
||||
marked.Add (provider);
|
||||
AddDependency (provider);
|
||||
}
|
||||
|
||||
public bool IsMarked (IMetadataTokenProvider provider)
|
||||
@@ -237,5 +266,64 @@ namespace Mono.Linker {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -114,7 +114,9 @@ namespace Mono.Linker {
|
||||
{
|
||||
while (_steps.Count > 0) {
|
||||
IStep step = (IStep) _steps [0];
|
||||
context.Annotations.Push (step);
|
||||
step.Process (context);
|
||||
context.Annotations.Pop ();
|
||||
_steps.Remove (step);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user