Skip to content

Commit dadbc3e

Browse files
authored
tests: Test that an SDK can be rebuilt without cleaning up (#79)
Since #68, rebuilding a RHEL SDK bundle has failed with the following error unless the bundle is first deleted: ``` Error: The file “lib64” couldn’t be saved in the folder “rhel-ubi9.sdk” because a file with the same name already exists. ``` This is because the condition check around the cleanup logic was inverted when the check was moved into `LinuxRecipe.swift`. #### Before: https://github.com/apple/swift-sdk-generator/blob/5428358a282d53e4d714b90c0348a293cca0038d/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator%2BEntrypoint.swift#L51-L52 #### After: https://github.com/apple/swift-sdk-generator/blob/b94744f2b3d89511145072d907a18c9ea6aa5578/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift#L129-L130 This PR adds a test which tries to build an SDK twice without cleaning up in between.
1 parent dd7929d commit dadbc3e

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
126126
httpClient client: HTTPClient
127127
) async throws -> SwiftSDKProduct {
128128
let sdkDirPath = self.sdkDirPath(paths: generator.pathsConfiguration)
129-
if generator.isIncremental {
129+
if !generator.isIncremental {
130130
try await generator.removeRecursively(at: sdkDirPath)
131131
}
132132
try await generator.createDirectoryIfNeeded(at: sdkDirPath)

Tests/SwiftSDKGeneratorTests/EndToEndTests.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,41 @@ final class EndToEndTests: XCTestCase {
100100
}
101101
}
102102
}
103+
104+
func testRepeatedSDKBuilds() async throws {
105+
let fm = FileManager.default
106+
107+
var packageDirectory = FilePath(#file)
108+
packageDirectory.removeLastComponent()
109+
packageDirectory.removeLastComponent()
110+
111+
// Test that an existing SDK can be rebuilt without cleaning up.
112+
// Test with no arguments by default:
113+
var possibleArguments = [""]
114+
do {
115+
try await Shell.run("docker ps")
116+
possibleArguments.append("--with-docker --linux-distribution-name rhel --linux-distribution-version ubi9")
117+
} catch {
118+
self.logger.warning("Docker CLI does not seem to be working, skipping tests that involve Docker.")
119+
}
120+
121+
for runArguments in possibleArguments {
122+
let testPackageURL = FileManager.default.temporaryDirectory.appendingPathComponent("swift-sdk-generator-test")
123+
let testPackageDir = FilePath(testPackageURL.path)
124+
try? fm.removeItem(atPath: testPackageDir.string)
125+
try fm.createDirectory(atPath: testPackageDir.string, withIntermediateDirectories: true)
126+
defer { try? fm.removeItem(atPath: testPackageDir.string) }
127+
128+
let firstGeneratorOutput = try await Shell.readStdout(
129+
"cd \(packageDirectory) && swift run swift-sdk-generator \(runArguments)"
130+
)
131+
XCTAssert(firstGeneratorOutput.contains("swift experimental-sdk install"))
132+
133+
let repeatGeneratorOutput = try await Shell.readStdout(
134+
"cd \(packageDirectory) && swift run swift-sdk-generator \(runArguments)"
135+
)
136+
XCTAssert(repeatGeneratorOutput.contains("swift experimental-sdk install"))
137+
}
138+
}
103139
#endif
104140
}

0 commit comments

Comments
 (0)