Skip to content

Commit 6ca73f1

Browse files
committed
Remove redundant checkum validation
1 parent e477ac5 commit 6ca73f1

File tree

3 files changed

+3
-112
lines changed

3 files changed

+3
-112
lines changed

Sources/SwiftSDKGenerator/Artifacts/DownloadableArtifacts.swift

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -46,67 +46,11 @@ enum ArtifactOS: Hashable {
4646

4747
typealias CPUMapping = [Triple.CPU: String]
4848

49-
/// SHA256 hashes of binary LLVM artifacts known to the generator.
50-
private let knownLLVMBinariesVersions: [ArtifactOS: [String: CPUMapping]] = [
51-
.macOS: [
52-
"15.0.7": [
53-
Triple.CPU.arm64: "867c6afd41158c132ef05a8f1ddaecf476a26b91c85def8e124414f9a9ba188d",
54-
],
55-
"16.0.0": [
56-
Triple.CPU.arm64: "2041587b90626a4a87f0de14a5842c14c6c3374f42c8ed12726ef017416409d9",
57-
],
58-
"16.0.1": [
59-
Triple.CPU.arm64: "cb487fa991f047dc79ae36430cbb9ef14621c1262075373955b1d97215c75879",
60-
],
61-
"16.0.4": [
62-
Triple.CPU.arm64: "429b8061d620108fee636313df55a0602ea0d14458c6d3873989e6b130a074bd",
63-
],
64-
"16.0.5": [
65-
Triple.CPU.arm64: "1aed0787417dd915f0101503ce1d2719c8820a2c92d4a517bfc4044f72035bcc",
66-
],
67-
],
68-
]
69-
70-
/// SHA256 hashes of binary Swift artifacts known to the generator.
71-
private let knownSwiftBinariesVersions: [ArtifactOS: [String: CPUMapping]] = [
72-
.linux(.ubuntu(.jammy)): [
73-
"5.7.3-RELEASE": [
74-
.arm64: "75003d5a995292ae3f858b767fbb89bc3edee99488f4574468a0e44341aec55b",
75-
],
76-
"5.8-RELEASE": [
77-
.arm64: "12ea2df36f9af0aefa74f0989009683600978f62223e7dd73b627c90c7fe9273",
78-
],
79-
"5.9-RELEASE": [
80-
.arm64: "30b289e02f7e03c380744ea97fdf0e96985dff504b0f09de23e098fdaf6513f3",
81-
.x86_64: "bca015e9d727ca39385d7e5b5399f46302d54a02218d40d1c3063662ffc6b42f",
82-
],
83-
],
84-
.macOS: [
85-
"5.7.3-RELEASE": [
86-
.arm64: "ba3516845eb8f4469a8bb06a273687f05791187324a3843996af32a73a2a687d",
87-
.x86_64: "ba3516845eb8f4469a8bb06a273687f05791187324a3843996af32a73a2a687d",
88-
],
89-
"5.8-RELEASE": [
90-
.arm64: "9b6cc56993652ca222c86a2d6b7b66abbd50bb92cc526efc2b23d47d40002097",
91-
.x86_64: "9b6cc56993652ca222c86a2d6b7b66abbd50bb92cc526efc2b23d47d40002097",
92-
],
93-
"5.9-RELEASE": [
94-
.arm64: "3cf7a4b2f3efcfcb4fef42b6588a7b1c54f7b0f2d0a479f41c3e1620b045f48e",
95-
.x86_64: "3cf7a4b2f3efcfcb4fef42b6588a7b1c54f7b0f2d0a479f41c3e1620b045f48e",
96-
],
97-
],
98-
]
99-
100-
private let knownLLVMSourcesVersions: [String: String] = [
101-
"16.0.5": "37f540124b9cfd4680666e649f557077f9937c9178489cea285a672e714b2863",
102-
]
103-
10449
struct DownloadableArtifacts: Sendable {
10550
@CacheKey
10651
struct Item: Sendable {
10752
let remoteURL: URL
10853
var localPath: FilePath
109-
let checksum: String?
11054
let isPrebuilt: Bool
11155
}
11256

@@ -145,7 +89,6 @@ struct DownloadableArtifacts: Sendable {
14589
),
14690
localPath: paths.artifactsCachePath
14791
.appending("host_swift_\(versions.swiftVersion)_\(hostTriple).pkg"),
148-
checksum: knownSwiftBinariesVersions[hostArtifactsOS]?[versions.swiftVersion]?[hostTriple.cpu],
14992
isPrebuilt: true
15093
)
15194

@@ -161,7 +104,6 @@ struct DownloadableArtifacts: Sendable {
161104
)!,
162105
localPath: paths.artifactsCachePath
163106
.appending("host_llvm_\(versions.lldVersion)_\(hostTriple).tar.xz"),
164-
checksum: knownLLVMBinariesVersions[hostArtifactsOS]?[versions.lldVersion]?[hostTriple.cpu],
165107
isPrebuilt: true
166108
)
167109

