Skip to content

Commit

Permalink
[tools] OS Versions are messy in Mac Catalyst 😡
Browse files Browse the repository at this point in the history
In some places we have to provide the macOS version, and in other places the
iOS version. Add a map and the corresponding code to convert between the two,
and use them when needed.
  • Loading branch information
rolfbjarne committed Dec 3, 2020
1 parent 3780b40 commit 42687be
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 9 deletions.
24 changes: 24 additions & 0 deletions Versions-ios.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@
<string>7.0</string>
<string>7.1</string>
</array>
<key>MacCatalyst</key>
<array>
<string>13.1</string>
<string>13.2</string>
<string>13.3</string>
<string>13.4</string>
<string>13.5</string>
<string>14.2</string>
</array>
</dict>
<key>MacCatalystVersionMap</key>
<dict>
<key>13.1</key>
<string>10.15</string>
<key>13.2</key>
<string>10.15.1</string>
<key>13.3</key>
<string>10.15.2</string>
<key>13.4</key>
<string>10.15.4</string>
<key>13.5</key>
<string>10.15.5</string>
<key>14.2</key>
<string>11.0</string>
</dict>
<key>RecommendedXcodeVersion</key>
<string>@XCODE_VERSION@</string>
Expand Down
4 changes: 2 additions & 2 deletions builds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ $(MAC_DESTDIR)/$(MAC_FRAMEWORK_CURRENT_DIR)/Version: $(TOP)/Make.config.inc
$(Q) echo $(MAC_PACKAGE_VERSION) > $@

$(MAC_DESTDIR)/$(MAC_FRAMEWORK_CURRENT_DIR)/Versions.plist: $(TOP)/Versions-mac.plist.in Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/versions-check.csharp .stamp-$(MONO_BUILD_MODE)
$(Q) $(TOP)/versions-check.csharp $< "$(MIN_IOS_SDK_VERSION)" "$(MAX_IOS_DEPLOYMENT_TARGET)" "$(MIN_TVOS_SDK_VERSION)" "$(MAX_TVOS_DEPLOYMENT_TARGET)" "$(MIN_WATCH_OS_VERSION)" "$(MAX_WATCH_DEPLOYMENT_TARGET)" "$(MIN_OSX_SDK_VERSION)" "$(OSX_SDK_VERSION)"
$(Q) $(TOP)/versions-check.csharp $< "$(MIN_IOS_SDK_VERSION)" "$(MAX_IOS_DEPLOYMENT_TARGET)" "$(MIN_TVOS_SDK_VERSION)" "$(MAX_TVOS_DEPLOYMENT_TARGET)" "$(MIN_WATCH_OS_VERSION)" "$(MAX_WATCH_DEPLOYMENT_TARGET)" "$(MIN_OSX_SDK_VERSION)" "$(OSX_SDK_VERSION)" "$(MIN_MACCATALYST_SDK_VERSION)" "$(MACCATALYST_SDK_VERSION)"
$(Q_GEN) sed -e 's/@XCODE_VERSION@/$(XCODE_VERSION)/g' -e "s/@MONO_VERSION@/$(shell cat $(MONO_MAC_SDK_DESTDIR)/mac-mono-version.txt)/g" -e "s/@MIN_XM_MONO_VERSION@/$(MIN_XM_MONO_VERSION)/g" $< > $@

$(DOTNET_DESTDIR)/$(MACOS_NUGET).Sdk/Versions.plist: $(MAC_DESTDIR)/$(MAC_FRAMEWORK_CURRENT_DIR)/Versions.plist | $(DOTNET_DESTDIR)/$(MACOS_NUGET).Sdk
Expand Down Expand Up @@ -807,7 +807,7 @@ $(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)/updateinfo: $(TOP)/Make.config.inc
$(Q) echo "4569c276-1397-4adb-9485-82a7696df22e $(IOS_PACKAGE_UPDATE_ID)" > $@

