Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 6d23992

Browse files
authored
Remove references to XreItem when using XCODE on Provisionsator (#12020)
* Switch to new xcode prov syntax * - fix extra item * - check for xcode install * - check az variables * - add xcode select
1 parent 83e7c68 commit 6d23992

File tree

2 files changed

+94
-9
lines changed

2 files changed

+94
-9
lines changed

build.cake

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ string workingDirectory = EnvironmentVariable("SYSTEM_DEFAULTWORKINGDIRECTORY",
4242
var configuration = Argument("BUILD_CONFIGURATION", "Debug");
4343

4444
var target = Argument("target", "Default");
45-
var IOS_SIM_NAME = Argument("IOS_SIM_NAME", "iPhone 7");
46-
var IOS_SIM_RUNTIME = Argument("IOS_SIM_RUNTIME", "com.apple.CoreSimulator.SimRuntime.iOS-12-4");
45+
var IOS_SIM_NAME = GetBuildVariable("IOS_SIM_NAME", "iPhone 7");
46+
var IOS_SIM_RUNTIME = GetBuildVariable("IOS_SIM_RUNTIME", "com.apple.CoreSimulator.SimRuntime.iOS-12-4");
4747
var IOS_TEST_PROJ = "./Xamarin.Forms.Core.iOS.UITests/Xamarin.Forms.Core.iOS.UITests.csproj";
4848
var IOS_TEST_LIBRARY = Argument("IOS_TEST_LIBRARY", $"./Xamarin.Forms.Core.iOS.UITests/bin/{configuration}/Xamarin.Forms.Core.iOS.UITests.dll");
4949
var IOS_IPA_PATH = Argument("IOS_IPA_PATH", $"./Xamarin.Forms.ControlGallery.iOS/bin/iPhoneSimulator/{configuration}/XamarinFormsControlGalleryiOS.app");
@@ -200,8 +200,6 @@ else if(releaseChannel == ReleaseChannel.Stable)
200200
{
201201
if(IsXcodeVersionOver("11.4"))
202202
{
203-
// Xcode 11.4 just uses boots enums
204-
Information ("XCODE 11.4");
205203
}
206204
else
207205
{
@@ -969,6 +967,7 @@ Task("cg-ios-build-tests")
969967
.WithProperty("MtouchArch", "x86_64")
970968
.WithProperty("iOSPlatform", "iPhoneSimulator")
971969
.WithProperty("BuildIpa", $"true")
970+
.WithProperty("CI", $"true")
972971
.WithRestore();
973972

974973
if(isCIBuild)
@@ -1129,6 +1128,17 @@ bool IsXcodeVersionOver(string version)
11291128
{
11301129
var xcodeVersion = Version.Parse(item.Replace("Xcode", ""));
11311130
Information($"Xcode: {xcodeVersion}");
1131+
var xcodePath = xcodeVersion.ToString().Replace(".0", "");
1132+
1133+
if(isCIBuild)
1134+
{
1135+
StartProcess("xcode-select",
1136+
new ProcessSettings {
1137+
Arguments = new ProcessArgumentBuilder().Append($"-s /Applications/Xcode_{xcodePath}.app")
1138+
}
1139+
);
1140+
}
1141+
11321142
return Version.Parse(item.Replace("Xcode", "")) >= Version.Parse(version);
11331143
}
11341144
}

build/provisioning/xcode.csx

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#r "_provisionator/provisionator.dll"
2+
3+
using static Xamarin.Provisioning.ProvisioningScript;
4+
15
using System;
26
using System.Linq;
37

@@ -7,13 +11,84 @@ if (string.IsNullOrEmpty (desiredXcode)) {
711
return;
812
}
913

10-
XreItem xreItem;
14+
desiredXcode = desiredXcode.Replace("Xcode_", "").Replace("_", ".");
15+
16+
Item item;
1117

1218
if(desiredXcode == "Latest")
13-
xreItem = (XreItem)Enum.GetValues(typeof(XreItem)).Cast<int>().Max();
19+
{
20+
item = XcodeBeta();
21+
22+
if(item.Version.StartsWith("12.0.0-beta."))
23+
{
24+
Console.WriteLine ("CheckInstalledDevOpsBetaXcodeAndSymlink");
25+
int expectedBeta = Convert.ToInt32(item.Version.Replace("12.0.0-beta.", ""));
26+
CheckInstalledDevOpsBetaXcodeAndSymlink("17200.1", expectedBeta: expectedBeta);
27+
}
28+
}
29+
else if (desiredXcode == "Stable")
30+
item = XcodeStable();
1431
else
15-
xreItem = (XreItem) Enum.Parse (typeof (XreItem), desiredXcode);
32+
item = Xcode(desiredXcode);
1633

17-
var item = Item (xreItem);
1834
Console.WriteLine ("InstallPath: {0}", item.Version);
19-
item.XcodeSelect ();
35+
item.XcodeSelect ();
36+
37+
LogInstalledXcodes();
38+
39+
var appleSdkOverride = Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.Personal), "Library", "Preferences", "Xamarin", "Settings.plist");
40+
Item("Override Apple SDK Settings")
41+
.Condition(item => !File.Exists(appleSdkOverride) || GetSettingValue(appleSdkOverride, "AppleSdkRoot") != GetSelectedXcodePath())
42+
.Action (item => {
43+
DeleteSafe(appleSdkOverride);
44+
CreateSetting(appleSdkOverride, "AppleSdkRoot", GetSelectedXcodePath ());
45+
Console.WriteLine($"New VSMac iOS SDK Location: {GetSelectedXcodePath ()}");
46+
});
47+
48+
49+
50+
void DeleteSafe(string file)
51+
{
52+
if (File.Exists(file))
53+
File.Delete(file);
54+
}
55+
56+
void CreateSetting(string settingFile, string key, string value)
57+
{
58+
Exec("defaults", "write", settingFile, key, value);
59+
}
60+
61+
string GetSettingValue(string settingFile, string keyName)
62+
{
63+
return Exec("defaults", "read", settingFile, keyName).FirstOrDefault();
64+
}
65+
66+
bool CheckInstalledDevOpsBetaXcodeAndSymlink (string expectedBundleVersion, int expectedBeta)
67+
{
68+
var devOpsXcodeBetaPath = "/Applications/Xcode_12_beta.app";
69+
if (!Directory.Exists (devOpsXcodeBetaPath))
70+
return false;
71+
72+
var infoPlist = Plist (devOpsXcodeBetaPath);
73+
var bundleVersion = (string)infoPlist.CFBundleVersion;
74+
if (bundleVersion != expectedBundleVersion)
75+
return false;
76+
77+
if (RunningInCI) {
78+
SafeSymlink (devOpsXcodeBetaPath, $"/Applications/Xcode_12.0.0-beta{expectedBeta}.app");
79+
SafeSymlink (devOpsXcodeBetaPath, $"/Applications/Xcode_12_beta_{expectedBeta}.app");
80+
}
81+
82+
Console.WriteLine ($"CFBundleVersion found: {bundleVersion}");
83+
return true;
84+
}
85+
86+
void SafeSymlink (string source, string destination)
87+
{
88+
if (Directory.Exists (destination) || Config.DryRun)
89+
return;
90+
91+
Console.WriteLine ($"ln -sf {source} {destination}");
92+
Exec ("/bin/ln", "-sf", source, destination);
93+
Console.WriteLine ($"Symlink created: '{source}' links to '{destination}'");
94+
}

0 commit comments

Comments
 (0)