[generator] Explicitly load NSNumber from the api assembly for core builds. (#1676)
* [generator] Explicitly load NSNumber from the api assembly for core builds. This fixes an issue where we'd run into a type comparison failure otherwise, when using the `BindAs` attribute in the api definition for our platform assemblies, because we end up with NSNumber loaded from two different assemblies: Foundation.NSNumber, **temp**, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Foundation.NSNumber, **core**, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null * [generator] Explicitly load NSValue too from the api assembly for core builds.
This commit is contained in:
Родитель
5fb09b1b84
Коммит
abc138a3da
|
@ -100,6 +100,8 @@ class BindingTouch {
|
|||
#endif
|
||||
static char shellQuoteChar;
|
||||
|
||||
public static bool BindingThirdParty = true;
|
||||
|
||||
public static string ToolName {
|
||||
get { return tool_name; }
|
||||
}
|
||||
|
@ -155,6 +157,20 @@ class BindingTouch {
|
|||
throw ErrorHelper.CreateError (70, "Invalid target framework: {0}. Valid target frameworks are: {1}.", target_framework.Value, string.Join (" ", TargetFramework.ValidFrameworks.Select ((v) => v.ToString ()).ToArray ()));
|
||||
}
|
||||
|
||||
public static string NamespacePlatformPrefix {
|
||||
get {
|
||||
switch (CurrentPlatform) {
|
||||
case PlatformName.MacOSX:
|
||||
return Unified ? null : "MonoMac";
|
||||
case PlatformName.iOS:
|
||||
return Unified ? null : "MonoTouch";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static int Main2 (string [] args)
|
||||
{
|
||||
bool show_help = false;
|
||||
|
@ -179,7 +195,6 @@ class BindingTouch {
|
|||
var core_sources = new List<string> ();
|
||||
var extra_sources = new List<string> ();
|
||||
var defines = new List<string> ();
|
||||
bool binding_third_party = true;
|
||||
string generate_file_list = null;
|
||||
bool process_enums = false;
|
||||
|
||||
|
@ -200,7 +215,7 @@ class BindingTouch {
|
|||
{ "sourceonly=", "Only generates the source", v => generate_file_list = v },
|
||||
{ "ns=", "Sets the namespace for storing helper classes", v => ns = v },
|
||||
{ "unsafe", "Sets the unsafe flag for the build", v=> unsafef = true },
|
||||
{ "core", "Use this to build product assemblies", v => binding_third_party = false },
|
||||
{ "core", "Use this to build product assemblies", v => BindingThirdParty = false },
|
||||
{ "r=", "Adds a reference", v => references.Add (v) },
|
||||
{ "lib=", "Adds the directory to the search path for the compiler", v => libs.Add (Quote (v)) },
|
||||
{ "compiler=", "Sets the compiler to use", v => compiler = v },
|
||||
|
@ -357,6 +372,8 @@ class BindingTouch {
|
|||
}
|
||||
GC.KeepAlive (baselib); // Fixes a compiler warning (unused variable).
|
||||
|
||||
TypeManager.Initialize (api);
|
||||
|
||||
foreach (object attr in AttributeManager.GetCustomAttributes (api, TypeManager.LinkWithAttribute, true)) {
|
||||
LinkWithAttribute linkWith = (LinkWithAttribute) attr;
|
||||
|
||||
|
@ -389,19 +406,6 @@ class BindingTouch {
|
|||
strong_dictionaries.Add (t);
|
||||
}
|
||||
|
||||
string nsManagerPrefix;
|
||||
switch (CurrentPlatform) {
|
||||
case PlatformName.MacOSX:
|
||||
nsManagerPrefix = Unified ? null : "MonoMac";
|
||||
break;
|
||||
case PlatformName.iOS:
|
||||
nsManagerPrefix = Unified ? null : "MonoTouch";
|
||||
break;
|
||||
default:
|
||||
nsManagerPrefix = null;
|
||||
break;
|
||||
}
|
||||
|
||||
if (CurrentPlatform == PlatformName.MacOSX && Unified) {
|
||||
if (!target_framework.HasValue)
|
||||
throw ErrorHelper.CreateError (86, "A target framework (--target-framework) must be specified when building for Xamarin.Mac.");
|
||||
|
@ -409,20 +413,20 @@ class BindingTouch {
|
|||
}
|
||||
|
||||
var nsManager = new NamespaceManager (
|
||||
nsManagerPrefix,
|
||||
NamespacePlatformPrefix,
|
||||
ns == null ? firstApiDefinitionName : ns,
|
||||
skipSystemDrawing
|
||||
);
|
||||
|
||||
var g = new Generator (nsManager, public_mode, external, debug, types.ToArray (), strong_dictionaries.ToArray ()){
|
||||
BindThirdPartyLibrary = binding_third_party,
|
||||
BindThirdPartyLibrary = BindingThirdParty,
|
||||
CoreNSObject = CoreObject,
|
||||
BaseDir = basedir != null ? basedir : tmpdir,
|
||||
ZeroCopyStrings = zero_copy,
|
||||
InlineSelectors = inline_selectors,
|
||||
};
|
||||
|
||||
if (!Unified && !binding_third_party) {
|
||||
if (!Unified && !BindingThirdParty) {
|
||||
foreach (var mi in baselib.GetType (nsManager.CoreObjCRuntime + ".Messaging").GetMethods ()){
|
||||
if (mi.Name.IndexOf ("_objc_msgSend") != -1)
|
||||
g.RegisterMethodName (mi.Name);
|
||||
|
|
|
@ -72,6 +72,7 @@ using ProductException=BindingException;
|
|||
// BI1049 Could not unbox type {0} from {1} container used on {2} member decorated with [BindAs].
|
||||
// BI1050 [BindAs] cannot be used inside Protocol or Model types. Type: {0}
|
||||
// BI1051 Internal error: Don't know how to get attributes for {0}. Please file a bug report (http://bugzilla.xamarin.com) with a test case.
|
||||
// BI1052 Internal error: Could not find the type {0} in the assembly {1}. Please file a bug report (http://bugzilla.xamarin.com) with a test case.
|
||||
// BI11xx warnings
|
||||
// BI1101 Trying to use a string as a [Target]
|
||||
// BI1102 Using the deprecated EventArgs for a delegate signature in {0}.{1}, please use DelegateName instead
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using XamCore.CoreFoundation;
|
||||
|
@ -286,8 +287,33 @@ public static class TypeManager {
|
|||
public static Type CoreGraphics_CGRect;
|
||||
public static Type CoreGraphics_CGSize;
|
||||
|
||||
static TypeManager ()
|
||||
static Assembly api_assembly;
|
||||
static Assembly platform_assembly;
|
||||
|
||||
static Type Lookup (Assembly assembly, string @namespace, string @typename)
|
||||
{
|
||||
string fullname;
|
||||
string nsManagerPrefix = BindingTouch.NamespacePlatformPrefix;
|
||||
if (!string.IsNullOrEmpty (nsManagerPrefix))
|
||||
nsManagerPrefix += ".";
|
||||
|
||||
if (string.IsNullOrEmpty (@namespace)) {
|
||||
fullname = nsManagerPrefix + @typename;
|
||||
} else {
|
||||
fullname = nsManagerPrefix + @namespace + "." + @typename;
|
||||
}
|
||||
|
||||
var rv = assembly.GetType (fullname);
|
||||
if (rv == null)
|
||||
throw new BindingException (1052, true, "Internal error: Could not find the type {0} in the assembly {1}. Please file a bug report (http://bugzilla.xamarin.com) with a test case.", fullname, assembly);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static void Initialize (Assembly api)
|
||||
{
|
||||
api_assembly = api;
|
||||
platform_assembly = typeof (NSObject).Assembly;
|
||||
|
||||
/* corlib */
|
||||
System_Attribute = typeof (System.Attribute);
|
||||
System_Boolean = typeof (bool);
|
||||
|
@ -474,10 +500,10 @@ public static class TypeManager {
|
|||
#if HAVE_AUDIOTOOLBOX_MUSICSEQUENCE
|
||||
MusicSequence = typeof (MusicSequence);
|
||||
#endif
|
||||
NSNumber = typeof (NSNumber);
|
||||
NSNumber = Lookup (BindingTouch.BindingThirdParty ? platform_assembly : api_assembly, "Foundation", "NSNumber");
|
||||
NSRange = typeof (NSRange);
|
||||
NSString = typeof (NSString);
|
||||
NSValue = typeof (NSValue);
|
||||
NSValue = Lookup (BindingTouch.BindingThirdParty ? platform_assembly : api_assembly, "Foundation", "NSValue");
|
||||
NSZone = typeof (NSZone);
|
||||
SCNMatrix4 = typeof (SCNMatrix4);
|
||||
SCNVector3 = typeof (SCNVector3);
|
||||
|
|
Загрузка…
Ссылка в новой задаче