@@ -170,7 +112,6 @@ struct DownloadableArtifacts: Sendable {
170112
remoteURL: versions.swiftDownloadURL(),
171113
localPath: paths.artifactsCachePath
172114
.appending("target_swift_\(versions.swiftVersion)_\(targetTriple).tar.gz"),
173-
checksum: knownSwiftBinariesVersions[targetArtifactsOS]?[versions.swiftVersion]?[targetTriple.cpu],
174115
isPrebuilt: true
175116
)
176117

@@ -190,7 +131,6 @@ struct DownloadableArtifacts: Sendable {
190131
)!,
191132
localPath: self.paths.artifactsCachePath
192133
.appending("llvm_\(self.versions.lldVersion).src.tar.xz"),
193-
checksum: knownLLVMSourcesVersions[self.versions.lldVersion],
194134
isPrebuilt: false
195135
)
196136
}

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public extension Triple.CPU {
2626
}
2727
}
2828

29-
extension SwiftSDKGenerator {
30-
public func generateBundle(shouldGenerateFromScratch: Bool) async throws {
29+
public extension SwiftSDKGenerator {
30+
func generateBundle(shouldGenerateFromScratch: Bool) async throws {
3131
var configuration = HTTPClient.Configuration(redirectConfiguration: .follow(max: 5, allowCycles: false))
3232
// Workaround an issue with github.com returning 400 instead of 404 status to HEAD requests from AHC.
3333
configuration.httpVersion = .http1Only
@@ -49,9 +49,7 @@ extension SwiftSDKGenerator {
4949
try createDirectoryIfNeeded(at: pathsConfiguration.sdkDirPath)
5050
try createDirectoryIfNeeded(at: pathsConfiguration.toolchainDirPath)
5151

52-
if try await !self.isCacheValid {
53-
try await self.downloadArtifacts(client)
54-
}
52+
try await self.downloadArtifacts(client)
5553

5654
if !shouldUseDocker {
5755
guard case let .ubuntu(version) = versionsConfiguration.linuxDistribution else {
@@ -102,35 +100,6 @@ extension SwiftSDKGenerator {
102100
"""
103101
)
104102
}
105-
106-
/// Check whether cached downloads for required `DownloadArtifacts.Item` values can be reused instead of downloading
107-
/// them each time the generator is running.
108-
/// - Returns: `true` if artifacts are valid, `false` otherwise.
109-
private var isCacheValid: Bool {
110-
get async throws {
111-
logGenerationStep("Checking packages cache...")
112-
113-
guard downloadableArtifacts.allItems.map(\.localPath).allSatisfy(doesFileExist(at:)) else {
114-
return false
115-
}
116-
117-
return try await withThrowingTaskGroup(of: Bool.self) { taskGroup in
118-
for artifact in downloadableArtifacts.allItems {
119-
taskGroup.addTask {
120-
try await Self.isChecksumValid(artifact: artifact, isVerbose: self.isVerbose)
121-
}
122-
}
123-
124-
for try await isValid in taskGroup {
125-
guard isValid else {
126-
return false
127-
}
128-
}
129-
130-
return true
131-
}
132-
}
133-
}
134103
}
135104

136105
func logGenerationStep(_ message: String) {

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,6 @@ public actor SwiftSDKGenerator {
136136
#endif
137137
}
138138

139-
static func isChecksumValid(artifact: DownloadableArtifacts.Item, isVerbose: Bool) async throws -> Bool {
140-
guard let expectedChecksum = artifact.checksum else { return false }
141-
142-
let computedChecksum = try await String(
143-
Shell.readStdout("openssl dgst -sha256 \(artifact.localPath)", shouldLogCommands: isVerbose)
144-
.split(separator: "= ")[1]
145-
// drop the trailing newline
146-
.dropLast()
147-
)
148-
149-
guard computedChecksum == expectedChecksum else {
150-
print("SHA256 digest of file at `\(artifact.localPath)` does not match expected value: \(expectedChecksum)")
151-
return false
152-
}
153-
154-
return true
155-
}
156-
157139
private func buildDockerImage(name: String, dockerfileDirectory: FilePath) async throws {
158140
try await Shell.run(
159141
"\(Self.dockerCommand) build . -t \(name)",

0 commit comments

Comments
 (0)