Skip to content

Commit 4714ea9

Browse files
authored
Fix Swift SDK handling URLs without filename components (#6708)
Currently when invoking `swift experimental-sdk install https://server.org/abc?xy=z` installation will fail as we assume URLs always have a filename component similar to `https://server.org/swift-sdk.tar.gz`. Let's make the installation logic more flexible so that bundle name is inferred from the downloaded extract archive contents and not the URL. Also improved logging so that final bundle name is printed for such URLs without a filename component. Additionally we now print a message when starting a download, which is helpful if the download is long-running.
1 parent 9854e40 commit 4714ea9

19 files changed

+710
-607
lines changed
412 Bytes
Binary file not shown.

Sources/Basics/FileSystem/FileSystem+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ extension FileSystem {
496496
}
497497
}
498498

499-
public func getSharedSwiftSDKsDirectory(explicitDirectory: AbsolutePath?) throws -> AbsolutePath? {
499+
public func getSharedSwiftSDKsDirectory(explicitDirectory: AbsolutePath?) throws -> AbsolutePath {
500500
if let explicitDirectory {
501501
// Create the explicit SDKs path if necessary
502502
if !exists(explicitDirectory) {

Sources/Commands/SwiftBuildTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,6 @@ public struct SwiftBuildTool: SwiftCommand {
163163

164164
public extension _SwiftCommand {
165165
func buildSystemProvider(_ swiftTool: SwiftTool) throws -> BuildSystemProvider {
166-
return try swiftTool.defaultBuildSystemProvider
166+
swiftTool.defaultBuildSystemProvider
167167
}
168168
}

Sources/CoreCommands/SwiftTool.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,16 @@ public final class SwiftTool {
199199
public let scratchDirectory: AbsolutePath
200200

201201
/// Path to the shared security directory
202-
public let sharedSecurityDirectory: AbsolutePath?
202+
public let sharedSecurityDirectory: AbsolutePath
203203

204204
/// Path to the shared cache directory
205-
public let sharedCacheDirectory: AbsolutePath?
205+
public let sharedCacheDirectory: AbsolutePath
206206

207207
/// Path to the shared configuration directory
208-
public let sharedConfigurationDirectory: AbsolutePath?
208+
public let sharedConfigurationDirectory: AbsolutePath
209209

210210
/// Path to the cross-compilation Swift SDKs directory.
211-
public let sharedSwiftSDKsDirectory: AbsolutePath?
211+
public let sharedSwiftSDKsDirectory: AbsolutePath
212212

213213
/// Cancellator to handle cancellation of outstanding work when handling SIGINT
214214
public let cancellator: Cancellator
@@ -747,11 +747,11 @@ public final class SwiftTool {
747747
let hostTriple = hostToolchain.targetTriple
748748

749749
// Create custom toolchain if present.
750-
if let customDestination = options.locations.customCompileDestination {
750+
if let customDestination = self.options.locations.customCompileDestination {
751751
let swiftSDKs = try SwiftSDK.decode(
752752
fromFile: customDestination,
753-
fileSystem: fileSystem,
754-
observabilityScope: observabilityScope
753+
fileSystem: self.fileSystem,
754+
observabilityScope: self.observabilityScope
755755
)
756756
if swiftSDKs.count == 1 {
757757
swiftSDK = swiftSDKs[0]
@@ -768,13 +768,13 @@ public final class SwiftTool {
768768
{
769769
swiftSDK = targetSwiftSDK
770770
} else if let swiftSDKSelector = options.build.swiftSDKSelector {
771-
swiftSDK = try SwiftSDKBundle.selectBundle(
772-
fromBundlesAt: sharedSwiftSDKsDirectory,
773-
fileSystem: fileSystem,
774-
matching: swiftSDKSelector,
775-
hostTriple: hostTriple,
776-
observabilityScope: observabilityScope
771+
let store = SwiftSDKBundleStore(
772+
swiftSDKsDirectory: self.sharedSwiftSDKsDirectory,
773+
fileSystem: self.fileSystem,
774+
observabilityScope: self.observabilityScope,
775+
outputHandler: { print($0.description) }
777776
)
777+
swiftSDK = try store.selectBundle(matching: swiftSDKSelector, hostTriple: hostTriple)
778778
} else {
779779
// Otherwise use the host toolchain.
780780
swiftSDK = hostSwiftSDK
@@ -824,7 +824,7 @@ public final class SwiftTool {
824824
case (false, .local):
825825
cachePath = self.scratchDirectory
826826
case (false, .shared):
827-
cachePath = self.sharedCacheDirectory.map{ Workspace.DefaultLocations.manifestsDirectory(at: $0) }
827+
cachePath = Workspace.DefaultLocations.manifestsDirectory(at: self.sharedCacheDirectory)
828828
}
829829

830830
var extraManifestFlags = self.options.build.manifestFlags
@@ -876,7 +876,7 @@ private func findPackageRoot(fileSystem: FileSystem) -> AbsolutePath? {
876876
return root
877877
}
878878

879-
private func getSharedSecurityDirectory(options: GlobalOptions, fileSystem: FileSystem) throws -> AbsolutePath? {
879+
private func getSharedSecurityDirectory(options: GlobalOptions, fileSystem: FileSystem) throws -> AbsolutePath {
880880
if let explicitSecurityDirectory = options.locations.securityDirectory {
881881
// Create the explicit security path if necessary
882882
if !fileSystem.exists(explicitSecurityDirectory) {
@@ -889,7 +889,7 @@ private func getSharedSecurityDirectory(options: GlobalOptions, fileSystem: File
889889
}
890890
}
891891

892-
private func getSharedConfigurationDirectory(options: GlobalOptions, fileSystem: FileSystem) throws -> AbsolutePath? {
892+
private func getSharedConfigurationDirectory(options: GlobalOptions, fileSystem: FileSystem) throws -> AbsolutePath {
893893
if let explicitConfigurationDirectory = options.locations.configurationDirectory {
894894
// Create the explicit config path if necessary
895895
if !fileSystem.exists(explicitConfigurationDirectory) {
@@ -902,7 +902,7 @@ private func getSharedConfigurationDirectory(options: GlobalOptions, fileSystem:
902902
}
903903
}
904904

905-
private func getSharedCacheDirectory(options: GlobalOptions, fileSystem: FileSystem) throws -> AbsolutePath? {
905+
private func getSharedCacheDirectory(options: GlobalOptions, fileSystem: FileSystem) throws -> AbsolutePath {
906906
if let explicitCacheDirectory = options.locations.cacheDirectory {
907907
// Create the explicit cache path if necessary
908908
if !fileSystem.exists(explicitCacheDirectory) {

Sources/PackageModel/ArtifactsArchiveMetadata.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Foundation
1515

1616
import struct TSCUtility.Version
1717

18+
public let artifactBundleExtension = "artifactbundle"
19+
1820
public struct ArtifactsArchiveMetadata: Equatable {
1921
public let schemaVersion: String
2022
public let artifacts: [String: Artifact]

Sources/PackageModel/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ add_library(PackageModel
4343
Sources.swift
4444
SupportedLanguageExtension.swift
4545
SwiftLanguageVersion.swift
46-
SwiftSDK.swift
47-
SwiftSDKConfigurationStore.swift
48-
SwiftSDKBundle.swift
46+
SwiftSDKs/SwiftSDK.swift
47+
SwiftSDKs/SwiftSDKConfigurationStore.swift
48+
SwiftSDKs/SwiftSDKBundle.swift
49+
SwiftSDKs/SwiftSDKBundleStore.swift
4950
Target/BinaryTarget.swift
5051
Target/ClangTarget.swift
5152
Target/PluginTarget.swift

0 commit comments

Comments
 (0)