From d42a9f4909f6ca0c619b7385eda658e841c4edef Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 8 Nov 2016 17:13:53 +0100 Subject: [PATCH] [mtouch] Make MT2015 (invalid HttpMessageHandler) a warning for known http message handlers on watchOS. Fixes #46552. (#1134) Earlier versions of Xamarin Studio stored an invalid http message handler in watchOS project files, which would cause a build error. In addition Xamarin Studio removed the UI to set the http message handler (since only one value is valid), which meant that the user had to edit the project file by hand to get around this build error. So make it a warning instead (and document what the user has to do to fix the warning). https://bugzilla.xamarin.com/show_bug.cgi?id=46552 --- docs/website/mtouch-errors.md | 6 ++++++ src/ObjCRuntime/RuntimeOptions.cs | 26 +++++++++++++++------- tests/mtouch/MTouch.cs | 36 +++++++++++++++++++++++++++++++ tests/mtouch/MTouchTool.cs | 9 ++++++++ tools/mtouch/error.cs | 2 +- 5 files changed, 70 insertions(+), 9 deletions(-) diff --git a/docs/website/mtouch-errors.md b/docs/website/mtouch-errors.md index 70da40803b..ab6b9ce5bd 100644 --- a/docs/website/mtouch-errors.md +++ b/docs/website/mtouch-errors.md @@ -841,6 +841,12 @@ This generally indicates that there is a problem with your Xamarin.iOS installat

MT2015: Invalid HttpMessageHandler `*` for watchOS. The only valid value is NSUrlSessionHandler.

+This is a warning that occurs because the project file specifies an invalid HttpMessageHandler. + +Earlier versions of our preview tools generated by default an invalid value in the project file. + +To fix this warning, open the project file in a text editor, and remove all HttpMessageHandler nodes from the XML. +

MT202x: Binding Optimizer failed processing `...`.

