Skip to content

Commit eecff69

Browse files
Factor out Get-BuiltToolchainTool analog to Get-PinnedToolchainTool and give both an optional Name param
1 parent 17a146b commit eecff69

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

utils/build.ps1

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -800,11 +800,16 @@ function Fetch-Dependencies {
800800
}
801801
}
802802

803-
function Get-PinnedToolchainTool() {
803+
function Get-PinnedToolchainTool([string] $Name) {
804804
if (Test-Path "$BinaryCache\toolchains\${PinnedToolchain}\LocalApp\Programs\Swift\Toolchains\$(Get-PinnedToolchainVersion)+Asserts\usr\bin") {
805-
return "$BinaryCache\toolchains\${PinnedToolchain}\LocalApp\Programs\Swift\Toolchains\$(Get-PinnedToolchainVersion)+Asserts\usr\bin"
805+
$Path = "$BinaryCache\toolchains\${PinnedToolchain}\LocalApp\Programs\Swift\Toolchains\$(Get-PinnedToolchainVersion)+Asserts\usr\bin"
806+
} else {
807+
$Path = "$BinaryCache\toolchains\${PinnedToolchain}\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin"
808+
}
809+
if ($Name) {
810+
$Path = "$Path\$Name"
806811
}
807-
return "$BinaryCache\toolchains\${PinnedToolchain}\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin"
812+
return $Path
808813
}
809814

810815
function Get-PinnedToolchainSDK() {
@@ -835,6 +840,10 @@ $CompilersBinaryCache = if ($IsCrossCompiling) {
835840
Get-HostProjectBinaryCache Compilers
836841
}
837842

843+
function Get-BuiltToolchainTool([string] $Name) {
844+
return if ($Name) { "$CompilersBinaryCache\bin\$Name" } else { "$CompilersBinaryCache\bin" }
845+
}
846+
838847
function Get-ClangDriverName([Platform] $Platform, [string] $Lang) {
839848
switch ($Platform) {
840849
Windows {
@@ -1004,7 +1013,7 @@ function Build-CMakeProject {
10041013
# Use a built lld linker as the Android's NDK linker might be too
10051014
# old and not support all required relocations needed by the Swift
10061015
# runtime.
1007-
$ldPath = ([IO.Path]::Combine($CompilersBinaryCache, "bin", "ld.lld"))
1016+
$ldPath = (Get-BuiltToolchainTool "ld.lld")
10081017
Append-FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS "--ld-path=$ldPath"
10091018
Append-FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS "--ld-path=$ldPath"
10101019
}
@@ -1027,9 +1036,9 @@ function Build-CMakeProject {
10271036
if ($UsePinnedCompilers.Contains("ASM") -Or $UseBuiltCompilers.Contains("ASM")) {
10281037
$Driver = (Get-ClangDriverName $Platform -Lang "ASM")
10291038
if ($UseBuiltCompilers.Contains("ASM")) {
1030-
TryAdd-KeyValue $Defines CMAKE_ASM_COMPILER ([IO.Path]::Combine($CompilersBinaryCache, "bin", $Driver))
1039+
TryAdd-KeyValue $Defines CMAKE_ASM_COMPILER (Get-BuiltToolchainTool $Driver)
10311040
} else {
1032-
TryAdd-KeyValue $Defines CMAKE_ASM_COMPILER (Join-Path -Path (Get-PinnedToolchainTool) -ChildPath $Driver)
1041+
TryAdd-KeyValue $Defines CMAKE_ASM_COMPILER (Get-PinnedToolchainTool $Driver)
10331042
}
10341043
Append-FlagsDefine $Defines CMAKE_ASM_FLAGS "--target=$($Arch.LLVMTarget)"
10351044
if ($Platform -eq "Windows") {
@@ -1039,9 +1048,9 @@ function Build-CMakeProject {
10391048
if ($UsePinnedCompilers.Contains("C") -Or $UseBuiltCompilers.Contains("C")) {
10401049
$Driver = (Get-ClangDriverName $Platform -Lang "C")
10411050
if ($UseBuiltCompilers.Contains("C")) {
1042-
TryAdd-KeyValue $Defines CMAKE_C_COMPILER ([IO.Path]::Combine($CompilersBinaryCache, "bin", $Driver))
1051+
TryAdd-KeyValue $Defines CMAKE_C_COMPILER (Get-BuiltToolchainTool $Driver)
10431052
} else {
1044-
TryAdd-KeyValue $Defines CMAKE_C_COMPILER (Join-Path -Path (Get-PinnedToolchainTool) -ChildPath $Driver)
1053+
TryAdd-KeyValue $Defines CMAKE_C_COMPILER (Get-PinnedToolchainTool $Driver)
10451054
}
10461055
TryAdd-KeyValue $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
10471056

@@ -1058,9 +1067,9 @@ function Build-CMakeProject {
10581067
if ($UsePinnedCompilers.Contains("CXX") -Or $UseBuiltCompilers.Contains("CXX")) {
10591068
$Driver = (Get-ClangDriverName $Platform -Lang "CXX")
10601069
if ($UseBuiltCompilers.Contains("CXX")) {
1061-
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER ([IO.Path]::Combine($CompilersBinaryCache, "bin", $Driver))
1070+
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER (Get-BuiltToolchainTool $Driver)
10621071
} else {
1063-
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER (Join-Path -Path (Get-PinnedToolchainTool) -ChildPath $Driver)
1072+
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER (Get-PinnedToolchainTool $Driver)
10641073
}
10651074
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
10661075

@@ -1080,9 +1089,9 @@ function Build-CMakeProject {
10801089
if ($UseSwiftSwiftDriver) {
10811090
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER ([IO.Path]::Combine($DriverBinaryCache, "bin", "swiftc.exe"))
10821091
} elseif ($UseBuiltCompilers.Contains("Swift")) {
1083-
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER ([IO.Path]::Combine($CompilersBinaryCache, "bin", "swiftc.exe"))
1092+
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER (Get-BuiltToolchainTool "swiftc.exe")
10841093
} else {
1085-
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER (Join-Path -Path (Get-PinnedToolchainTool) -ChildPath "swiftc.exe")
1094+
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER (Get-PinnedToolchainTool "swiftc.exe")
10861095
}
10871096
if (-not ($Platform -eq "Windows")) {
10881097
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER_WORKS = "YES"

0 commit comments

Comments
 (0)