$(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)/Versions.plist: $(TOP)/Versions-ios.plist.in Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/versions-check.csharp .stamp-$(MONO_BUILD_MODE)
$(Q) $(TOP)/versions-check.csharp $< "$(MIN_IOS_SDK_VERSION)" "$(MAX_IOS_DEPLOYMENT_TARGET)" "$(MIN_TVOS_SDK_VERSION)" "$(MAX_TVOS_DEPLOYMENT_TARGET)" "$(MIN_WATCH_OS_VERSION)" "$(MAX_WATCH_DEPLOYMENT_TARGET)" "$(MIN_OSX_SDK_VERSION)" "$(OSX_SDK_VERSION)"
$(Q) $(TOP)/versions-check.csharp $< "$(MIN_IOS_SDK_VERSION)" "$(MAX_IOS_DEPLOYMENT_TARGET)" "$(MIN_TVOS_SDK_VERSION)" "$(MAX_TVOS_DEPLOYMENT_TARGET)" "$(MIN_WATCH_OS_VERSION)" "$(MAX_WATCH_DEPLOYMENT_TARGET)" "$(MIN_OSX_SDK_VERSION)" "$(OSX_SDK_VERSION)" "$(MIN_MACCATALYST_SDK_VERSION)" "$(MACCATALYST_SDK_VERSION)"
$(Q_GEN) sed -e 's/@XCODE_VERSION@/$(XCODE_VERSION)/g' -e "s/@MONO_VERSION@/$(shell cat $(MONO_IOS_SDK_DESTDIR)/ios-mono-version.txt)/g" $< > $@

$(DOTNET_DESTDIR)/%.Sdk/Versions.plist: $(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)/Versions.plist | $(DOTNET_DESTDIR)/%.Sdk
Expand Down
45 changes: 45 additions & 0 deletions tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,51 @@ public bool Is32Build {
}
}

// Versions for Mac Catalyst are complicated. In some cases we have to use the
// corresponding iOS version of the SDK, and in some cases we have to use the
// macOS version that iOS version correspond to. In Xcode, when you select the
// deployment target, you select a macOS version in the UI, but the corresponding
// iOS version is written to the project file. This means that there's a mapping
// between the two, and we've captured that mapping in our Versions.plist for
// Xamarin.iOS (in the MacCatalystVersionMap plist dictionary). Here we provide
// two methods that can convert between iOS version and macOS version either way.
Dictionary<Version, Version> mac_catalyst_ios_to_macos_map;
Dictionary<Version, Version> GetCatalystiOSTomacOSMap ()
{
if (mac_catalyst_ios_to_macos_map == null) {
var file = Path.Combine (Driver.GetFrameworkCurrentDirectory (this), "Versions.plist");
var plist = Driver.FromPList (file);
var dict = plist.Get<PDictionary> ("MacCatalystVersionMap");

mac_catalyst_ios_to_macos_map = new Dictionary<Version, Version> ();
foreach (var kvp in dict) {
// The input here is fixed, so don't try to parse, just do it, because it should succeed.
mac_catalyst_ios_to_macos_map [Version.Parse (kvp.Key)] = Version.Parse (((PString) kvp.Value).Value);
}
}
return mac_catalyst_ios_to_macos_map;
}

public Version GetMacCatalystmacOSVersion (Version iOSVersion)
{
var map = GetCatalystiOSTomacOSMap ();

if (!map.TryGetValue (iOSVersion, out var value))
throw ErrorHelper.CreateError (183, Errors.MX0183 /* Could not map the iOS version {0} to a macOS version for Mac Catalyst */, iOSVersion.ToString ());

return value;
}

public Version GetMacCatalystiOSVersion (Version macVersion)
{
var map = GetCatalystiOSTomacOSMap ();
var iosVersions = map.Where (kvp => kvp.Value == macVersion).Select (v => v.Key).ToArray ();
if (iosVersions.Length != 1)
throw ErrorHelper.CreateError (184, Errors.MX0184 /* Could not map the Mac Catalyst version {0} to an iOS version */, macVersion.ToString ());

return iosVersions [0];
}

public string GetProductName ()
{
return ProductName;
Expand Down
7 changes: 6 additions & 1 deletion tools/common/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,12 @@ public static string GetPlatform (Application app)
public static string GetFrameworkDirectory (Application app)
{
var platform = GetPlatform (app);
return Path.Combine (PlatformsDirectory, platform + ".platform", "Developer", "SDKs", platform + app.SdkVersion.ToString () + ".sdk");
switch (app.Platform) {
case ApplePlatform.MacCatalyst:
return Path.Combine (PlatformsDirectory, platform + ".platform", "Developer", "SDKs", platform + app.GetMacCatalystmacOSVersion (app.SdkVersion).ToString () + ".sdk");
default:
return Path.Combine (PlatformsDirectory, platform + ".platform", "Developer", "SDKs", platform + app.SdkVersion.ToString () + ".sdk");
}
}

public static string GetProductAssembly (Application app)
Expand Down
2 changes: 2 additions & 0 deletions tools/common/Make.common
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
../common/SdkVersions.cs: ../common/SdkVersions.cs.in Makefile $(TOP)/Make.config
$(Q_GEN) sed \
-e 's/@IOS_SDK_VERSION@/$(IOS_SDK_VERSION)/g' -e 's/@WATCHOS_SDK_VERSION@/$(WATCH_SDK_VERSION)/' -e 's/@TVOS_SDK_VERSION@/$(TVOS_SDK_VERSION)/' -e 's/@OSX_SDK_VERSION@/$(OSX_SDK_VERSION)/' \
-e 's/@MACCATALYST_SDK_VERSION@/$(MACCATALYST_SDK_VERSION)/g' \
-e 's/@MIN_IOS_SDK_VERSION@/$(MIN_IOS_SDK_VERSION)/g' -e 's/@MIN_WATCHOS_SDK_VERSION@/$(MIN_WATCHOS_SDK_VERSION)/' -e 's/@MIN_TVOS_SDK_VERSION@/$(MIN_TVOS_SDK_VERSION)/' -e 's/@MIN_OSX_SDK_VERSION@/$(MIN_OSX_SDK_VERSION)/' \
-e 's/@MIN_MACCATALYST_SDK_VERSION@/$(MIN_MACCATALYST_SDK_VERSION)/g' \
-e 's/@XCODE_VERSION@/$(XCODE_VERSION)/g' \
-e 's/@MIN_XM_MONO_VERSION@/$(MIN_XM_MONO_VERSION)/g' \
-e 's/@MIN_IOS_SIMULATOR_VERSION@/$(MIN_IOS_SIMULATOR_VERSION)/g' \
Expand Down
6 changes: 6 additions & 0 deletions tools/common/SdkVersions.cs.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ namespace Xamarin {
public const string iOS = "@IOS_SDK_VERSION@";
public const string WatchOS = "@WATCHOS_SDK_VERSION@";
public const string TVOS = "@TVOS_SDK_VERSION@";
public const string MacCatalyst = "@MACCATALYST_SDK_VERSION@";

public const string MinOSX = "@MIN_OSX_SDK_VERSION@";
public const string MiniOS = "@MIN_IOS_SDK_VERSION@";
public const string MinWatchOS = "@MIN_WATCHOS_SDK_VERSION@";
public const string MinTVOS = "@MIN_TVOS_SDK_VERSION@";
public const string MinMacCatalyst = "@MIN_MACCATALYST_SDK_VERSION@";

public const string MiniOSSimulator = "@MIN_IOS_SIMULATOR_VERSION@";
public const string MinWatchOSSimulator = "@MIN_WATCHOS_SIMULATOR_VERSION@";
Expand All @@ -40,6 +42,7 @@ namespace Xamarin {
public static Version iOSVersion { get { return new Version (iOS); }}
public static Version WatchOSVersion { get { return new Version (WatchOS); }}
public static Version TVOSVersion { get { return new Version (TVOS); }}
public static Version MacCatalystVersion { get { return new Version (MacCatalyst); }}

public static Version iOSTargetVersion { get { return new Version (MaxiOSDeploymentTarget); }}
public static Version WatchOSTargetVersion { get { return new Version (MaxWatchDeploymentTarget); }}
Expand All @@ -49,6 +52,7 @@ namespace Xamarin {
public static Version MiniOSVersion { get { return new Version (MiniOS); }}
public static Version MinWatchOSVersion { get { return new Version (MinWatchOS); }}
public static Version MinTVOSVersion { get { return new Version (MinTVOS); }}
public static Version MinMacCatalystVersion { get { return new Version (MinMacCatalyst); }}

public static Version MiniOSSimulatorVersion { get { return new Version (MiniOSSimulator); }}
public static Version MinWatchOSSimulatorVersion { get { return new Version (MinWatchOSSimulator); }}
Expand All @@ -70,6 +74,7 @@ namespace Xamarin {
case ApplePlatform.iOS: return iOSVersion;
case ApplePlatform.WatchOS: return WatchOSVersion;
case ApplePlatform.TVOS: return TVOSVersion;
case ApplePlatform.MacCatalyst: return MacCatalystVersion;
default:
throw ErrorHelper.CreateError (71, "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.", app.Platform, app.ProductName);
}
Expand All @@ -94,6 +99,7 @@ namespace Xamarin {
case ApplePlatform.iOS: return MiniOSVersion;
case ApplePlatform.WatchOS: return MinWatchOSVersion;
case ApplePlatform.TVOS: return MinTVOSVersion;
case ApplePlatform.MacCatalyst: return MinMacCatalystVersion;
default:
throw ErrorHelper.CreateError (71, "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.", app.Platform, app.ProductName);
}
Expand Down
7 changes: 7 additions & 0 deletions tools/mtouch/Application.mtouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,13 @@ void Initialize ()
DeploymentTarget = new Version (8, 0);
}

if (Platform == ApplePlatform.MacCatalyst) {
// The deployment target we expect for Mac Catalyst is the macOS version,
// but we're expected to provide the corresponding iOS version pretty much
// everywhere, so convert here.
DeploymentTarget = GetMacCatalystiOSVersion (DeploymentTarget);
}

if (!enable_msym.HasValue)
enable_msym = !EnableDebug && IsDeviceBuild;

Expand Down
12 changes: 12 additions & 0 deletions tools/mtouch/Errors.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tools/mtouch/Errors.resx
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,14 @@
<data name="MX0182" xml:space="preserve">
<value>Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</value>
</data>

<data name="MX0183" xml:space="preserve">
<value>Could not map the iOS version {0} to a macOS version for Mac Catalyst</value>
</data>

<data name="MX0184" xml:space="preserve">
<value>Could not map the Mac Catalyst version {0} to an iOS version</value>
</data>

<data name="MX1009" xml:space="preserve">
<value>Could not copy the assembly '{0}' to '{1}': {2}
Expand Down
10 changes: 10 additions & 0 deletions tools/mtouch/xlf/Errors.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,16 @@
<target state="new">Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</target>
<note />
</trans-unit>
<trans-unit id="MX0183">
<source>Could not map the iOS version {0} to a macOS version for Mac Catalyst</source>
<target state="new">Could not map the iOS version {0} to a macOS version for Mac Catalyst</target>
<note />
</trans-unit>
<trans-unit id="MX0184">
<source>Could not map the Mac Catalyst version {0} to an iOS version</source>
<target state="new">Could not map the Mac Catalyst version {0} to an iOS version</target>
<note />
</trans-unit>
<trans-unit id="MX1009">
<source>Could not copy the assembly '{0}' to '{1}': {2}
</source>
Expand Down
10 changes: 10 additions & 0 deletions tools/mtouch/xlf/Errors.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,16 @@
<target state="new">Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</target>
<note />
</trans-unit>
<trans-unit id="MX0183">
<source>Could not map the iOS version {0} to a macOS version for Mac Catalyst</source>
<target state="new">Could not map the iOS version {0} to a macOS version for Mac Catalyst</target>
<note />
</trans-unit>
<trans-unit id="MX0184">
<source>Could not map the Mac Catalyst version {0} to an iOS version</source>
<target state="new">Could not map the Mac Catalyst version {0} to an iOS version</target>
<note />
</trans-unit>
<trans-unit id="MX1009">
<source>Could not copy the assembly '{0}' to '{1}': {2}
</source>
Expand Down
10 changes: 10 additions & 0 deletions tools/mtouch/xlf/Errors.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,16 @@
<target state="new">Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</target>
<note />
</trans-unit>
<trans-unit id="MX0183">
<source>Could not map the iOS version {0} to a macOS version for Mac Catalyst</source>
<target state="new">Could not map the iOS version {0} to a macOS version for Mac Catalyst</target>
<note />
</trans-unit>
<trans-unit id="MX0184">
<source>Could not map the Mac Catalyst version {0} to an iOS version</source>
<target state="new">Could not map the Mac Catalyst version {0} to an iOS version</target>
<note />
</trans-unit>
<trans-unit id="MX1009">
<source>Could not copy the assembly '{0}' to '{1}': {2}
</source>
Expand Down
10 changes: 10 additions & 0 deletions tools/mtouch/xlf/Errors.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,16 @@
<target state="new">Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</target>
<note />
</trans-unit>
<trans-unit id="MX0183">
<source>Could not map the iOS version {0} to a macOS version for Mac Catalyst</source>
<target state="new">Could not map the iOS version {0} to a macOS version for Mac Catalyst</target>
<note />
</trans-unit>
<trans-unit id="MX0184">
<source>Could not map the Mac Catalyst version {0} to an iOS version</source>
<target state="new">Could not map the Mac Catalyst version {0} to an iOS version</target>
<note />
</trans-unit>
<trans-unit id="MX1009">
<source>Could not copy the assembly '{0}' to '{1}': {2}
</source>
Expand Down
10 changes: 10 additions & 0 deletions tools/mtouch/xlf/Errors.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,16 @@
<target state="new">Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</target>
<note />
</trans-unit>
<trans-unit id="MX0183">
<source>Could not map the iOS version {0} to a macOS version for Mac Catalyst</source>
<target state="new">Could not map the iOS version {0} to a macOS version for Mac Catalyst</target>
<note />
</trans-unit>
<trans-unit id="MX0184">
<source>Could not map the Mac Catalyst version {0} to an iOS version</source>
<target state="new">Could not map the Mac Catalyst version {0} to an iOS version</target>
<note />
</trans-unit>
<trans-unit id="MX1009">
<source>Could not copy the assembly '{0}' to '{1}': {2}
</source>
Expand Down
10 changes: 10 additions & 0 deletions tools/mtouch/xlf/Errors.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,16 @@
<target state="new">Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</target>
<note />
</trans-unit>
<trans-unit id="MX0183">
<source>Could not map the iOS version {0} to a macOS version for Mac Catalyst</source>
<target state="new">Could not map the iOS version {0} to a macOS version for Mac Catalyst</target>
<note />
</trans-unit>
<trans-unit id="MX0184">
<source>Could not map the Mac Catalyst version {0} to an iOS version</source>
<target state="new">Could not map the Mac Catalyst version {0} to an iOS version</target>
<note />
</trans-unit>
<trans-unit id="MX1009">
<source>Could not copy the assembly '{0}' to '{1}': {2}
</source>
Expand Down
10 changes: 10 additions & 0 deletions tools/mtouch/xlf/Errors.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,16 @@
<target state="new">Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</target>
<note />
</trans-unit>
<trans-unit id="MX0183">
<source>Could not map the iOS version {0} to a macOS version for Mac Catalyst</source>
<target state="new">Could not map the iOS version {0} to a macOS version for Mac Catalyst</target>
<note />
</trans-unit>
<trans-unit id="MX0184">
<source>Could not map the Mac Catalyst version {0} to an iOS version</source>
<target state="new">Could not map the Mac Catalyst version {0} to an iOS version</target>
<note />
</trans-unit>
<trans-unit id="MX1009">
<source>Could not copy the assembly '{0}' to '{1}': {2}
</source>
Expand Down
10 changes: 10 additions & 0 deletions tools/mtouch/xlf/Errors.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,16 @@
<target state="new">Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</target>
<note />
</trans-unit>
<trans-unit id="MX0183">
<source>Could not map the iOS version {0} to a macOS version for Mac Catalyst</source>
<target state="new">Could not map the iOS version {0} to a macOS version for Mac Catalyst</target>
<note />
</trans-unit>
<trans-unit id="MX0184">
<source>Could not map the Mac Catalyst version {0} to an iOS version</source>
<target state="new">Could not map the Mac Catalyst version {0} to an iOS version</target>
<note />
</trans-unit>
<trans-unit id="MX1009">
<source>Could not copy the assembly '{0}' to '{1}': {2}
</source>
Expand Down
10 changes: 10 additions & 0 deletions tools/mtouch/xlf/Errors.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,16 @@
<target state="new">Not linking with the framework {0} (referenced by a module reference in {1}) because it's not available on the current platform ({2}).</target>
<note />
</trans-unit>
<trans-unit id="MX0183">
<source>Could not map the iOS version {0} to a macOS version for Mac Catalyst</source>
<target state="new">Could not map the iOS version {0} to a macOS version for Mac Catalyst</target>
<note />
</trans-unit>
<trans-unit id="MX0184">
<source>Could not map the Mac Catalyst version {0} to an iOS version</source>
<target state="new">Could not map the Mac Catalyst version {0} to an iOS version</target>
<note />
</trans-unit>
<trans-unit id="MX1009">
<source>Could not copy the assembly '{0}' to '{1}': {2}
</source>
Expand Down
Loading

0 comments on commit 42687be

Please sign in to comment.