@@ -134,7 +134,9 @@ struct SetupCacheTests {
134134 // MARK: - Store / Load
135135
136136 /// Create a fake build artifacts directory that matches expected compiler flags.
137- private func makeArtifacts( packageDir: URL , moduleName: String ) throws -> [ String ] {
137+ private func makeArtifacts( packageDir: URL , moduleName: String ) throws
138+ -> ( flags: [ String ] , dylibPath: URL )
139+ {
138140 let buildDir = packageDir. appendingPathComponent ( " .build/debug " )
139141 let modulesDir = buildDir. appendingPathComponent ( " Modules " )
140142 try FileManager . default. createDirectory (
@@ -147,11 +149,14 @@ struct SetupCacheTests {
147149 try Data ( " fake " . utf8) . write (
148150 to: swiftmoduleDir. appendingPathComponent ( " arm64-apple-macos.swiftmodule " ) )
149151
150- // Create static library
151- try Data ( " fake " . utf8 ) . write (
152- to : buildDir . appendingPathComponent ( " lib \( moduleName ) .a " ) )
152+ // Create setup dylib
153+ let dylibPath = buildDir . appendingPathComponent ( " libPreviewSetup.dylib " )
154+ try Data ( " fake " . utf8 ) . write ( to : dylibPath )
153155
154- return [ " -I " , modulesDir. path, " -L " , buildDir. path, " -l \( moduleName) " ]
156+ return (
157+ flags: [ " -I " , modulesDir. path, " -L " , buildDir. path, " -lPreviewSetup " ] ,
158+ dylibPath: dylibPath
159+ )
155160 }
156161
157162 @Test ( " load returns nil when no cache file exists " )
@@ -191,7 +196,8 @@ struct SetupCacheTests {
191196 // Store a valid entry with flags pointing to non-existent paths
192197 let fakeResult = SetupBuilder . Result (
193198 moduleName: " TestSetup " , typeName: " Setup " ,
194- compilerFlags: [ " -I " , " /nonexistent/Modules " , " -L " , " /nonexistent " ] )
199+ compilerFlags: [ " -I " , " /nonexistent/Modules " , " -L " , " /nonexistent " ] ,
200+ dylibPath: URL ( fileURLWithPath: " /nonexistent/libPreviewSetup.dylib " ) )
195201 SetupCache . store (
196202 fakeResult, packageDir: dir, platform: . macOS,
197203 sourceHash: " abc123 " , swiftVersion: " Swift 6.0 " )
@@ -216,13 +222,20 @@ struct SetupCacheTests {
216222 try Data ( " fake " . utf8) . write (
217223 to: swiftmoduleDir. appendingPathComponent ( " arm64.swiftmodule " ) )
218224
225+ let dylibPath = buildDir. appendingPathComponent ( " libPreviewSetup.dylib " )
226+ try Data ( " fake " . utf8) . write ( to: dylibPath)
227+
219228 let fakeResult = SetupBuilder . Result (
220229 moduleName: " TestSetup " , typeName: " Setup " ,
221- compilerFlags: [ " -I " , modulesDir. path, " -L " , buildDir. path, " -lTestSetup " ] )
230+ compilerFlags: [ " -I " , modulesDir. path, " -L " , buildDir. path, " -lPreviewSetup " ] ,
231+ dylibPath: dylibPath)
222232 SetupCache . store (
223233 fakeResult, packageDir: dir, platform: . macOS,
224234 sourceHash: " abc123 " , swiftVersion: " Swift 6.0 " )
225235
236+ // Delete the dylib to simulate missing artifact
237+ try FileManager . default. removeItem ( at: dylibPath)
238+
226239 let loaded = SetupCache . load (
227240 packageDir: dir, platform: . macOS, sourceHash: " abc123 " ,
228241 swiftVersion: " Swift 6.0 " )
@@ -234,9 +247,10 @@ struct SetupCacheTests {
234247 let dir = try makePackageDir ( )
235248 defer { try ? FileManager . default. removeItem ( at: dir) }
236249
237- let flags = try makeArtifacts ( packageDir: dir, moduleName: " TestSetup " )
250+ let ( flags, dylibPath ) = try makeArtifacts ( packageDir: dir, moduleName: " TestSetup " )
238251 let original = SetupBuilder . Result (
239- moduleName: " TestSetup " , typeName: " AppSetup " , compilerFlags: flags)
252+ moduleName: " TestSetup " , typeName: " AppSetup " , compilerFlags: flags,
253+ dylibPath: dylibPath)
240254
241255 SetupCache . store (
242256 original, packageDir: dir, platform: . macOS,
@@ -270,7 +284,8 @@ struct SetupCacheTests {
270284 }
271285
272286 let result = SetupBuilder . Result (
273- moduleName: " Test " , typeName: " Setup " , compilerFlags: [ ] )
287+ moduleName: " Test " , typeName: " Setup " , compilerFlags: [ ] ,
288+ dylibPath: URL ( fileURLWithPath: " /tmp/libPreviewSetup.dylib " ) )
274289 // Should not throw — errors are swallowed
275290 SetupCache . store (
276291 result, packageDir: dir, platform: . macOS,
@@ -284,9 +299,10 @@ struct SetupCacheTests {
284299 let dir = try makePackageDir ( )
285300 defer { try ? FileManager . default. removeItem ( at: dir) }
286301
287- let macFlags = try makeArtifacts ( packageDir: dir, moduleName: " TestSetup " )
302+ let ( macFlags, macDylibPath ) = try makeArtifacts ( packageDir: dir, moduleName: " TestSetup " )
288303 let macResult = SetupBuilder . Result (
289- moduleName: " TestSetup " , typeName: " Setup " , compilerFlags: macFlags)
304+ moduleName: " TestSetup " , typeName: " Setup " , compilerFlags: macFlags,
305+ dylibPath: macDylibPath)
290306
291307 // Create separate iOS artifacts
292308 let iosBuildDir = dir. appendingPathComponent ( " .build/ios-debug " )
@@ -296,11 +312,12 @@ struct SetupCacheTests {
296312 at: iosSwiftmodule, withIntermediateDirectories: true )
297313 try Data ( " fake " . utf8) . write (
298314 to: iosSwiftmodule. appendingPathComponent ( " arm64.swiftmodule " ) )
299- try Data ( " fake " . utf8 ) . write (
300- to : iosBuildDir . appendingPathComponent ( " libTestSetup.a " ) )
301- let iosFlags = [ " -I " , iosModulesDir. path, " -L " , iosBuildDir. path, " -lTestSetup " ]
315+ let iosDylibPath = iosBuildDir . appendingPathComponent ( " libPreviewSetup.dylib " )
316+ try Data ( " fake " . utf8 ) . write ( to : iosDylibPath )
317+ let iosFlags = [ " -I " , iosModulesDir. path, " -L " , iosBuildDir. path, " -lPreviewSetup " ]
302318 let iosResult = SetupBuilder . Result (
303- moduleName: " TestSetup " , typeName: " Setup " , compilerFlags: iosFlags)
319+ moduleName: " TestSetup " , typeName: " Setup " , compilerFlags: iosFlags,
320+ dylibPath: iosDylibPath)
304321
305322 // Store both
306323 SetupCache . store (
0 commit comments