Skip to content

Commit

Permalink
[mtouch] Show MT0091 as a warning if we're using the dynamic registrar.
Browse files Browse the repository at this point in the history
Even if using an Xcode older than the bindings we're shipping, everything
might just happen to work when using the dynamic registrar, so downgrade the
MT0091 error to a warning in that case (and cross fingers, because things
might still break).

Hopefully this makes it easier when using older Xcodes, because the typical
scenario of Sim+DontLink and Dev+LinkSdk/LinkAll will now just work (if the
app developer also crosses fingers piously and sacrifies the appropriate
amount of pizza to the proper deity).

Reference: https://trello.com/c/wP3Pcb1q/692-targeting-older-xcodes-without-enabling-managed-linking
  • Loading branch information
rolfbjarne committed Aug 17, 2017
1 parent 693269b commit 6f9a5c4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
9 changes: 8 additions & 1 deletion docs/website/mtouch-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,14 @@ earlier iOS version.

<h3><a name="MT0117"/>MT0117: Can't launch a 32-bit app on a simulator that only supports 64-bit.</h3>

<!-- 0116 - 0124: free to use -->
<h3><a name="MT0118"/>MT0118: Skipped linking with the framework '{framework}' (referenced by a module reference in {module_reference}) because it was introduced in {platform} {platform_version} (and currently building with the {platform} SDK {sdk_version}).</h3>

A framework reference was detected to a framework that isn't included in the
SDK currently being used to build.

This is usually fixed by using the latest available version of Xcode.

<!-- 0119 - 0124: free to use -->

<h3><a name="MT0125"/>MT0125: The --assembly-build-target command-line argument is ignored in the simulator.</h3>

Expand Down
3 changes: 3 additions & 0 deletions tests/common/ExecutionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ public void AssertError (string prefix, int number, string message, string filen
Assert.Fail (string.Format ("The error '{0}{1:0000}: {2}' was not found in the output:\n{3}", prefix, number, message, string.Join ("\n", details.ToArray ())));
}

if (!matches.Where ((msg) => msg.IsError).Any ())
Assert.Fail (string.Format ("Found the message '{0}{1:0000}: {2}' as expected, but it's a warning, not an error.", prefix, number, message));

