@@ -582,16 +582,19 @@ final class SwiftDriverTests: XCTestCase {
582
582
let diags = DiagnosticsEngine ( )
583
583
let fooPath = path. appending ( component: " foo.rsp " )
584
584
let barPath = path. appending ( component: " bar.rsp " )
585
+ let notAFilePath = path. appending ( component: " nonexistent.rsp " )
585
586
try localFileSystem. writeFileContents ( fooPath) {
586
587
$0 <<< " hello \n bye \n bye \\ to \\ you \n @ \( barPath. pathString) "
587
588
}
588
589
try localFileSystem. writeFileContents ( barPath) {
589
- $0 <<< " from \n bar \n @ \( fooPath. pathString) "
590
+ $0 <<< " from \n bar \n @ \( fooPath. pathString) \n @ \( notAFilePath . pathString ) "
590
591
}
591
592
let args = try Driver . expandResponseFiles ( [ " swift " , " compiler " , " -Xlinker " , " @loader_path " , " @ " + fooPath. pathString, " something " ] , diagnosticsEngine: diags)
592
593
XCTAssertEqual ( args, [ " swift " , " compiler " , " -Xlinker " , " @loader_path " , " hello " , " bye " , " bye to you " , " from " , " bar " , " something " ] )
593
- XCTAssertEqual ( diags. diagnostics. count, 1 )
594
+ XCTAssertEqual ( diags. diagnostics. count, 2 )
594
595
XCTAssert ( diags. diagnostics. first!. description. contains ( " is recursively expanded " ) )
596
+ // FIXME: Error message about nonexistent response file could be improved
597
+ XCTAssertEqual ( diags. diagnostics [ 1 ] . description, " noEntry " )
595
598
}
596
599
}
597
600
@@ -610,7 +613,6 @@ final class SwiftDriverTests: XCTestCase {
610
613
// this is another comment
611
614
but this is \\\\\a command
612
615
@ \#( barPath. pathString)
613
- @NotAFile
614
616
-flag="quoted string with a \"quote\" inside" -another-flag
615
617
"""#
616
618
<<< " \n this line \t has lots \t of whitespace "
@@ -634,7 +636,7 @@ final class SwiftDriverTests: XCTestCase {
634
636
$0 <<< " swift \n --driver-mode=swiftc \n -v \r \n //comment \n \" the end \" "
635
637
}
636
638
let args = try Driver . expandResponseFiles ( [ " @ " + fooPath. pathString] , diagnosticsEngine: diags)
637
- XCTAssertEqual ( args, [ " Command1 " , " --kkc " , " but " , " this " , " is " , #"\\a"# , " command " , #"swift"# , " rocks! " , " compiler " , " -Xlinker " , " @loader_path " , " mkdir " , " Quoted Dir " , " cd " , " Unquoted Dir " , " @NotAFile " , #"-flag=quoted string with a "quote" inside"# , " -another-flag " , " this " , " line " , " has " , " lots " , " of " , " whitespace " ] )
639
+ XCTAssertEqual ( args, [ " Command1 " , " --kkc " , " but " , " this " , " is " , #"\\a"# , " command " , #"swift"# , " rocks! " , " compiler " , " -Xlinker " , " @loader_path " , " mkdir " , " Quoted Dir " , " cd " , " Unquoted Dir " , #"-flag=quoted string with a "quote" inside"# , " -another-flag " , " this " , " line " , " has " , " lots " , " of " , " whitespace " ] )
638
640
let escapingArgs = try Driver . expandResponseFiles ( [ " @ " + escapingPath. pathString] , diagnosticsEngine: diags)
639
641
XCTAssertEqual ( escapingArgs, [ " swift " , " --driver-mode=swiftc " , " -v " , " the end " ] )
640
642
}
@@ -685,6 +687,67 @@ final class SwiftDriverTests: XCTestCase {
685
687
}
686
688
}
687
689
690
+ func testResponseFileExpansionIgnoresForwarded( ) throws {
691
+ try withTemporaryDirectory { path in
692
+ try assertNoDiagnostics { diags in
693
+ let forwardedRsp = path. appending ( component: " foo.rsp " )
694
+ let barPath = path. appending ( component: " bar.rsp " )
695
+ let nonexisting = path. appending ( component: " nonexiting.rsp " )
696
+ try localFileSystem. writeFileContents ( forwardedRsp) {
697
+ $0 <<< " should_not_appear_in_args "
698
+ }
699
+ try localFileSystem. writeFileContents ( barPath) {
700
+ $0 <<< """
701
+ -Xcc @ \( forwardedRsp. pathString)
702
+ -Xclang-linker @ \( forwardedRsp. pathString)
703
+ -Xcc @ \( nonexisting. pathString)
704
+ -Xclang-linker @ \( nonexisting. pathString)
705
+ """
706
+ }
707
+ let args = try Driver . expandResponseFiles ( [
708
+ " swift " , " compiler " ,
709
+ " -Xlinker " , " @ \( nonexisting. pathString) " ,
710
+ " -Xfrontend " , " @ \( forwardedRsp. pathString) " ,
711
+ " @ \( barPath. pathString) " ,
712
+ ] , diagnosticsEngine: diags)
713
+ XCTAssertEqual ( args, [
714
+ " swift " , " compiler " ,
715
+ " -Xlinker " , " @ \( nonexisting. pathString) " ,
716
+ " -Xfrontend " , " @ \( forwardedRsp. pathString) " ,
717
+ " -Xcc " , " @ \( forwardedRsp. pathString) " ,
718
+ " -Xclang-linker " , " @ \( forwardedRsp. pathString) " ,
719
+ " -Xcc " , " @ \( nonexisting. pathString) " ,
720
+ " -Xclang-linker " , " @ \( nonexisting. pathString) " ,
721
+ ] )
722
+ }
723
+ }
724
+ }
725
+
726
+ func testResponseFile( ) throws {
727
+ try withTemporaryDirectory { path in
728
+ guard let cwd = localFileSystem
729
+ . currentWorkingDirectory else { fatalError ( ) }
730
+ let responseFile1 = path. appending ( component: " fileList1.rsp " )
731
+ let responseFile2 = path. appending ( component: " fileList2.rsp " )
732
+ try localFileSystem. writeFileContents ( responseFile1) {
733
+ $0 <<< " from1stList.swift "
734
+ }
735
+ try localFileSystem. writeFileContents ( responseFile2) {
736
+ $0 <<< " from2ndList.swift "
737
+ }
738
+ let responseFile2Relative = responseFile2. relative ( to: cwd)
739
+ let driver = try Driver ( args: [
740
+ " swiftc " ,
741
+ " @ \( responseFile1. pathString) " ,
742
+ " @ \( responseFile2Relative) " ,
743
+ ] )
744
+ XCTAssertEqual ( driver. inputFiles, [
745
+ . init( file: . relative( . init( " from1stList.swift " ) ) , type: . swift) ,
746
+ . init( file: . relative( . init( " from2ndList.swift " ) ) , type: . swift) ,
747
+ ] )
748
+ }
749
+ }
750
+
688
751
func testLinking( ) throws {
689
752
var env = ProcessEnv . vars
690
753
env [ " SWIFT_DRIVER_TESTS_ENABLE_EXEC_PATH_FALLBACK " ] = " 1 "
0 commit comments