@@ -536,8 +536,12 @@ final class JobExecutorTests: XCTestCase {
536536 executor: executor)
537537 let jobs = try driver. planBuild ( )
538538 XCTAssertEqual ( jobs. removingAutolinkExtractJobs ( ) . map ( \. kind) , [ . compile, . link] )
539- XCTAssertEqual ( jobs [ 0 ] . outputs. count, 1 )
540- let compileOutput = jobs [ 0 ] . outputs [ 0 ] . file
539+ // With -save-temps, we now have additional SIL and IR outputs, so expect more outputs
540+ XCTAssertTrue ( jobs [ 0 ] . outputs. count >= 1 , " Should have at least the object file output " )
541+ // Find the main object file output
542+ let objectOutput = jobs [ 0 ] . outputs. first { $0. type == . object }
543+ XCTAssertNotNil ( objectOutput, " Should have object file output " )
544+ let compileOutput = objectOutput!. file
541545 guard matchTemporary ( compileOutput, " main.o " ) else {
542546 XCTFail ( " unexpected output " )
543547 return
@@ -585,5 +589,53 @@ final class JobExecutorTests: XCTestCase {
585589 )
586590 }
587591 }
592+
593+ // Test that -save-temps also saves SIL and IR intermediate files
594+ do {
595+ // Skip test if frontend doesn't support these options
596+ let diags = DiagnosticsEngine ( )
597+ let executor = try SwiftDriverExecutor ( diagnosticsEngine: diags,
598+ processSet: ProcessSet ( ) ,
599+ fileSystem: localFileSystem,
600+ env: ProcessEnv . block)
601+ let checkDriver = try Driver ( args: [ " swiftc " , " foo.swift " ] + getHostToolchainSdkArg( executor) ,
602+ envBlock: ProcessEnv . block,
603+ diagnosticsOutput: . engine( diags) ,
604+ fileSystem: localFileSystem,
605+ executor: executor)
606+ guard Driver . isOptionFound ( " -sil-output-path " , allOpts: checkDriver. supportedFrontendFlags) &&
607+ Driver . isOptionFound ( " -ir-output-path " , allOpts: checkDriver. supportedFrontendFlags) else {
608+ throw XCTSkip ( " Skipping: frontend does not support -sil-output-path or -ir-output-path " )
609+ }
610+
611+ try withTemporaryDirectory { path in
612+ let main = path. appending ( component: " main.swift " )
613+ try localFileSystem. writeFileContents ( main, bytes: " print( \" hello, world! \" ) " )
614+ let diags = DiagnosticsEngine ( )
615+ let executor = try SwiftDriverExecutor ( diagnosticsEngine: diags,
616+ processSet: ProcessSet ( ) ,
617+ fileSystem: localFileSystem,
618+ env: ProcessEnv . block)
619+ let outputPath = path. appending ( component: " finalOutput " )
620+ var driver = try Driver ( args: [ " swiftc " , main. pathString,
621+ " -save-temps " ,
622+ " -o " , outputPath. pathString] + getHostToolchainSdkArg( executor) ,
623+ envBlock: ProcessEnv . block,
624+ diagnosticsOutput: . engine( diags) ,
625+ fileSystem: localFileSystem,
626+ executor: executor)
627+ let jobs = try driver. planBuild ( )
628+ let compileJobs = jobs. removingAutolinkExtractJobs ( )
629+ XCTAssertEqual ( compileJobs. map ( \. kind) , [ . compile, . link] )
630+
631+ let compileJob = compileJobs [ 0 ]
632+
633+ XCTAssertTrue ( compileJob. commandLine. contains ( . flag( " -sil-output-path " ) ) )
634+ XCTAssertTrue ( compileJob. commandLine. contains ( . flag( " -ir-output-path " ) ) )
635+
636+ let hasMultipleOutputs = compileJob. outputs. count > 1
637+ XCTAssertTrue ( hasMultipleOutputs, " Should have additional SIL/IR outputs when using -save-temps " )
638+ }
639+ }
588640 }
589641}
0 commit comments