Skip to content

Commit 1c7fa7f

Browse files
committed
wip
1 parent 3f85b2a commit 1c7fa7f

File tree

15 files changed

+65
-60
lines changed

15 files changed

+65
-60
lines changed

msbuild/Xamarin.MacDev.Tasks/Sdks.cs

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,24 @@
99

1010
namespace Xamarin.MacDev {
1111
public static class Sdks {
12-
public static AppleIPhoneSdk IOS { get; private set; }
13-
public static MacOSXSdk MacOS { get; private set; }
14-
public static AppleTVOSSdk TVOS { get; private set; }
15-
16-
static Sdks ()
17-
{
18-
IOS = new AppleIPhoneSdk (AppleSdkSettings.DeveloperRoot, AppleSdkSettings.DeveloperRootVersionPlist);
19-
TVOS = new AppleTVOSSdk (AppleSdkSettings.DeveloperRoot, AppleSdkSettings.DeveloperRootVersionPlist);
20-
MacOS = new MacOSXSdk (AppleSdkSettings.DeveloperRoot, AppleSdkSettings.DeveloperRootVersionPlist);
21-
}
22-
23-
public static AppleSdk GetSdk (ApplePlatform framework)
12+
public static IAppleSdk GetAppleSdk (ApplePlatform framework, XcodeLocator appleSdk)
2413
{
2514
switch (framework) {
2615
case ApplePlatform.iOS:
27-
return IOS;
16+
return new AppleIPhoneSdk (appleSdk.DeveloperRoot, appleSdk.DeveloperRootVersionPlist);
2817
case ApplePlatform.TVOS:
29-
return TVOS;
30-
default:
31-
throw new InvalidOperationException (string.Format (MSBStrings.InvalidFramework, framework));
32-
}
33-
}
34-
35-
public static AppleSdk GetSdk (string targetFrameworkMoniker)
36-
{
37-
return GetSdk (PlatformFrameworkHelper.GetFramework (targetFrameworkMoniker));
38-
}
39-
40-
public static IAppleSdk GetAppleSdk (ApplePlatform framework)
41-
{
42-
switch (framework) {
43-
case ApplePlatform.iOS:
44-
return IOS;
45-
case ApplePlatform.TVOS:
46-
return TVOS;
18+
return new AppleTVOSSdk (appleSdk.DeveloperRoot, appleSdk.DeveloperRootVersionPlist);
4719
case ApplePlatform.MacCatalyst:
4820
case ApplePlatform.MacOSX:
49-
return MacOS;
21+
return new MacOSXSdk (appleSdk.DeveloperRoot, appleSdk.DeveloperRootVersionPlist);
5022
default:
5123
throw new InvalidOperationException (string.Format (MSBStrings.InvalidFramework, framework));
5224
}
5325
}
5426

55-
public static IAppleSdk GetAppleSdk (string targetFrameworkMoniker)
27+
public static IAppleSdk GetAppleSdk (string targetFrameworkMoniker, XcodeLocator appleSdk)
5628
{
57-
return GetAppleSdk (PlatformFrameworkHelper.GetFramework (targetFrameworkMoniker));
29+
return GetAppleSdk (PlatformFrameworkHelper.GetFramework (targetFrameworkMoniker), appleSdk);
5830
}
59-
6031
}
6132
}

