Skip to content

Commit 5b1fe44

Browse files
Fix non-tarballed SDK installation with remote URL (#7312)
### Motivation: 4714ea9 introduced a regression where non-tarball SDKs could not be installed from a remote URL due to the wrong assumption that the downloaded file would always be a tarball. This issue exists in 5.10 release branch, so will cherry-pick after merging this PR. ### Modifications: This commit fixes the issue by checking the file extension part of the URL for every supported archive format, then falling back to the tarball format if no supported extension is found. ### Result: Non-tarball SDK artifact bundles can be installed from remote URL.
1 parent 8817ad5 commit 5b1fe44

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed
1.03 KB
Binary file not shown.

Sources/PackageModel/SwiftSDKs/SwiftSDKBundleStore.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ public final class SwiftSDKBundleStore {
151151
{
152152
let bundleName: String
153153
let fileNameComponent = bundleURL.lastPathComponent
154-
if fileNameComponent.hasSuffix(".tar.gz") {
154+
if archiver.supportedExtensions.contains(where: { fileNameComponent.hasSuffix($0) }) {
155155
bundleName = fileNameComponent
156156
} else {
157+
// Assume that the bundle is a tarball if it doesn't have a recognized extension.
157158
bundleName = "bundle.tar.gz"
158159
}
159160
let downloadedBundlePath = temporaryDirectory.appending(component: bundleName)

Tests/PackageModelTests/SwiftSDKBundleTests.swift

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ private func generateTestFileSystem(bundleArtifacts: [MockArtifact]) throws -> (
129129
private let arm64Triple = try! Triple("arm64-apple-macosx13.0")
130130
private let i686Triple = try! Triple("i686-apple-macosx13.0")
131131

132-
private let fixtureArchivePath = try! AbsolutePath(validating: #file)
132+
private let fixtureSDKsPath = try! AbsolutePath(validating: #file)
133133
.parentDirectory
134134
.parentDirectory
135135
.parentDirectory
136-
.appending(components: ["Fixtures", "SwiftSDKs", "test-sdk.artifactbundle.tar.gz"])
136+
.appending(components: ["Fixtures", "SwiftSDKs"])
137137

138138
final class SwiftSDKBundleTests: XCTestCase {
139139
func testInstallRemote() async throws {
@@ -142,43 +142,51 @@ final class SwiftSDKBundleTests: XCTestCase {
142142
#endif
143143

144144
let system = ObservabilitySystem.makeForTesting()
145-
var output = [SwiftSDKBundleStore.Output]()
146145
let observabilityScope = system.topScope
147146
let cancellator = Cancellator(observabilityScope: observabilityScope)
148147
let archiver = UniversalArchiver(localFileSystem, cancellator)
149148

150-
let httpClient = HTTPClient { request, _ in
151-
guard case let .download(_, downloadPath) = request.kind else {
152-
XCTFail("Unexpected HTTPClient.Request.Kind")
153-
return .init(statusCode: 400)
149+
let fixtureAndURLs: [(url: String, fixture: String)] = [
150+
("https://localhost/archive?test=foo", "test-sdk.artifactbundle.tar.gz"),
151+
("https://localhost/archive.tar.gz", "test-sdk.artifactbundle.tar.gz"),
152+
("https://localhost/archive.zip", "test-sdk.artifactbundle.zip"),
153+
]
154+
155+
for (bundleURLString, fixture) in fixtureAndURLs {
156+
let httpClient = HTTPClient { request, _ in
157+
guard case let .download(_, downloadPath) = request.kind else {
158+
XCTFail("Unexpected HTTPClient.Request.Kind")
159+
return .init(statusCode: 400)
160+
}
161+
let fixturePath = fixtureSDKsPath.appending(component: fixture)
162+
try localFileSystem.copy(from: fixturePath, to: downloadPath)
163+
return .init(statusCode: 200)
154164
}
155-
try localFileSystem.copy(from: fixtureArchivePath, to: downloadPath)
156-
return .init(statusCode: 200)
157-
}
158165

159-
try await withTemporaryDirectory(fileSystem: localFileSystem, removeTreeOnDeinit: true) { tmpDir in
160-
let store = SwiftSDKBundleStore(
161-
swiftSDKsDirectory: tmpDir,
162-
fileSystem: localFileSystem,
163-
observabilityScope: observabilityScope,
164-
outputHandler: {
165-
output.append($0)
166-
}
167-
)
168-
let bundleURLString = "https://localhost/archive?test=foo"
169-
try await store.install(bundlePathOrURL: bundleURLString, archiver, httpClient)
170-
171-
let bundleURL = URL(string: bundleURLString)!
172-
XCTAssertEqual(output, [
173-
.downloadStarted(bundleURL),
174-
.downloadFinishedSuccessfully(bundleURL),
175-
.unpackingArchive(bundlePathOrURL: bundleURLString),
176-
.installationSuccessful(
177-
bundlePathOrURL: bundleURLString,
178-
bundleName: "test-sdk.artifactbundle"
179-
),
180-
])
181-
}.value
166+
try await withTemporaryDirectory(fileSystem: localFileSystem, removeTreeOnDeinit: true) { tmpDir in
167+
var output = [SwiftSDKBundleStore.Output]()
168+
let store = SwiftSDKBundleStore(
169+
swiftSDKsDirectory: tmpDir,
170+
fileSystem: localFileSystem,
171+
observabilityScope: observabilityScope,
172+
outputHandler: {
173+
output.append($0)
174+
}
175+
)
176+
try await store.install(bundlePathOrURL: bundleURLString, archiver, httpClient)
177+
178+
let bundleURL = URL(string: bundleURLString)!
179+
XCTAssertEqual(output, [
180+
.downloadStarted(bundleURL),
181+
.downloadFinishedSuccessfully(bundleURL),
182+
.unpackingArchive(bundlePathOrURL: bundleURLString),
183+
.installationSuccessful(
184+
bundlePathOrURL: bundleURLString,
185+
bundleName: "test-sdk.artifactbundle"
186+
),
187+
])
188+
}.value
189+
}
182190
}
183191

184192
func testInstall() async throws {

0 commit comments

Comments
 (0)