Something unexpected occured when trying to optimize generated binding code. The element causing the issue is named in the error message. In order to fix this issue the assembly named (or containing the type or method named) will need to be provided in a [bug report](http://bugzilla.xamarin.com) along with a complete build log with verbosity enabled (i.e. `-v -v -v -v` in the **Additional mtouch arguments**). diff --git a/src/ObjCRuntime/RuntimeOptions.cs b/src/ObjCRuntime/RuntimeOptions.cs index ce351b3d7f..537bdc0d37 100644 --- a/src/ObjCRuntime/RuntimeOptions.cs +++ b/src/ObjCRuntime/RuntimeOptions.cs @@ -68,12 +68,16 @@ namespace XamCore.ObjCRuntime { return HttpClientHandlerValue; case CFNetworkHandlerValue: case HttpClientHandlerValue: - if (Driver.App.Platform == Utils.ApplePlatform.WatchOS) - throw ErrorHelper.CreateError (2015, "Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler.", value); + if (Driver.App.Platform == Utils.ApplePlatform.WatchOS) { + ErrorHelper.Warning (2015, "Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler.", value); + return NSUrlSessionHandlerValue; + } return value; case NSUrlSessionHandlerValue: return value; default: + if (Driver.App.Platform == Utils.ApplePlatform.WatchOS) // This is value we don't know about at all, show as error instead of warning. + throw ErrorHelper.CreateError (2015, "Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler.", value); throw ErrorHelper.CreateError (2010, "Unknown HttpMessageHandler `{0}`. Valid values are HttpClientHandler (default), CFNetworkHandler or NSUrlSessionHandler", value); } } @@ -185,14 +189,20 @@ namespace XamCore.ObjCRuntime { break; #else case HttpClientHandlerValue: - if (Driver.App.Platform == Utils.ApplePlatform.WatchOS) - throw ErrorHelper.CreateError (2015, "Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler.", handler); - type = httpModule.GetType ("System.Net.Http", "HttpClientHandler"); + if (Driver.App.Platform == Utils.ApplePlatform.WatchOS) { + ErrorHelper.Warning (2015, "Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler.", handler); + type = httpModule.GetType ("System.Net.Http", "NSUrlSessionHandler"); + } else { + type = httpModule.GetType ("System.Net.Http", "HttpClientHandler"); + } break; case CFNetworkHandlerValue: - if (Driver.App.Platform == Utils.ApplePlatform.WatchOS) - throw ErrorHelper.CreateError (2015, "Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler.", handler); - type = httpModule.GetType ("System.Net.Http", "CFNetworkHandler"); + if (Driver.App.Platform == Utils.ApplePlatform.WatchOS) { + ErrorHelper.Warning (2015, "Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler.", handler); + type = httpModule.GetType ("System.Net.Http", "NSUrlSessionHandler"); + } else { + type = httpModule.GetType ("System.Net.Http", "CFNetworkHandler"); + } break; case NSUrlSessionHandlerValue: type = httpModule.GetType ("System.Net.Http", "NSUrlSessionHandler"); diff --git a/tests/mtouch/MTouch.cs b/tests/mtouch/MTouch.cs index c749647162..33c810fb70 100644 --- a/tests/mtouch/MTouch.cs +++ b/tests/mtouch/MTouch.cs @@ -2146,6 +2146,42 @@ class C { } } + [TestCase (Profile.Unified)] + [TestCase (Profile.TVOS)] + public void MT2010 (Profile profile) + { + using (var mtouch = new MTouchTool ()) { + mtouch.Profile = profile; + mtouch.CreateTemporaryApp (); + + mtouch.HttpMessageHandler = "Dummy"; + Assert.AreEqual (1, mtouch.Execute (MTouchAction.BuildSim)); + mtouch.AssertError (2010, "Unknown HttpMessageHandler `Dummy`. Valid values are HttpClientHandler (default), CFNetworkHandler or NSUrlSessionHandler"); + } + } + + [Test] + public void MT2015 () + { + using (var mtouch = new MTouchTool ()) { + mtouch.Profile = Profile.WatchOS; + mtouch.CreateTemporaryWatchKitExtension (); + mtouch.Extension = true; + + mtouch.HttpMessageHandler = "HttpClientHandler"; + mtouch.AssertExecute (MTouchAction.BuildSim); + mtouch.AssertError (2015, "Invalid HttpMessageHandler `HttpClientHandler` for watchOS. The only valid value is NSUrlSessionHandler."); + + mtouch.HttpMessageHandler = "CFNetworkHandler"; + mtouch.AssertExecute (MTouchAction.BuildSim); + mtouch.AssertError (2015, "Invalid HttpMessageHandler `CFNetworkHandler` for watchOS. The only valid value is NSUrlSessionHandler."); + + mtouch.HttpMessageHandler = "Dummy"; + mtouch.AssertExecuteFailure (MTouchAction.BuildSim); + mtouch.AssertError (2015, "Invalid HttpMessageHandler `Dummy` for watchOS. The only valid value is NSUrlSessionHandler."); + } + } + #region Helper functions static string CompileUnifiedTestAppExecutable (string targetDirectory, string code = null, string extraArg = "") { diff --git a/tests/mtouch/MTouchTool.cs b/tests/mtouch/MTouchTool.cs index 8054896cea..f818357dc3 100644 --- a/tests/mtouch/MTouchTool.cs +++ b/tests/mtouch/MTouchTool.cs @@ -75,6 +75,7 @@ namespace Xamarin public bool? Extension; public List AppExtensions = new List (); public List Frameworks = new List (); + public string HttpMessageHandler; #pragma warning restore 649 // These are a bit smarter @@ -125,6 +126,11 @@ namespace Xamarin NUnit.Framework.Assert.AreEqual (0, Execute (action), message); } + public void AssertExecuteFailure (MTouchAction action, string message = null) + { + NUnit.Framework.Assert.AreEqual (1, Execute (action), message); + } + string BuildArguments (MTouchAction action) { var sb = new StringBuilder (); @@ -195,6 +201,9 @@ namespace Xamarin foreach (var framework in Frameworks) sb.Append (" --framework ").Append (MTouch.Quote (framework)); + if (!string.IsNullOrEmpty (HttpMessageHandler)) + sb.Append (" --http-message-handler=").Append (MTouch.Quote (HttpMessageHandler)); + if (Dlsym.HasValue) sb.Append (" --dlsym:").Append (Dlsym.Value ? "true" : "false"); diff --git a/tools/mtouch/error.cs b/tools/mtouch/error.cs index 9e41cff0d0..92fd452f8e 100644 --- a/tools/mtouch/error.cs +++ b/tools/mtouch/error.cs @@ -206,7 +206,7 @@ namespace Xamarin.Bundler { // MT2012 ** reserved Xamarin.Mac ** // MT2013 ** reserved Xamarin.Mac ** // MT2014 ** reserved Xamarin.Mac ** - // MT2015 Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler. + // Warning MT2015 Invalid HttpMessageHandler `{0}` for watchOS. The only valid value is NSUrlSessionHandler. // MT202x Binding Optimizer failed processing `...`. // MT203x Removing User Resources failed processing `...`. // MT3xxx AOT