msbuild/Xamarin.MacDev.Tasks/Tasks/CompileAppManifest.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ bool SetMinimumOSVersion (PDictionary plist)
252252
if (Platform == ApplePlatform.MacCatalyst && !string.IsNullOrEmpty (SupportedOSPlatformVersion)) {
253253
// SupportedOSPlatformVersion is the iOS version for Mac Catalyst.
254254
// But we need to store the macOS version in the app manifest, so convert it to the macOS version here.
255-
if (!MacCatalystSupport.TryGetMacOSVersion (Sdks.GetAppleSdk (Platform).GetSdkPath (SdkVersion), SupportedOSPlatformVersion, out var convertedVersion, out var knowniOSVersions)) {
255+
if (!MacCatalystSupport.TryGetMacOSVersion (GetSdk ().GetSdkPath (SdkVersion), SupportedOSPlatformVersion, out var convertedVersion, out var knowniOSVersions)) {
256256
Log.LogError (MSBStrings.E0188, SupportedOSPlatformVersion, string.Join (", ", knowniOSVersions.OrderBy (v => v)));
257257
return false;
258258
}
@@ -266,7 +266,7 @@ bool SetMinimumOSVersion (PDictionary plist)
266266
var minimumiOSVersionInManifest = plist.Get<PString> (ManifestKeys.MinimumOSVersion)?.Value;
267267
if (!string.IsNullOrEmpty (minimumiOSVersionInManifest)) {
268268
// Convert to the macOS version
269-
if (!MacCatalystSupport.TryGetMacOSVersion (Sdks.GetAppleSdk (Platform).GetSdkPath (SdkVersion), minimumiOSVersionInManifest!, out var convertedVersion, out var knowniOSVersions)) {
269+
if (!MacCatalystSupport.TryGetMacOSVersion (GetSdk ().GetSdkPath (SdkVersion), minimumiOSVersionInManifest!, out var convertedVersion, out var knowniOSVersions)) {
270270
Log.LogError (MSBStrings.E0188, minimumiOSVersionInManifest, string.Join (", ", knowniOSVersions.OrderBy (v => v)));
271271
return false;
272272
}
@@ -325,7 +325,7 @@ bool Compile (PDictionary plist)
325325
return false;
326326
}
327327

328-
var currentSDK = Sdks.GetAppleSdk (Platform);
328+
var currentSDK = GetSdk ();
329329

330330
sdkVersion = AppleSdkVersion.Parse (DefaultSdkVersion);
331331
if (!currentSDK.SdkIsInstalled (sdkVersion, SdkIsSimulator)) {
@@ -424,6 +424,11 @@ protected void MergePartialPlistTemplates (PDictionary plist)
424424
MergePartialPLists (this, plist, PartialAppManifests);
425425
}
426426

427+
IAppleSdk GetSdk ()
428+
{
429+
return Sdks.GetAppleSdk (Platform, GetXcodeLocator ());
430+
}
431+
427432
void Validation (PDictionary plist)
428433
{
429434
if (!Validate)
@@ -440,7 +445,7 @@ void Validation (PDictionary plist)
440445
GetMinimumOSVersion (plist, out var minimumOSVersion);
441446
if (minimumOSVersion < new Version (11, 0)) {
442447
string miniOSVersion = "?";
443-
if (MacCatalystSupport.TryGetiOSVersion (Sdks.GetAppleSdk (Platform).GetSdkPath (SdkVersion), minimumOSVersion, out var iOSVersion, out var _))
448+
if (MacCatalystSupport.TryGetiOSVersion (GetSdk ().GetSdkPath (SdkVersion), minimumOSVersion, out var iOSVersion, out var _))
444449
miniOSVersion = iOSVersion?.ToString () ?? "?";
445450
LogAppManifestError (MSBStrings.E7099 /* The UIDeviceFamily value '6' requires macOS 11.0. Please set the 'SupportedOSPlatformVersion' in the project file to at least 14.0 (the Mac Catalyst version equivalent of macOS 11.0). The current value is {0} (equivalent to macOS {1}). */, miniOSVersion, minimumOSVersion);
446451
}
@@ -534,7 +539,7 @@ void SetXcodeValues (PDictionary plist, IAppleSdk currentSDK)
534539
SetValueIfNotNull (plist, "DTPlatformName", PlatformUtils.GetTargetPlatform (SdkPlatform, IsWatchApp));
535540
SetValueIfNotNull (plist, "DTPlatformVersion", dtSettings.DTPlatformVersion);
536541
SetValueIfNotNull (plist, "DTSDKName", sdkSettings.CanonicalName);
537-
SetValueIfNotNull (plist, "DTXcode", AppleSdkSettings.DTXcode);
542+
SetValueIfNotNull (plist, "DTXcode", GetXcodeLocator ().DTXcode);
538543
SetValueIfNotNull (plist, "DTXcodeBuild", dtSettings.DTXcodeBuild);
539544
}
540545

msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlements.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ string DefaultEntitlementsPath {
117117
return "Entitlements.plist";
118118
}
119119

120-
return Path.Combine (Sdks.GetAppleSdk (TargetFrameworkMoniker).GetSdkPath (SdkVersion, false), "Entitlements.plist");
120+
return Path.Combine (Sdks.GetAppleSdk (TargetFrameworkMoniker, GetXcodeLocator ()).GetSdkPath (SdkVersion, false), "Entitlements.plist");
121121
}
122122
}
123123

msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSdkLocation.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ public string SdkRoot {
2828
get; set;
2929
} = "";
3030

31+
// this is input too
3132
[Output]
3233
public new string SdkDevPath {
33-
get; set;
34-
} = "";
35-
34+
get => base.SdkDevPath;
35+
set => base.SdkDevPath = value;
36+
}
3637

