-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from dellis1972/master
[Xamarin.Android.Build.Tasks] Import from monodroid/301e7238
- Loading branch information
Showing
194 changed files
with
43,528 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ bin | |
Configuration.Override.props | ||
obj | ||
packages | ||
.DS_Store |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Mono.Cecil; | ||
using Microsoft.Build.Utilities; | ||
|
||
using Java.Interop.Tools.Diagnostics; | ||
using Java.Interop.Tools.JavaCallableWrappers; | ||
|
||
namespace Xamarin.Android.Tasks | ||
{ | ||
class Generator | ||
{ | ||
public static bool CreateJavaSources (TaskLoggingHelper log, IEnumerable<TypeDefinition> javaTypes, string outputPath, bool useSharedRuntime, bool generateOnCreateOverrides, bool hasExportReference) | ||
{ | ||
bool ok = true; | ||
foreach (var t in javaTypes) { | ||
try { | ||
GenerateJavaSource (log, t, outputPath, useSharedRuntime, generateOnCreateOverrides, hasExportReference); | ||
} catch (XamarinAndroidException xae) { | ||
ok = false; | ||
log.LogError ( | ||
subcategory: "", | ||
errorCode: "XA" + xae.Code, | ||
helpKeyword: string.Empty, | ||
file: xae.SourceFile, | ||
lineNumber: xae.SourceLine, | ||
columnNumber: 0, | ||
endLineNumber: 0, | ||
endColumnNumber: 0, | ||
message: xae.MessageWithoutCode, | ||
messageArgs: new object [0] | ||
); | ||
} | ||
} | ||
return ok; | ||
} | ||
|
||
static void GenerateJavaSource (TaskLoggingHelper log, TypeDefinition t, string outputPath, bool useSharedRuntime, bool generateOnCreateOverrides, bool hasExportReference) | ||
{ | ||
try { | ||
var jti = new JavaCallableWrapperGenerator (t, log.LogWarning) { | ||
UseSharedRuntime = useSharedRuntime, | ||
GenerateOnCreateOverrides = generateOnCreateOverrides, | ||
}; | ||
|
||
jti.Generate (outputPath); | ||
if (jti.HasExport && !hasExportReference) | ||
Diagnostic.Error (4210, "You need to add a reference to Mono.Android.Export.dll when you use ExportAttribute or ExportFieldAttribute."); | ||
} catch (Exception ex) { | ||
if (ex is XamarinAndroidException) | ||
throw; | ||
Diagnostic.Error (4209, "Failed to create JavaTypeInfo for class: {0} due to {1}", t.FullName, ex); | ||
} | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace Xamarin.Android.Tasks | ||
{ | ||
public enum LinkModes | ||
{ | ||
None, | ||
SdkOnly, | ||
Full | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/Xamarin.Android.Build.Tasks/Linker/Mobile.Tuner/MobileProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Mono.Cecil; | ||
|
||
using Mono.Tuner; | ||
|
||
namespace Mobile.Tuner { | ||
|
||
public abstract class MobileProfile : Profile { | ||
|
||
static readonly HashSet<string> Sdk = new HashSet<string> { | ||
"mscorlib", | ||
"System", | ||
"System.ComponentModel.Composition", | ||
"System.ComponentModel.DataAnnotations", | ||
"System.Core", | ||
"System.Data", | ||
"System.Data.Services.Client", | ||
"System.IO.Compression.FileSystem", | ||
"System.IO.Compression", | ||
"System.Json", | ||
"System.Net", | ||
"System.Net.Http", | ||
"System.Numerics", | ||
"System.Runtime.Serialization", | ||
"System.ServiceModel", | ||
"System.ServiceModel.Web", | ||
"System.Transactions", | ||
"System.Web.Services", | ||
"System.Windows", | ||
"System.Xml", | ||
"System.Xml.Linq", | ||
"System.Xml.Serialization", | ||
"Microsoft.CSharp", | ||
"Microsoft.VisualBasic", | ||
"Mono.CSharp", | ||
"Mono.Cairo", | ||
"Mono.CompilerServices.SymbolWriter", | ||
"Mono.Data.Tds", | ||
"Mono.Data.Sqlite", | ||
"Mono.Security", | ||
"OpenTK", | ||
"OpenTK-1.0", | ||
// Facades assemblies (PCL) | ||
"System.Collections.Concurrent", | ||
"System.Collections", | ||
"System.ComponentModel.Annotations", | ||
"System.ComponentModel.EventBasedAsync", | ||
"System.ComponentModel", | ||
"System.Diagnostics.Contracts", | ||
"System.Diagnostics.Debug", | ||
"System.Diagnostics.Tools", | ||
"System.Dynamic.Runtime", | ||
"System.EnterpriseServices", | ||
"System.Globalization", | ||
"System.IO", | ||
"System.Linq.Expressions", | ||
"System.Linq.Parallel", | ||
"System.Linq.Queryable", | ||
"System.Linq", | ||
"System.Net.NetworkInformation", | ||
"System.Net.Primitives", | ||
"System.Net.Requests", | ||
"System.ObjectModel", | ||
"System.Reflection.Extensions", | ||
"System.Reflection.Primitives", | ||
"System.Reflection", | ||
"System.Resources.ResourceManager", | ||
"System.Runtime.Extensions", | ||
"System.Runtime.InteropServices", | ||
"System.Runtime.InteropServices.WindowsRuntime", | ||
"System.Runtime.Numerics", | ||
"System.Runtime.Serialization.Json", | ||
"System.Runtime.Serialization.Primitives", | ||
"System.Runtime.Serialization.Xml", | ||
"System.Runtime", | ||
"System.Security.Principal", | ||
"System.ServiceModel.Http", | ||
"System.ServiceModel.Primitives", | ||
"System.Text.Encoding.Extensions", | ||
"System.Text.Encoding", | ||
"System.Text.RegularExpressions", | ||
"System.Threading.Tasks.Parallel", | ||
"System.Threading.Tasks", | ||
"System.Threading", | ||
"System.Xml.ReaderWriter", | ||
"System.Xml.XDocument", | ||
"System.Xml.XmlSerializer", | ||
}; | ||
|
||
protected override bool IsSdk (string assemblyName) | ||
{ | ||
return Sdk.Contains (assemblyName); | ||
} | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/ApplyPreserveAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Copyright 2011, 2015 Xamarin Inc. All rights reserved. | ||
|
||
using System; | ||
|
||
using Mono.Linker; | ||
using Mono.Tuner; | ||
|
||
using Mono.Cecil; | ||
|
||
namespace MonoDroid.Tuner { | ||
|
||
public class ApplyPreserveAttribute : ApplyPreserveAttributeBase { | ||
|
||
// System.ServiceModeldll is an SDK assembly but it does contain types with [DataMember] attributes | ||
public override bool IsActiveFor (AssemblyDefinition assembly) | ||
{ | ||
if (Profile.IsSdkAssembly (assembly)) { | ||
if (assembly.Name.Name != "System.ServiceModel") | ||
return false; | ||
} | ||
return Annotations.GetAction (assembly) == AssemblyAction.Link; | ||
} | ||
|
||
protected override bool IsPreservedAttribute (ICustomAttributeProvider provider, CustomAttribute attribute, out bool removeAttribute) | ||
{ | ||
removeAttribute = false; | ||
TypeReference type = attribute.Constructor.DeclaringType; | ||
|
||
switch (type.Namespace) { | ||
case "Android.Runtime": | ||
// there's no need to keep the [Preserve] attribute in the assembly once it was processed | ||
if (type.Name == "PreserveAttribute") { | ||
removeAttribute = true; | ||
return true; | ||
} | ||
break; | ||
case "System.Runtime.Serialization": | ||
bool srs = false; | ||
// http://bugzilla.xamarin.com/show_bug.cgi?id=1415 | ||
// http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx | ||
if (provider is PropertyDefinition || provider is FieldDefinition || provider is EventDefinition) | ||
srs = (type.Name == "DataMemberAttribute"); | ||
else if (provider is TypeDefinition) | ||
srs = (type.Name == "DataContractAttribute"); | ||
|
||
if (srs) { | ||
MarkDefautConstructor (provider); | ||
return true; | ||
} | ||
break; | ||
case "System.Xml.Serialization": | ||
// http://msdn.microsoft.com/en-us/library/83y7df3e.aspx | ||
string name = type.Name; | ||
if ((name.StartsWith ("Xml", StringComparison.Ordinal) && name.EndsWith ("Attribute", StringComparison.Ordinal))) { | ||
// but we do not have to keep things that XML serialization will ignore anyway! | ||
if (name != "XmlIgnoreAttribute") { | ||
// the default constructor of the type *being used* is needed | ||
MarkDefautConstructor (provider); | ||
return true; | ||
} | ||
} | ||
break; | ||
default: | ||
if (type.Name == "PreserveAttribute") { | ||
// there's no need to keep the [Preserve] attribute in the assembly once it was processed | ||
removeAttribute = true; | ||
return true; | ||
} | ||
break; | ||
} | ||
// keep them (provider and attribute) | ||
return false; | ||
} | ||
|
||
// xml serialization requires the default .ctor to be present | ||
void MarkDefautConstructor (ICustomAttributeProvider provider) | ||
{ | ||
TypeDefinition td = (provider as TypeDefinition); | ||
if (td == null) { | ||
PropertyDefinition pd = (provider as PropertyDefinition); | ||
if (pd != null) { | ||
MarkDefautConstructor (pd.DeclaringType); | ||
MarkGenericType (pd.PropertyType as GenericInstanceType); | ||
td = pd.PropertyType.Resolve (); | ||
} else { | ||
FieldDefinition fd = (provider as FieldDefinition); | ||
if (fd != null) { | ||
MarkDefautConstructor (fd.DeclaringType); | ||
MarkGenericType (fd.FieldType as GenericInstanceType); | ||
td = (fd.FieldType as TypeReference).Resolve (); | ||
} | ||
} | ||
} | ||
|
||
// e.g. <T> property (see bug #5543) or field (see linkall unit tests) | ||
if (td != null) | ||
MarkDefautConstructor (td); | ||
} | ||
|
||
void MarkGenericType (GenericInstanceType git) | ||
{ | ||
if (git == null || !git.HasGenericArguments) | ||
return; | ||
|
||
foreach (TypeReference tr in git.GenericArguments) | ||
MarkDefautConstructor (tr.Resolve ()); | ||
} | ||
|
||
void MarkDefautConstructor (TypeDefinition type) | ||
{ | ||
if ((type == null) || !type.HasMethods) | ||
return; | ||
|
||
foreach (MethodDefinition ctor in type.Methods) { | ||
if (!ctor.IsConstructor || ctor.IsStatic || ctor.HasParameters) | ||
continue; | ||
|
||
Annotations.AddPreservedMethod (type, ctor); | ||
} | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/Extensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Mono.Cecil; | ||
|
||
using Mono.Linker; | ||
|
||
using Mono.Tuner; | ||
|
||
namespace MonoDroid.Tuner { | ||
|
||
static class Extensions { | ||
|
||
const string JavaObject = "Java.Lang.Object"; | ||
const string IJavaObject = "Android.Runtime.IJavaObject"; | ||
const string JavaThrowable = "Java.Lang.Throwable"; | ||
|
||
public static bool IsJavaObject (this TypeDefinition type) | ||
{ | ||
return type.Inherits (JavaObject); | ||
} | ||
|
||
public static bool IsJavaException (this TypeDefinition type) | ||
{ | ||
return type.Inherits (JavaThrowable); | ||
} | ||
|
||
public static bool ImplementsIJavaObject (this TypeDefinition type) | ||
{ | ||
return type.Implements (IJavaObject); | ||
} | ||
|
||
public static object GetSettableValue (this CustomAttributeArgument arg) | ||
{ | ||
TypeReference tr = arg.Value as TypeReference; | ||
TypeDefinition td = tr != null ? tr.Resolve () : null; | ||
return td != null ? td.FullName + "," + td.Module.Assembly.FullName : arg.Value; | ||
} | ||
|
||
public static bool Implements (this TypeReference self, string interfaceName) | ||
{ | ||
if (interfaceName == null) | ||
throw new ArgumentNullException ("interfaceName"); | ||
if (self == null) | ||
return false; | ||
|
||
TypeDefinition type = self.Resolve (); | ||
if (type == null) | ||
return false; // not enough information available | ||
|
||
// special case, check if we implement ourselves | ||
if (type.IsInterface && (type.FullName == interfaceName)) | ||
return true; | ||
|
||
return Implements (type, interfaceName, (interfaceName.IndexOf ('`') >= 0)); | ||
} | ||
|
||
public static bool Implements (TypeDefinition type, string interfaceName, bool generic) | ||
{ | ||
while (type != null) { | ||
// does the type implements it itself | ||
if (type.HasInterfaces) { | ||
foreach (TypeReference iface in type.Interfaces) { | ||
string fullname = (generic) ? iface.GetElementType ().FullName : iface.FullName; | ||
if (fullname == interfaceName) | ||
return true; | ||
//if not, then maybe one of its parent interfaces does | ||
if (Implements (iface.Resolve (), interfaceName, generic)) | ||
return true; | ||
} | ||
} | ||
|
||
type = type.BaseType != null ? type.BaseType.Resolve () : null; | ||
} | ||
return false; | ||
} | ||
|
||
public static bool Inherits (this TypeReference self, string className) | ||
{ | ||
if (className == null) | ||
throw new ArgumentNullException ("className"); | ||
if (self == null) | ||
return false; | ||
|
||
TypeReference current = self.Resolve (); | ||
while (current != null) { | ||
string fullname = current.FullName; | ||
if (fullname == className) | ||
return true; | ||
if (fullname == "System.Object") | ||
return false; | ||
|
||
TypeDefinition td = current.Resolve (); | ||
if (td == null) | ||
return false; // could not resolve type | ||
current = td.BaseType; | ||
} | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.