Skip to content

Commit

Permalink
If an iOS SDK is embedded and this SDK archive contains an xcodeVersi…
Browse files Browse the repository at this point in the history
…on file, use it to define the Xcode Version
  • Loading branch information
e-marchand committed Sep 13, 2024
1 parent e145c89 commit 5c86b41
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 86 deletions.
94 changes: 88 additions & 6 deletions Project/Sources/Classes/Xcode.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,39 @@ Function getRequirements($force : Boolean)

End if

// If embedded iOS sdk use it as reference
var $sdk : 4D:C1709.File
$sdk:=cs:C1710.path.new().sdkApple()

If ($sdk.exists)

var $version : Object
var $xcodeVersionFile : 4D:C1709.ZipFile
var $archive : 4D:C1709.ZipArchive
var $Txt_methodOnErrorCall : Text
$Txt_methodOnErrorCall:=Method called on error:C704
ON ERR CALL:C155("ob_noError")
$archive:=ZIP Read archive:C1637($sdk)
ON ERR CALL:C155($Txt_methodOnErrorCall)
If ($archive#Null:C1517)

$xcodeVersionFile:=$archive.root.file("xcodeVersion")

If ($xcodeVersionFile.exists)

$version:=This:C1470._xcodeBuildVersion(New object:C1471("out"; $xcodeVersionFile.getText()))
If ($version.success)

This:C1470.requirement:="~"+$version.version // accept minor? (expecting not breaking change)

End if

End if

End if

End if

//====================================================================
// Populate Application with the default path
Function defaultPath()
Expand Down Expand Up @@ -601,15 +634,64 @@ Function showDevicesWindow

//====================================================================
Function downloadIOSPlatform() : Object
var $in; $out; $err : Text
LAUNCH EXTERNAL PROCESS:C811("xcodebuild -downloadPlatform iOS"; $in; $out; $err)
return New object:C1471("message"; $out; "error"; $err)

return This:C1470.lep("xcodebuild -downloadPlatform iOS")

//====================================================================
Function downloadAllPlatform() : Object
var $in; $out; $err : Text
LAUNCH EXTERNAL PROCESS:C811("xcodebuild -downloadAllPlatforms"; $in; $out; $err)
return New object:C1471("message"; $out; "error"; $err)

return This:C1470.lep("xcodebuild -downloadAllPlatforms")

//====================================================================
Function sdks() : Object

return This:C1470.lep("xcodebuild -showsdks")

//====================================================================
Function xcodeBuildVersion() : Object

return This:C1470._xcodeBuildVersion(This:C1470.lep("xcodebuild -version"))

Function _xcodeBuildVersion($result : Object) : Object

var $regex : cs:C1710.regex
$regex:=cs:C1710.regex.new(String:C10($result.out); "(?s-mi)Xcode (\\d{1,}(?:\\.\\d)*).*version\\s*([A-Z0-9]*)")

$result.success:=False:C215

If ($regex.match())

If ($regex.matches.length=3)

$result.success:=True:C214
$result.version:=$regex.matches[1].data
$result.build:=$regex.matches[2].data

End if
End if

return $result

//====================================================================
Function swiftVersion() : Object

var $result : Object
$result:=This:C1470.lep("xcrun swift --version")

var $regex : cs:C1710.regex
$regex:=cs:C1710.regex.new(String:C10($result.out); "(?mi-s)Apple Swift version ((?:\\d\\.)*\\d)")

If ($regex.match())

If ($regex.matches.length>0)

$result.success:=True:C214
$result.swift:=$regex.matches[1].data

End if
End if

return $result

//====================================================================
Function isCancelled()->$is : Boolean
Expand Down
2 changes: 1 addition & 1 deletion Project/Sources/Methods/RIBBON_SIMULATOR.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Case of
var $resultDl : Object
$resultDl:=(Shift down:C543) ? cs:C1710.Xcode.new().downloadAllPlatform() : cs:C1710.Xcode.new().downloadIOSPlatform()

ALERT:C41($resultDl.message+$resultDl.error)
ALERT:C41(String:C10($resultDl.out)+String:C10($resultDl.error))

//______________________________________________________
: ($menu.choice="createAVD")
Expand Down
91 changes: 12 additions & 79 deletions Project/Sources/Methods/Xcode.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
// ----------------------------------------------------
// Declarations
#DECLARE($Obj_param)->$Obj_result
#DECLARE($Obj_param : Object)->$Obj_result : Object

var $Boo_search : Boolean
var $Lon_i; $Lon_x : Integer
Expand All @@ -20,10 +20,6 @@ var $subfolder : Object
var $Col_folder; $Col_paths : Collection
var $regex : cs:C1710.regex

If (False:C215)
C_OBJECT:C1216(Xcode; $0)
C_OBJECT:C1216(Xcode; $1)
End if

$Obj_result:=New object:C1471("success"; False:C215)

Expand Down Expand Up @@ -270,64 +266,13 @@ Case of
// MARK:- xbuild-version
: ($Obj_param.action="xbuild-version")

$Txt_cmd:="xcodebuild -version"

LAUNCH EXTERNAL PROCESS:C811($Txt_cmd; $Txt_in; $Txt_out; $Txt_error)

If (Asserted:C1132(OK=1; "LEP failed: "+$Txt_cmd))

If (Length:C16($Txt_out)>0)

var $rgx : cs:C1710.regex
$rgx:=cs:C1710.regex.new($Txt_out; "(?s-mi)Xcode (\\d{1,}(?:\\.\\d)*).*version\\s*([A-Z0-9]*)")

If ($rgx.match())

If ($rgx.matches.length=3)

$Obj_result.success:=True:C214
$Obj_result.version:=$rgx.matches[1].data
$Obj_result.build:=$rgx.matches[2].data

End if
End if

Else

$Obj_result.error:=$Txt_error

End if
End if
$Obj_result:=cs:C1710.Xcode.new().xcodeBuildVersion()

// MARK:- swift-version
: ($Obj_param.action="swift-version")

$Txt_cmd:="xcrun swift --version"
$Obj_result:=cs:C1710.Xcode.new().swiftVersion()

LAUNCH EXTERNAL PROCESS:C811($Txt_cmd; $Txt_in; $Txt_out; $Txt_error)

If (Asserted:C1132(OK=1; "LEP failed: "+$Txt_cmd))

If (Length:C16($Txt_out)>0)

$regex:=cs:C1710.regex.new($Txt_out; "(?mi-s)Apple Swift version ((?:\\d\\.)*\\d)")

If ($regex.match())

If ($regex.matches.length>0)

$Obj_result.success:=True:C214
$Obj_result.swift:=$regex.matches[1].data

End if
End if

Else

$Obj_result.error:=$Txt_error

End if
End if

// MARK:- find
: ($Obj_param.action="find")
Expand Down Expand Up @@ -814,21 +759,7 @@ Case of
// MARK:- showsdks
: ($Obj_param.action="showsdks")

$Txt_cmd:="xcodebuild -showsdks"
LAUNCH EXTERNAL PROCESS:C811($Txt_cmd; $Txt_in; $Txt_out; $Txt_error)

If (Asserted:C1132(OK=1; "LEP failed: "+$Txt_cmd))

If (Length:C16($Txt_out)>0)

$Obj_result.success:=True:C214

Else

$Obj_result.error:=$Txt_error

End if
End if
$Obj_result:=cs:C1710.Xcode.new().sdks()

// MARK:- set-tool-path
: ($Obj_param.action="set-tool-path")
Expand Down Expand Up @@ -1465,12 +1396,6 @@ Get system info should not be called frequently (consumer) as the processor will
End if
End if

// MARK:- showDevicesWindow
: ($Obj_param.action="showDevicesWindow")

OPEN URL:C673("xcdevice://ShowDevicesWindow"; *)
// LAUNCH EXTERNAL PROCESS("open xcdevice://showDevicesWindow")
$Obj_result.success:=True:C214

// MARK:- enableForDevelopment
: ($Obj_param.action="enableForDevelopment")
Expand Down Expand Up @@ -1512,3 +1437,11 @@ Get system info should not be called frequently (consumer) as the processor will
//______________________________________________________
End case

var $log : Collection
$log:=New collection:C1472
$log.push("CMD: "+$Txt_cmd)
$log.push("STATUS: "+($Obj_result.success ? "success" : "failed"))
$log.push("OUTPUT: "+String:C10($Obj_result.out))
$log.push("ERROR: "+String:C10($Obj_result.error))

LOG EVENT:C667(Into 4D debug message:K38:5; $log.join("\r"); ($Obj_result.success ? Information message:K38:1 : Error message:K38:3))

0 comments on commit 5c86b41

Please sign in to comment.