3738
[Output]
3839
public bool SdkIsSimulator {
3940
get; set;
4041
}
4142

43+
[Output]
4244
public string SdkPlatform {
4345
get; set;
4446
} = "";
@@ -64,10 +66,12 @@ public string XcodeVersion {
6466

6567
protected IAppleSdk CurrentSdk {
6668
get {
67-
return Sdks.GetAppleSdk (Platform);
69+
return Sdks.GetAppleSdk (Platform, GetXcodeLocator ());
6870
}
6971
}
7072

73+
XcodeLocator? appleSdkSettings;
74+
7175
IAppleSdkVersion GetDefaultSdkVersion ()
7276
{
7377
switch (Platform) {
@@ -148,22 +152,24 @@ bool ExecuteImpl ()
148152
return ExecuteRemotely ();
149153
}
150154

151-
AppleSdkSettings.Init ();
155+
appleSdkSettings = GetXcodeLocator (initialDiscovery: true);
156+
SdkDevPath = appleSdkSettings.DeveloperRoot;
157+
XcodeVersion = appleSdkSettings.XcodeVersion.ToString ();
158+
if (Log.HasLoggedErrors)
159+
return false;
152160

153161
if (EnsureAppleSdkRoot ())
154162
EnsureSdkPath ();
155163
EnsureXamarinSdkRoot ();
156164

157-
XcodeVersion = AppleSdkSettings.XcodeVersion.ToString ();
158-
159165
return !Log.HasLoggedErrors;
160166
}
161167

162168
protected bool EnsureAppleSdkRoot ()
163169
{
164170
var currentSdk = CurrentSdk;
165171
if (!currentSdk.IsInstalled) {
166-
Log.LogError (MSBStrings.E0044v2 /* Could not find a valid Xcode app bundle at '{0}'. Please verify that 'xcode-select -p' points to your Xcode installation. For more information see https://aka.ms/macios-missing-xcode. */, AppleSdkSettings.InvalidDeveloperRoot);
172+
Log.LogError (MSBStrings.E0044v2 /* Could not find a valid Xcode app bundle at '{0}'. Please verify that 'xcode-select -p' points to your Xcode installation. For more information see https://aka.ms/macios-missing-xcode. */, appleSdkSettings?.XcodeLocation);
167173
return false;
168174
}
169175
Log.LogMessage (MessageImportance.Low, "DeveloperRoot: {0}", currentSdk.DeveloperRoot);

msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSigningIdentity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class DetectSigningIdentity : XamarinTask, ITaskCallback, ICancelableTask
3131

3232
protected string DeveloperRoot {
3333
get {
34-
return Sdks.GetAppleSdk (TargetFrameworkMoniker).DeveloperRoot;
34+
return Sdks.GetAppleSdk (TargetFrameworkMoniker, GetXcodeLocator ()).DeveloperRoot;
3535
}
3636
}
3737

msbuild/Xamarin.MacDev.Tasks/Tasks/ReadAppManifest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public override bool Execute ()
7373
if (Platform == ApplePlatform.MacCatalyst) {
7474
// The minimum version in the Info.plist is the macOS version. However, the rest of our tooling
7575
// expects the iOS version, so expose that.
76-
if (!MacCatalystSupport.TryGetiOSVersion (Sdks.GetAppleSdk (Platform).GetSdkPath (), MinimumOSVersion!, out var convertedVersion, out var knownMacOSVersions))
76+
if (!MacCatalystSupport.TryGetiOSVersion (Sdks.GetAppleSdk (Platform, GetXcodeLocator ()).GetSdkPath (), MinimumOSVersion!, out var convertedVersion, out var knownMacOSVersions))
7777
Log.LogError (MSBStrings.E0187, MinimumOSVersion, string.Join (", ", knownMacOSVersions.OrderBy (v => v)));
7878
MinimumOSVersion = convertedVersion;
7979
}

msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ public abstract class XamarinTask : Task, IHasSessionId, ICustomLogger {
2525

2626
public string SdkDevPath { get; set; } = string.Empty;
2727

28+
XcodeLocator? xcodeLocator = null;
29+
public XcodeLocator GetXcodeLocator (bool initialDiscovery = false)
30+
{
31+
if (xcodeLocator is null) {
32+
if (!initialDiscovery && string.IsNullOrEmpty (SdkDevPath)) {
33+
// Log.LogError (MSBStrings.E7164 /* The task '{0}' is trying to call an external process, but a path to Xcode has not been provided. Please file an issue at https://github.com/dotnet/macios/issues/new/choose. */, task.GetType ().Name);
34+
Log.LogError ("The task '{0}' requires SdkDevPath to be set.\n{1}", GetType ().Name, Environment.StackTrace);
35+
}
36+
37+
var xcodeLocator = new XcodeLocator (this);
38+
if (!xcodeLocator.TryLocatingXcode (SdkDevPath))
39+
Log.LogError (MSBStrings.E0086 /* Could not find a valid Xcode developer path */);
40+
this.xcodeLocator = xcodeLocator;
41+
}
42+
return xcodeLocator;
43+
}
44+
2845
void VerifyTargetFrameworkMoniker ()
2946
{
3047
if (!string.IsNullOrEmpty (TargetFrameworkMoniker))

msbuild/Xamarin.Shared/Xamarin.Shared.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
697697
ProjectDir="$(MSBuildProjectDirectory)"
698698
ResourcePrefix="$(_ResourcePrefix)"
699699
ResourceRules="$(_PreparedResourceRules)"
700+
SdkDevPath="$(_SdkDevPath)"
700701
SdkIsSimulator="$(_SdkIsSimulator)"
701702
SdkVersion="$(_SdkVersion)"
702703
SupportedOSPlatformVersion="$(SupportedOSPlatformVersion)"
@@ -2062,6 +2063,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
20622063
SdkPlatform="$(_SdkPlatform)"
20632064
ProvisioningProfile="$(CodesignProvision)"
20642065
SigningKey="$(_SpecifiedCodesignKey)"
2066+
SdkDevPath="$(_SdkDevPath)"
20652067
DetectedCodeSigningKey="$(_CodeSigningKey)"
20662068
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
20672069
>

tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ACToolTaskTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ ACTool CreateACToolTask (ApplePlatform platform, string projectDir, out string i
2222

2323
intermediateOutputPath = Cache.CreateTemporaryDirectory ();
2424

25-
var sdk = Sdks.GetAppleSdk (platform);
25+
var task = CreateTask<ACTool> ();
26+
27+
var sdk = Sdks.GetAppleSdk (platform, task.GetXcodeLocator (initialDiscovery: true));
2628
var version = AppleSdkVersion.UseDefault.ToString ();
2729
var root = sdk.GetSdkPath (version, false);
2830
string sdkPlatform;
@@ -47,7 +49,6 @@ ACTool CreateACToolTask (ApplePlatform platform, string projectDir, out string i
4749
throw new NotImplementedException (platform.ToString ());
4850
}
4951

50-
var task = CreateTask<ACTool> ();
5152
task.ImageAssets = imageAssets
5253
.Select (v => {
5354
var spl = v.Split ('|');

0 commit comments

Comments
 (0)