Skip to content

Commit

Permalink
[msbuild] Unify the DetectSdkLocations task logic between iOS and Mac. (
Browse files Browse the repository at this point in the history
xamarin#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.
  • Loading branch information
rolfbjarne authored Jun 16, 2022
1 parent 357adfd commit ab52bb2
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 73 deletions.
19 changes: 0 additions & 19 deletions msbuild/Xamarin.Mac.Tasks.Core/Tasks/DetectSdkLocationsTaskBase.cs

This file was deleted.

7 changes: 0 additions & 7 deletions msbuild/Xamarin.Mac.Tasks/Tasks/DetectSdkLocations.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,36 @@ protected IAppleSdk CurrentSdk {
}
}

protected abstract string GetDefaultXamarinSdkRoot ();
protected abstract IAppleSdkVersion GetDefaultSdkVersion ();
string GetDefaultXamarinSdkRoot ()
{
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 ()
{
Expand Down Expand Up @@ -147,6 +175,10 @@ void EnsureXamarinSdkRoot ()

public override bool Execute ()
{
AppleSdkSettings.Init ();

SetIsSimulator ();

// If XamarinSdkRoot is set, then make that override any other value, and in order to do so,
// set the corresponding environment variable accordingly.
if (!string.IsNullOrEmpty (XamarinSdkRoot))
Expand All @@ -159,6 +191,25 @@ public override bool Execute ()
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 ()
{
var currentSdk = CurrentSdk;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;

using Microsoft.Build.Framework;

using Xamarin.Messaging.Build.Client;

namespace Xamarin.iOS.Tasks
{
public class DetectSdkLocations : DetectSdkLocationsTaskBase, ICancelableTask
{
namespace Xamarin.MacDev.Tasks {
public class DetectSdkLocations : DetectSdkLocationsCoreTaskBase, ICancelableTask {
const string SdkVersionDefaultValue = "default";

public override bool Execute ()
{
if (!ShouldExecuteRemotely())
if (!ShouldExecuteRemotely ())
return base.Execute ();

// The new targets do not support the "default" value for the MtouchSdkVersion
Expand Down
3 changes: 1 addition & 2 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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.CreateAssetPack" 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.FindWatchOS2AppBundle" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.GetMlaunchArguments" AssemblyFile="$(_TaskAssemblyName)" />
Expand All @@ -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 -->
<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.DetectSdkLocations" 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.PrepareNativeReferences" AssemblyFile="$(_TaskAssemblyName)" />
Expand Down Expand Up @@ -88,6 +86,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask TaskName="Xamarin.MacDev.Tasks.CompileProductDefinition" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.ComputeCodesignItems" 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.DSymUtil" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.EmbedProvisionProfile" AssemblyFile="$(_TaskAssemblyName)" />
Expand Down
37 changes: 0 additions & 37 deletions msbuild/Xamarin.iOS.Tasks.Core/Tasks/DetectSdkLocationsTaskBase.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

using NUnit.Framework;

namespace Xamarin.iOS.Tasks
using Xamarin.iOS.Tasks;

namespace Xamarin.MacDev.Tasks
{
[TestFixture]
public class DetectSdkLocationsTaskTests : TestBase
Expand Down

0 comments on commit ab52bb2

Please sign in to comment.