Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.10] Fix non-tarballed SDK installation with remote URL (#7312) #7321

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added Fixtures/SwiftSDKs/test-sdk.artifactbundle.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion Sources/PackageModel/SwiftSDKs/SwiftSDKBundleStore.swift
Expand Up @@ -151,9 +151,10 @@ public final class SwiftSDKBundleStore {
{
let bundleName: String
let fileNameComponent = bundleURL.lastPathComponent
if fileNameComponent.hasSuffix(".tar.gz") {
if archiver.supportedExtensions.contains(where: { fileNameComponent.hasSuffix($0) }) {
bundleName = fileNameComponent
} else {
// Assume that the bundle is a tarball if it doesn't have a recognized extension.
bundleName = "bundle.tar.gz"
}
let downloadedBundlePath = temporaryDirectory.appending(component: bundleName)
Expand Down
74 changes: 41 additions & 33 deletions Tests/PackageModelTests/SwiftSDKBundleTests.swift
Expand Up @@ -113,11 +113,11 @@ private func generateTestFileSystem(bundleArtifacts: [MockArtifact]) throws -> (
private let arm64Triple = try! Triple("arm64-apple-macosx13.0")
private let i686Triple = try! Triple("i686-apple-macosx13.0")

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

final class SwiftSDKBundleTests: XCTestCase {
func testInstallRemote() async throws {
Expand All @@ -126,43 +126,51 @@ final class SwiftSDKBundleTests: XCTestCase {
#endif

let system = ObservabilitySystem.makeForTesting()
var output = [SwiftSDKBundleStore.Output]()
let observabilityScope = system.topScope
let cancellator = Cancellator(observabilityScope: observabilityScope)
let archiver = UniversalArchiver(localFileSystem, cancellator)

let httpClient = HTTPClient { request, _ in
guard case let .download(_, downloadPath) = request.kind else {
XCTFail("Unexpected HTTPClient.Request.Kind")
return .init(statusCode: 400)
let fixtureAndURLs: [(url: String, fixture: String)] = [
("https://localhost/archive?test=foo", "test-sdk.artifactbundle.tar.gz"),
("https://localhost/archive.tar.gz", "test-sdk.artifactbundle.tar.gz"),
("https://localhost/archive.zip", "test-sdk.artifactbundle.zip"),
]

for (bundleURLString, fixture) in fixtureAndURLs {
let httpClient = HTTPClient { request, _ in
guard case let .download(_, downloadPath) = request.kind else {
XCTFail("Unexpected HTTPClient.Request.Kind")
return .init(statusCode: 400)
}
let fixturePath = fixtureSDKsPath.appending(component: fixture)
try localFileSystem.copy(from: fixturePath, to: downloadPath)
return .init(statusCode: 200)
}
try localFileSystem.copy(from: fixtureArchivePath, to: downloadPath)
return .init(statusCode: 200)
}

try await withTemporaryDirectory(fileSystem: localFileSystem, removeTreeOnDeinit: true) { tmpDir in
let store = SwiftSDKBundleStore(
swiftSDKsDirectory: tmpDir,
fileSystem: localFileSystem,
observabilityScope: observabilityScope,
outputHandler: {
output.append($0)
}
)
let bundleURLString = "https://localhost/archive?test=foo"
try await store.install(bundlePathOrURL: bundleURLString, archiver, httpClient)

let bundleURL = URL(string: bundleURLString)!
XCTAssertEqual(output, [
.downloadStarted(bundleURL),
.downloadFinishedSuccessfully(bundleURL),
.unpackingArchive(bundlePathOrURL: bundleURLString),
.installationSuccessful(
bundlePathOrURL: bundleURLString,
bundleName: "test-sdk.artifactbundle"
),
])
}.value
try await withTemporaryDirectory(fileSystem: localFileSystem, removeTreeOnDeinit: true) { tmpDir in
var output = [SwiftSDKBundleStore.Output]()
let store = SwiftSDKBundleStore(
swiftSDKsDirectory: tmpDir,
fileSystem: localFileSystem,
observabilityScope: observabilityScope,
outputHandler: {
output.append($0)
}
)
try await store.install(bundlePathOrURL: bundleURLString, archiver, httpClient)

let bundleURL = URL(string: bundleURLString)!
XCTAssertEqual(output, [
.downloadStarted(bundleURL),
.downloadFinishedSuccessfully(bundleURL),
.unpackingArchive(bundlePathOrURL: bundleURLString),
.installationSuccessful(
bundlePathOrURL: bundleURLString,
bundleName: "test-sdk.artifactbundle"
),
])
}.value
}
}

func testInstall() async throws {
Expand Down