1
+ #r "_provisionator/provisionator.dll"
2
+
3
+ using static Xamarin . Provisioning . ProvisioningScript ;
4
+
1
5
using System ;
2
6
using System . Linq ;
3
7
@@ -7,13 +11,84 @@ if (string.IsNullOrEmpty (desiredXcode)) {
7
11
return ;
8
12
}
9
13
10
- XreItem xreItem ;
14
+ desiredXcode = desiredXcode . Replace ( "Xcode_" , "" ) . Replace ( "_" , "." ) ;
15
+
16
+ Item item ;
11
17
12
18
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 ( ) ;
14
31
else
15
- xreItem = ( XreItem ) Enum . Parse ( typeof ( XreItem ) , desiredXcode ) ;
32
+ item = Xcode ( desiredXcode ) ;
16
33
17
- var item = Item ( xreItem ) ;
18
34
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