@@ -591,16 +591,19 @@ final class SwiftDriverTests: XCTestCase {
591
591
let diags = DiagnosticsEngine ( )
592
592
let fooPath = path. appending ( component: " foo.rsp " )
593
593
let barPath = path. appending ( component: " bar.rsp " )
594
+ let notAFilePath = path. appending ( component: " nonexistent.rsp " )
594
595
try localFileSystem. writeFileContents ( fooPath) {
595
596
$0 <<< " hello \n bye \n bye \\ to \\ you \n @ \( barPath. pathString) "
596
597
}
597
598
try localFileSystem. writeFileContents ( barPath) {
598
- $0 <<< " from \n bar \n @ \( fooPath. pathString) "
599
+ $0 <<< " from \n bar \n @ \( fooPath. pathString) \n @ \( notAFilePath . pathString ) "
599
600
}
600
601
let args = try Driver . expandResponseFiles ( [ " swift " , " compiler " , " -Xlinker " , " @loader_path " , " @ " + fooPath. pathString, " something " ] , diagnosticsEngine: diags)
601
602
XCTAssertEqual ( args, [ " swift " , " compiler " , " -Xlinker " , " @loader_path " , " hello " , " bye " , " bye to you " , " from " , " bar " , " something " ] )
602
- XCTAssertEqual ( diags. diagnostics. count, 1 )
603
+ XCTAssertEqual ( diags. diagnostics. count, 2 )
603
604
XCTAssert ( diags. diagnostics. first!. description. contains ( " is recursively expanded " ) )
605
+ // FIXME: Error message about nonexistent response file could be improved
606
+ XCTAssertEqual ( diags. diagnostics [ 1 ] . description, " noEntry " )
604
607
}
605
608
}
606
609
@@ -619,7 +622,6 @@ final class SwiftDriverTests: XCTestCase {
619
622
// this is another comment
620
623
but this is \\\\\a command
621
624
@ \#( barPath. pathString)
622
- @NotAFile
623
625
-flag="quoted string with a \"quote\" inside" -another-flag
624
626
"""#
625
627
<<< " \n this line \t has lots \t of whitespace "
@@ -643,7 +645,7 @@ final class SwiftDriverTests: XCTestCase {
643
645
$0 <<< " swift \n --driver-mode=swiftc \n -v \r \n //comment \n \" the end \" "
644
646
}
645
647
let args = try Driver . expandResponseFiles ( [ " @ " + fooPath. pathString] , diagnosticsEngine: diags)
646
- 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 " ] )
648
+ 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 " ] )
647
649
let escapingArgs = try Driver . expandResponseFiles ( [ " @ " + escapingPath. pathString] , diagnosticsEngine: diags)
648
650
XCTAssertEqual ( escapingArgs, [ " swift " , " --driver-mode=swiftc " , " -v " , " the end " ] )
649
651
}
@@ -694,6 +696,67 @@ final class SwiftDriverTests: XCTestCase {
694
696
}
695
697
}
696
698
699
+ func testResponseFileExpansionIgnoresForwarded( ) throws {
700
+ try withTemporaryDirectory { path in
701
+ try assertNoDiagnostics { diags in
702
+ let forwardedRsp = path. appending ( component: " foo.rsp " )
703
+ let barPath = path. appending ( component: " bar.rsp " )
704
+ let nonexisting = path. appending ( component: " nonexiting.rsp " )
705
+ try localFileSystem. writeFileContents ( forwardedRsp) {
706
+ $0 <<< " should_not_appear_in_args "
707
+ }
708
+ try localFileSystem. writeFileContents ( barPath) {
709
+ $0 <<< """
710
+ -Xcc @ \( forwardedRsp. pathString)
711
+ -Xclang-linker @ \( forwardedRsp. pathString)
712
+ -Xcc @ \( nonexisting. pathString)
713
+ -Xclang-linker @ \( nonexisting. pathString)
714
+ """
715
+ }
716
+ let args = try Driver . expandResponseFiles ( [
717
+ " swift " , " compiler " ,
718
+ " -Xlinker " , " @ \( nonexisting. pathString) " ,
719
+ " -Xfrontend " , " @ \( forwardedRsp. pathString) " ,
720
+ " @ \( barPath. pathString) " ,
721
+ ] , diagnosticsEngine: diags)
722
+ XCTAssertEqual ( args, [
723
+ " swift " , " compiler " ,
724
+ " -Xlinker " , " @ \( nonexisting. pathString) " ,
725
+ " -Xfrontend " , " @ \( forwardedRsp. pathString) " ,
726
+ " -Xcc " , " @ \( forwardedRsp. pathString) " ,
727
+ " -Xclang-linker " , " @ \( forwardedRsp. pathString) " ,
728
+ " -Xcc " , " @ \( nonexisting. pathString) " ,
729
+ " -Xclang-linker " , " @ \( nonexisting. pathString) " ,
730
+ ] )
731
+ }
732
+ }
733
+ }
734
+
735
+ func testResponseFile( ) throws {
736
+ try withTemporaryDirectory { path in
737
+ guard let cwd = localFileSystem
738
+ . currentWorkingDirectory else { fatalError ( ) }
739
+ let responseFile1 = path. appending ( component: " fileList1.rsp " )
740
+ let responseFile2 = path. appending ( component: " fileList2.rsp " )
741
+ try localFileSystem. writeFileContents ( responseFile1) {
742
+ $0 <<< " from1stList.swift "
743
+ }
744
+ try localFileSystem. writeFileContents ( responseFile2) {
745
+ $0 <<< " from2ndList.swift "
746
+ }
747
+ let responseFile2Relative = responseFile2. relative ( to: cwd)
748
+ let driver = try Driver ( args: [
749
+ " swiftc " ,
750
+ " @ \( responseFile1. pathString) " ,
751
+ " @ \( responseFile2Relative) " ,
752
+ ] )
753
+ XCTAssertEqual ( driver. inputFiles, [
754
+ . init( file: . relative( . init( " from1stList.swift " ) ) , type: . swift) ,
755
+ . init( file: . relative( . init( " from2ndList.swift " ) ) , type: . swift) ,
756
+ ] )
757
+ }
758
+ }
759
+
697
760
func testLinking( ) throws {
698
761
var env = ProcessEnv . vars
699
762
env [ " SWIFT_DRIVER_TESTS_ENABLE_EXEC_PATH_FALLBACK " ] = " 1 "
0 commit comments