[tools] Extract the code to parse, validate and process exception marshalling arguments into the Application class. (#9492)
So that it's easier to re-use it from our .NET linker code.
This commit is contained in:
Родитель
d49f9d4236
Коммит
827591eccc
|
@ -545,41 +545,8 @@ namespace Xamarin.Bundler {
|
||||||
if (!EnableCoopGC.HasValue)
|
if (!EnableCoopGC.HasValue)
|
||||||
EnableCoopGC = Platform == ApplePlatform.WatchOS;
|
EnableCoopGC = Platform == ApplePlatform.WatchOS;
|
||||||
|
|
||||||
if (EnableCoopGC.Value) {
|
SetObjectiveCExceptionMode ();
|
||||||
switch (MarshalObjectiveCExceptions) {
|
SetManagedExceptionMode ();
|
||||||
case MarshalObjectiveCExceptionMode.UnwindManagedCode:
|
|
||||||
case MarshalObjectiveCExceptionMode.Disable:
|
|
||||||
throw ErrorHelper.CreateError (89, Errors.MT0089, "--marshal-objectivec-exceptions", MarshalObjectiveCExceptions.ToString ().ToLowerInvariant ());
|
|
||||||
}
|
|
||||||
switch (MarshalManagedExceptions) {
|
|
||||||
case MarshalManagedExceptionMode.UnwindNativeCode:
|
|
||||||
case MarshalManagedExceptionMode.Disable:
|
|
||||||
throw ErrorHelper.CreateError (89, Errors.MT0089, "--marshal-managed-exceptions", MarshalManagedExceptions.ToString ().ToLowerInvariant ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool isSimulatorOrDesktopDebug = EnableDebug;
|
|
||||||
#if MTOUCH
|
|
||||||
isSimulatorOrDesktopDebug &= IsSimulatorBuild;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (MarshalObjectiveCExceptions == MarshalObjectiveCExceptionMode.Default) {
|
|
||||||
if (EnableCoopGC.Value || (Platform == ApplePlatform.MacOSX && EnableDebug)) {
|
|
||||||
MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.ThrowManagedException;
|
|
||||||
} else {
|
|
||||||
MarshalObjectiveCExceptions = isSimulatorOrDesktopDebug ? MarshalObjectiveCExceptionMode.UnwindManagedCode : MarshalObjectiveCExceptionMode.Disable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MarshalManagedExceptions == MarshalManagedExceptionMode.Default) {
|
|
||||||
if (EnableCoopGC.Value) {
|
|
||||||
MarshalManagedExceptions = MarshalManagedExceptionMode.ThrowObjectiveCException;
|
|
||||||
} else {
|
|
||||||
MarshalManagedExceptions = isSimulatorOrDesktopDebug ? MarshalManagedExceptionMode.UnwindNativeCode : MarshalManagedExceptionMode.Disable;
|
|
||||||
}
|
|
||||||
IsDefaultMarshalManagedExceptionMode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SymbolMode == SymbolMode.Default) {
|
if (SymbolMode == SymbolMode.Default) {
|
||||||
#if MONOTOUCH
|
#if MONOTOUCH
|
||||||
|
@ -974,5 +941,120 @@ namespace Xamarin.Bundler {
|
||||||
|
|
||||||
return fw.IsFrameworkAvailableInSimulator (this);
|
return fw.IsFrameworkAvailableInSimulator (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool TryParseManagedExceptionMode (string value, out MarshalManagedExceptionMode mode)
|
||||||
|
{
|
||||||
|
mode = MarshalManagedExceptionMode.Default;
|
||||||
|
|
||||||
|
switch (value) {
|
||||||
|
case "default":
|
||||||
|
mode = MarshalManagedExceptionMode.Default;
|
||||||
|
break;
|
||||||
|
case "unwindnative":
|
||||||
|
case "unwindnativecode":
|
||||||
|
mode = MarshalManagedExceptionMode.UnwindNativeCode;
|
||||||
|
break;
|
||||||
|
case "throwobjectivec":
|
||||||
|
case "throwobjectivecexception":
|
||||||
|
mode = MarshalManagedExceptionMode.ThrowObjectiveCException;
|
||||||
|
break;
|
||||||
|
case "abort":
|
||||||
|
mode = MarshalManagedExceptionMode.Abort;
|
||||||
|
break;
|
||||||
|
case "disable":
|
||||||
|
mode = MarshalManagedExceptionMode.Disable;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryParseObjectiveCExceptionMode (string value, out MarshalObjectiveCExceptionMode mode)
|
||||||
|
{
|
||||||
|
mode = MarshalObjectiveCExceptionMode.Default;
|
||||||
|
switch (value) {
|
||||||
|
case "default":
|
||||||
|
mode = MarshalObjectiveCExceptionMode.Default;
|
||||||
|
break;
|
||||||
|
case "unwindmanaged":
|
||||||
|
case "unwindmanagedcode":
|
||||||
|
mode = MarshalObjectiveCExceptionMode.UnwindManagedCode;
|
||||||
|
break;
|
||||||
|
case "throwmanaged":
|
||||||
|
case "throwmanagedexception":
|
||||||
|
mode = MarshalObjectiveCExceptionMode.ThrowManagedException;
|
||||||
|
break;
|
||||||
|
case "abort":
|
||||||
|
mode = MarshalObjectiveCExceptionMode.Abort;
|
||||||
|
break;
|
||||||
|
case "disable":
|
||||||
|
mode = MarshalObjectiveCExceptionMode.Disable;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetManagedExceptionMode ()
|
||||||
|
{
|
||||||
|
switch (MarshalManagedExceptions) {
|
||||||
|
case MarshalManagedExceptionMode.Default:
|
||||||
|
if (EnableCoopGC.Value) {
|
||||||
|
MarshalManagedExceptions = MarshalManagedExceptionMode.ThrowObjectiveCException;
|
||||||
|
} else {
|
||||||
|
switch (Platform) {
|
||||||
|
case ApplePlatform.iOS:
|
||||||
|
case ApplePlatform.TVOS:
|
||||||
|
case ApplePlatform.WatchOS:
|
||||||
|
MarshalManagedExceptions = EnableDebug && IsSimulatorBuild ? MarshalManagedExceptionMode.UnwindNativeCode : MarshalManagedExceptionMode.Disable;
|
||||||
|
break;
|
||||||
|
case ApplePlatform.MacOSX:
|
||||||
|
MarshalManagedExceptions = EnableDebug ? MarshalManagedExceptionMode.UnwindNativeCode : MarshalManagedExceptionMode.Disable;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw ErrorHelper.CreateError (71, Errors.MX0071 /* Unknown platform: {0}. This usually indicates a bug in {1}; please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new with a test case. */, Platform, ProductName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IsDefaultMarshalManagedExceptionMode = true;
|
||||||
|
break;
|
||||||
|
case MarshalManagedExceptionMode.UnwindNativeCode:
|
||||||
|
case MarshalManagedExceptionMode.Disable:
|
||||||
|
if (EnableCoopGC.Value)
|
||||||
|
throw ErrorHelper.CreateError (89, Errors.MT0089, "--marshal-managed-exceptions", MarshalManagedExceptions.ToString ().ToLowerInvariant ());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetObjectiveCExceptionMode ()
|
||||||
|
{
|
||||||
|
switch (MarshalObjectiveCExceptions) {
|
||||||
|
case MarshalObjectiveCExceptionMode.Default:
|
||||||
|
if (EnableCoopGC.Value) {
|
||||||
|
MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.ThrowManagedException;
|
||||||
|
} else {
|
||||||
|
switch (Platform) {
|
||||||
|
case ApplePlatform.iOS:
|
||||||
|
case ApplePlatform.TVOS:
|
||||||
|
case ApplePlatform.WatchOS:
|
||||||
|
MarshalObjectiveCExceptions = EnableDebug && IsSimulatorBuild ? MarshalObjectiveCExceptionMode.UnwindManagedCode : MarshalObjectiveCExceptionMode.Disable;
|
||||||
|
break;
|
||||||
|
case ApplePlatform.MacOSX:
|
||||||
|
MarshalObjectiveCExceptions = EnableDebug ? MarshalObjectiveCExceptionMode.ThrowManagedException : MarshalObjectiveCExceptionMode.Disable;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw ErrorHelper.CreateError (71, Errors.MX0071 /* Unknown platform: {0}. This usually indicates a bug in {1}; please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new with a test case. */, Platform, ProductName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MarshalObjectiveCExceptionMode.UnwindManagedCode:
|
||||||
|
case MarshalObjectiveCExceptionMode.Disable:
|
||||||
|
if (EnableCoopGC.Value)
|
||||||
|
throw ErrorHelper.CreateError (89, Errors.MT0089, "--marshal-objectivec-exceptions", MarshalObjectiveCExceptions.ToString ().ToLowerInvariant ());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,48 +131,16 @@ namespace Xamarin.Bundler {
|
||||||
options.Add ("coop:", "If the GC should run in cooperative mode.", v => { app.EnableCoopGC = ParseBool (v, "coop"); }, hidden: true);
|
options.Add ("coop:", "If the GC should run in cooperative mode.", v => { app.EnableCoopGC = ParseBool (v, "coop"); }, hidden: true);
|
||||||
options.Add ("sgen-conc", "Enable the *experimental* concurrent garbage collector.", v => { app.EnableSGenConc = true; });
|
options.Add ("sgen-conc", "Enable the *experimental* concurrent garbage collector.", v => { app.EnableSGenConc = true; });
|
||||||
options.Add ("marshal-objectivec-exceptions:", "Specify how Objective-C exceptions should be marshalled. Valid values: default, unwindmanagedcode, throwmanagedexception, abort and disable. The default depends on the target platform (on watchOS the default is 'throwmanagedexception', while on all other platforms it's 'disable').", v => {
|
options.Add ("marshal-objectivec-exceptions:", "Specify how Objective-C exceptions should be marshalled. Valid values: default, unwindmanagedcode, throwmanagedexception, abort and disable. The default depends on the target platform (on watchOS the default is 'throwmanagedexception', while on all other platforms it's 'disable').", v => {
|
||||||
switch (v) {
|
if (Application.TryParseObjectiveCExceptionMode (v, out var value)) {
|
||||||
case "default":
|
app.MarshalObjectiveCExceptions = value;
|
||||||
app.MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.Default;
|
} else {
|
||||||
break;
|
|
||||||
case "unwindmanaged":
|
|
||||||
case "unwindmanagedcode":
|
|
||||||
app.MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.UnwindManagedCode;
|
|
||||||
break;
|
|
||||||
case "throwmanaged":
|
|
||||||
case "throwmanagedexception":
|
|
||||||
app.MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.ThrowManagedException;
|
|
||||||
break;
|
|
||||||
case "abort":
|
|
||||||
app.MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.Abort;
|
|
||||||
break;
|
|
||||||
case "disable":
|
|
||||||
app.MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.Disable;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw ErrorHelper.CreateError (26, Errors.MX0026, "--marshal-objective-exceptions", $"Invalid value: {v}. Valid values are: default, unwindmanagedcode, throwmanagedexception, abort and disable.");
|
throw ErrorHelper.CreateError (26, Errors.MX0026, "--marshal-objective-exceptions", $"Invalid value: {v}. Valid values are: default, unwindmanagedcode, throwmanagedexception, abort and disable.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
options.Add ("marshal-managed-exceptions:", "Specify how managed exceptions should be marshalled. Valid values: default, unwindnativecode, throwobjectivecexception, abort and disable. The default depends on the target platform (on watchOS the default is 'throwobjectivecexception', while on all other platform it's 'disable').", v => {
|
options.Add ("marshal-managed-exceptions:", "Specify how managed exceptions should be marshalled. Valid values: default, unwindnativecode, throwobjectivecexception, abort and disable. The default depends on the target platform (on watchOS the default is 'throwobjectivecexception', while on all other platform it's 'disable').", v => {
|
||||||
switch (v) {
|
if (Application.TryParseManagedExceptionMode (v, out var value)) {
|
||||||
case "default":
|
app.MarshalManagedExceptions = value;
|
||||||
app.MarshalManagedExceptions = MarshalManagedExceptionMode.Default;
|
} else {
|
||||||
break;
|
|
||||||
case "unwindnative":
|
|
||||||
case "unwindnativecode":
|
|
||||||
app.MarshalManagedExceptions = MarshalManagedExceptionMode.UnwindNativeCode;
|
|
||||||
break;
|
|
||||||
case "throwobjectivec":
|
|
||||||
case "throwobjectivecexception":
|
|
||||||
app.MarshalManagedExceptions = MarshalManagedExceptionMode.ThrowObjectiveCException;
|
|
||||||
break;
|
|
||||||
case "abort":
|
|
||||||
app.MarshalManagedExceptions = MarshalManagedExceptionMode.Abort;
|
|
||||||
break;
|
|
||||||
case "disable":
|
|
||||||
app.MarshalManagedExceptions = MarshalManagedExceptionMode.Disable;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw ErrorHelper.CreateError (26, Errors.MX0026, "--marshal-managed-exceptions", $"Invalid value: {v}. Valid values are: default, unwindnativecode, throwobjectivecexception, abort and disable.");
|
throw ErrorHelper.CreateError (26, Errors.MX0026, "--marshal-managed-exceptions", $"Invalid value: {v}. Valid values are: default, unwindnativecode, throwobjectivecexception, abort and disable.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче