[msbuild] Unify the DetectSdkLocations task logic between iOS and Mac. (#15256)

This was mostly a clean merge, with a few minor differences:

* We no longer compute whether we're running in the simulator or not when building for Mac Catalyst.
* The task now supports building remotely for macOS (due to code sharing).
  Will be useful if we ever support building macOS apps remotely.
* We now call AppleSdkSettings.Init () on macOS. No idea why we weren't
  before, but it seems logical for macOS to behave like our other platforms.

There shouldn't be any other functional differences.
This commit is contained in:
Rolf Bjarne Kvinge 2022-06-16 23:52:43 +02:00 коммит произвёл GitHub
Родитель 357adfde76
Коммит ab52bb2f45
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 62 добавлений и 73 удалений

Просмотреть файл

@ -1,19 +0,0 @@
using Xamarin.MacDev.Tasks;
using Xamarin.MacDev;
namespace Xamarin.Mac.Tasks
{
public abstract class DetectSdkLocationsTaskBase : DetectSdkLocationsCoreTaskBase
{
protected override IAppleSdkVersion GetDefaultSdkVersion ()
{
var v = CurrentSdk.GetInstalledSdkVersions (false);
return v.Count > 0 ? v [v.Count - 1] : AppleSdkVersion.UseDefault;
}
protected override string GetDefaultXamarinSdkRoot ()
{
return Sdks.XamMac.FrameworkDirectory;
}
}
}

Просмотреть файл

@ -1,7 +0,0 @@
namespace Xamarin.Mac.Tasks
{
public class DetectSdkLocations : DetectSdkLocationsTaskBase
{
}
}

Просмотреть файл

@ -73,8 +73,36 @@ namespace Xamarin.MacDev.Tasks {
} }
} }
protected abstract string GetDefaultXamarinSdkRoot (); string GetDefaultXamarinSdkRoot ()
protected abstract IAppleSdkVersion GetDefaultSdkVersion (); {
switch (Platform) {
case ApplePlatform.iOS:
case ApplePlatform.TVOS:
case ApplePlatform.WatchOS:
case ApplePlatform.MacCatalyst:
return Sdks.XamIOS.SdkDir;
case ApplePlatform.MacOSX:
return Sdks.XamMac.FrameworkDirectory;
default:
throw new InvalidOperationException (string.Format (MSBStrings.InvalidPlatform, Platform));
}
}
IAppleSdkVersion GetDefaultSdkVersion ()
{
switch (Platform) {
case ApplePlatform.iOS:
case ApplePlatform.TVOS:
case ApplePlatform.WatchOS:
case ApplePlatform.MacCatalyst:
return AppleSdkVersion.UseDefault;
case ApplePlatform.MacOSX:
var v = CurrentSdk.GetInstalledSdkVersions (false);
return v.Count > 0 ? v [v.Count - 1] : AppleSdkVersion.UseDefault;
default:
throw new InvalidOperationException (string.Format (MSBStrings.InvalidPlatform, Platform));
}
}
protected string GetEnvironmentVariableOverride () protected string GetEnvironmentVariableOverride ()
{ {
@ -147,6 +175,10 @@ namespace Xamarin.MacDev.Tasks {
public override bool Execute () public override bool Execute ()
{ {
AppleSdkSettings.Init ();
SetIsSimulator ();
// If XamarinSdkRoot is set, then make that override any other value, and in order to do so, // If XamarinSdkRoot is set, then make that override any other value, and in order to do so,
// set the corresponding environment variable accordingly. // set the corresponding environment variable accordingly.
if (!string.IsNullOrEmpty (XamarinSdkRoot)) if (!string.IsNullOrEmpty (XamarinSdkRoot))
@ -159,6 +191,25 @@ namespace Xamarin.MacDev.Tasks {
return !Log.HasLoggedErrors; return !Log.HasLoggedErrors;
} }
void SetIsSimulator ()
{
switch (Platform) {
case ApplePlatform.MacCatalyst:
case ApplePlatform.MacOSX:
return;
}
TargetArchitecture architectures;
if (string.IsNullOrEmpty (TargetArchitectures) || !Enum.TryParse (TargetArchitectures, out architectures))
architectures = TargetArchitecture.Default;
if (!string.IsNullOrEmpty (IsDotNetSimulatorBuild)) {
SdkIsSimulator = string.Equals (IsDotNetSimulatorBuild, "true", StringComparison.OrdinalIgnoreCase);
} else {
SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0;
}
}
protected bool EnsureAppleSdkRoot () protected bool EnsureAppleSdkRoot ()
{ {
var currentSdk = CurrentSdk; var currentSdk = CurrentSdk;

Просмотреть файл

@ -1,16 +1,16 @@
using System; using System;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Xamarin.Messaging.Build.Client; using Xamarin.Messaging.Build.Client;
namespace Xamarin.iOS.Tasks namespace Xamarin.MacDev.Tasks {
{ public class DetectSdkLocations : DetectSdkLocationsCoreTaskBase, ICancelableTask {
public class DetectSdkLocations : DetectSdkLocationsTaskBase, ICancelableTask
{
const string SdkVersionDefaultValue = "default"; const string SdkVersionDefaultValue = "default";
public override bool Execute () public override bool Execute ()
{ {
if (!ShouldExecuteRemotely()) if (!ShouldExecuteRemotely ())
return base.Execute (); return base.Execute ();
// The new targets do not support the "default" value for the MtouchSdkVersion // The new targets do not support the "default" value for the MtouchSdkVersion

Просмотреть файл

@ -41,7 +41,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CompileITunesMetadata" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CompileITunesMetadata" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CreateAssetPack" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CreateAssetPack" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CreateEmbeddedResources" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CreateEmbeddedResources" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.DetectSdkLocations" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.DetectSigningIdentity" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.DetectSigningIdentity" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.FindWatchOS2AppBundle" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.FindWatchOS2AppBundle" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.GetMlaunchArguments" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.GetMlaunchArguments" AssemblyFile="$(_TaskAssemblyName)" />
@ -57,7 +56,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<!-- Xamarin.Mac-specific tasks. Some of these are duplicated with the Xamarin.iOS ones above, and should eventually be re-namespaced to be in Xamarin.MacDev --> <!-- Xamarin.Mac-specific tasks. Some of these are duplicated with the Xamarin.iOS ones above, and should eventually be re-namespaced to be in Xamarin.MacDev -->
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.CompileAppManifest" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.CompileAppManifest" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.CreateEmbeddedResources" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.CreateEmbeddedResources" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.DetectSdkLocations" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.DetectSigningIdentity" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.DetectSigningIdentity" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.Mmp" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.Mmp" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.PrepareNativeReferences" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.PrepareNativeReferences" AssemblyFile="$(_TaskAssemblyName)" />
@ -88,6 +86,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask TaskName="Xamarin.MacDev.Tasks.CompileProductDefinition" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask TaskName="Xamarin.MacDev.Tasks.CompileProductDefinition" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.ComputeCodesignItems" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask TaskName="Xamarin.MacDev.Tasks.ComputeCodesignItems" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.DetectDebugNetworkConfiguration" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask TaskName="Xamarin.MacDev.Tasks.DetectDebugNetworkConfiguration" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.DetectSdkLocations" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.Ditto" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask TaskName="Xamarin.MacDev.Tasks.Ditto" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.DSymUtil" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask TaskName="Xamarin.MacDev.Tasks.DSymUtil" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.EmbedProvisionProfile" AssemblyFile="$(_TaskAssemblyName)" /> <UsingTask TaskName="Xamarin.MacDev.Tasks.EmbedProvisionProfile" AssemblyFile="$(_TaskAssemblyName)" />

Просмотреть файл

@ -1,37 +0,0 @@
using System;
using Xamarin.MacDev.Tasks;
using Xamarin.MacDev;
namespace Xamarin.iOS.Tasks
{
public abstract class DetectSdkLocationsTaskBase : DetectSdkLocationsCoreTaskBase
{
protected override IAppleSdkVersion GetDefaultSdkVersion ()
{
return AppleSdkVersion.UseDefault;
}
public override bool Execute ()
{
AppleSdkSettings.Init ();
TargetArchitecture architectures;
if (string.IsNullOrEmpty (TargetArchitectures) || !Enum.TryParse (TargetArchitectures, out architectures))
architectures = TargetArchitecture.Default;
if (!string.IsNullOrEmpty (IsDotNetSimulatorBuild)) {
SdkIsSimulator = string.Equals (IsDotNetSimulatorBuild, "true", StringComparison.OrdinalIgnoreCase);
} else {
SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0;
}
return base.Execute ();
}
protected override string GetDefaultXamarinSdkRoot ()
{
return Sdks.XamIOS.SdkDir;
}
}
}

Просмотреть файл

@ -3,7 +3,9 @@ using System.IO;
using NUnit.Framework; using NUnit.Framework;
namespace Xamarin.iOS.Tasks using Xamarin.iOS.Tasks;
namespace Xamarin.MacDev.Tasks
{ {
[TestFixture] [TestFixture]
public class DetectSdkLocationsTaskTests : TestBase public class DetectSdkLocationsTaskTests : TestBase