if (filename != null) {
var hasDirectory = filename.IndexOf (Path.DirectorySeparatorChar) > -1;
if (!matches.Any ((v) => {
Expand Down
10 changes: 9 additions & 1 deletion tests/mtouch/MTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,18 @@ public void MT0091 (Profile profile, string name)
mtouch.SdkRoot = old_xcode;
mtouch.Linker = MTouchLinker.DontLink;
mtouch.Sdk = sdk_version;
Assert.AreEqual (1, mtouch.Execute (MTouchAction.BuildSim));
mtouch.AssertExecute (MTouchAction.BuildSim, "build sim dynamic");
var xcodeVersionString = Configuration.XcodeVersion;
if (xcodeVersionString.EndsWith (".0", StringComparison.Ordinal))
xcodeVersionString = xcodeVersionString.Substring (0, xcodeVersionString.Length - 2);
mtouch.AssertWarning (91, String.Format ("This version of Xamarin.iOS requires the {0} {1} SDK (shipped with Xcode {2}). Either upgrade Xcode to get the required header files or set the managed linker behaviour to Link Framework SDKs Only (to try to avoid the new APIs).", name, GetSdkVersion (profile), xcodeVersionString));

mtouch.Registrar = MTouchRegistrar.Static;
mtouch.AssertExecuteFailure (MTouchAction.BuildSim, "build sim static");
mtouch.AssertError (91, String.Format ("This version of Xamarin.iOS requires the {0} {1} SDK (shipped with Xcode {2}). Either upgrade Xcode to get the required header files or set the managed linker behaviour to Link Framework SDKs Only (to try to avoid the new APIs).", name, GetSdkVersion (profile), xcodeVersionString));

mtouch.Registrar = MTouchRegistrar.Unspecified;
mtouch.AssertExecuteFailure (MTouchAction.BuildDev, "build dev");
mtouch.AssertError (91, String.Format ("This version of Xamarin.iOS requires the {0} {1} SDK (shipped with Xcode {2}). Either upgrade Xcode to get the required header files or set the managed linker behaviour to Link Framework SDKs Only (to try to avoid the new APIs).", name, GetSdkVersion (profile), xcodeVersionString));
}
}
Expand Down
5 changes: 4 additions & 1 deletion tools/common/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,10 @@ public void ComputeLinkerFlags ()
// detect frameworks
int f = name.IndexOf (".framework/", StringComparison.Ordinal);
if (f > 0) {
if (Frameworks.Add (file))
if (Driver.GetFrameworks (App).TryGetValue (file, out var fw) && fw.Version > App.SdkVersion)
ErrorHelper.Warning (118, "Skipped linking with the framework '{0}' (referenced by a module reference in {1}) because it was introduced in {2} {3} (and currently building with the {2} SDK {4}).",
file, FileName, App.PlatformName, fw.Version, App.SdkVersion);
else if (Frameworks.Add (file))
Driver.Log (3, "Linking with the framework {0} because it's referenced by a module reference in {1}", file, FileName);
} else {
if (UnresolvedModuleReferences == null)
Expand Down
30 changes: 18 additions & 12 deletions tools/mtouch/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,8 +1334,24 @@ void Initialize ()
if (EnableBitCode && IsSimulatorBuild)
throw ErrorHelper.CreateError (84, "Bitcode is not supported in the simulator. Do not pass --bitcode when building for the simulator.");

if (LinkMode == LinkMode.None && SdkVersion < SdkVersions.GetVersion (Platform))
throw ErrorHelper.CreateError (91, "This version of Xamarin.iOS requires the {0} {1} SDK (shipped with Xcode {2}). Either upgrade Xcode to get the required header files or set the managed linker behaviour to Link Framework SDKs Only (to try to avoid the new APIs).", PlatformName, SdkVersions.GetVersion (Platform), SdkVersions.Xcode);
// If the default values are changed, remember to update CanWeSymlinkTheApplication
// and main.m (default value for xamarin_use_old_dynamic_registrar must match).
if (Registrar == RegistrarMode.Default) {
if (IsDeviceBuild) {
Registrar = RegistrarMode.Static;
} else { /* if (app.IsSimulatorBuild) */
Registrar = RegistrarMode.Dynamic;
}
}

if (LinkMode == LinkMode.None && SdkVersion < SdkVersions.GetVersion (Platform)) {
var msg = string.Format ("This version of Xamarin.iOS requires the {0} {1} SDK (shipped with Xcode {2}). Either upgrade Xcode to get the required header files or set the managed linker behaviour to Link Framework SDKs Only (to try to avoid the new APIs).", PlatformName, SdkVersions.GetVersion (Platform), SdkVersions.Xcode);
if (Registrar == RegistrarMode.Dynamic) {
ErrorHelper.Warning (91, msg);
} else {
throw ErrorHelper.CreateError (91, msg);
}
}

Namespaces.Initialize ();

Expand All @@ -1358,16 +1374,6 @@ void Initialize ()

void SelectRegistrar ()
{
// If the default values are changed, remember to update CanWeSymlinkTheApplication
// and main.m (default value for xamarin_use_old_dynamic_registrar must match).
if (Registrar == RegistrarMode.Default) {
if (IsDeviceBuild) {
Registrar = RegistrarMode.Static;
} else { /* if (app.IsSimulatorBuild) */
Registrar = RegistrarMode.Dynamic;
}
}

foreach (var target in Targets)
target.SelectStaticRegistrar ();
}
Expand Down

0 comments on commit 6f9a5c4

Please sign in to comment.