@@ -562,7 +562,7 @@ public struct Driver {
562562 swiftCompilerPrefixArgs: self . swiftCompilerPrefixArgs)
563563
564564 // Classify and collect all of the input files.
565- let inputFiles = try Self . collectInputFiles ( & self . parsedOptions, diagnosticsEngine: diagnosticsEngine)
565+ let inputFiles = try Self . collectInputFiles ( & self . parsedOptions, diagnosticsEngine: diagnosticsEngine, fileSystem : self . fileSystem )
566566 self . inputFiles = inputFiles
567567 self . recordedInputModificationDates = . init( uniqueKeysWithValues:
568568 Set ( inputFiles) . compactMap {
@@ -634,6 +634,7 @@ public struct Driver {
634634 fileSystem: fileSystem,
635635 workingDirectory: workingDirectory,
636636 diagnosticEngine: diagnosticEngine)
637+ Self . validateEmitDependencyGraphArgs ( & parsedOptions, diagnosticEngine: diagnosticEngine)
637638 Self . validateParseableOutputArgs ( & parsedOptions, diagnosticEngine: diagnosticEngine)
638639 Self . validateCompilationConditionArgs ( & parsedOptions, diagnosticEngine: diagnosticEngine)
639640 Self . validateFrameworkSearchPathArgs ( & parsedOptions, diagnosticEngine: diagnosticEngine)
@@ -1247,7 +1248,7 @@ extension Driver {
12471248 }
12481249
12491250 /// Expand response files in the input arguments and return a new argument list.
1250- @ _spi ( Testing ) public static func expandResponseFiles(
1251+ public static func expandResponseFiles(
12511252 _ args: [ String ] ,
12521253 fileSystem: FileSystem ,
12531254 diagnosticsEngine: DiagnosticsEngine
@@ -1790,10 +1791,11 @@ extension Driver {
17901791 /// Collect all of the input files from the parsed options, translating them into input files.
17911792 private static func collectInputFiles(
17921793 _ parsedOptions: inout ParsedOptions ,
1793- diagnosticsEngine: DiagnosticsEngine
1794+ diagnosticsEngine: DiagnosticsEngine ,
1795+ fileSystem: FileSystem
17941796 ) throws -> [ TypedVirtualPath ] {
17951797 var swiftFiles = [ String: String] ( ) // [Basename: Path]
1796- return try parsedOptions. allInputs. map { input in
1798+ var paths : [ TypedVirtualPath ] = try parsedOptions. allInputs. map { input in
17971799 // Standard input is assumed to be Swift code.
17981800 if input == " - " {
17991801 return TypedVirtualPath ( file: . standardInput, type: . swift)
@@ -1823,6 +1825,29 @@ extension Driver {
18231825
18241826 return TypedVirtualPath ( file: inputHandle, type: fileType)
18251827 }
1828+
1829+ if parsedOptions. hasArgument ( . e) {
1830+ if let mainPath = swiftFiles [ " main.swift " ] {
1831+ diagnosticsEngine. emit ( . error_two_files_same_name( basename: " main.swift " , firstPath: mainPath, secondPath: " -e " ) )
1832+ diagnosticsEngine. emit ( . note_explain_two_files_same_name)
1833+ throw Diagnostics . fatalError
1834+ }
1835+
1836+ try withTemporaryDirectory ( dir: fileSystem. tempDirectory, removeTreeOnDeinit: false ) { absPath in
1837+ let filePath = VirtualPath . absolute ( absPath. appending ( component: " main.swift " ) )
1838+
1839+ try fileSystem. writeFileContents ( filePath) { file in
1840+ file <<< ###"#sourceLocation(file: "-e", line: 1)\###n"###
1841+ for option in parsedOptions. arguments ( for: . e) {
1842+ file <<< option. argument. asSingle <<< " \n "
1843+ }
1844+ }
1845+
1846+ paths. append ( TypedVirtualPath ( file: filePath. intern ( ) , type: . swift) )
1847+ }
1848+ }
1849+
1850+ return paths
18261851 }
18271852
18281853 /// Determine the primary compiler and linker output kinds.
@@ -2646,6 +2671,28 @@ extension Driver {
26462671 }
26472672 }
26482673
2674+ static func validateEmitDependencyGraphArgs( _ parsedOptions: inout ParsedOptions ,
2675+ diagnosticEngine: DiagnosticsEngine ) {
2676+ // '-print-explicit-dependency-graph' requires '-explicit-module-build'
2677+ if parsedOptions. hasArgument ( . printExplicitDependencyGraph) &&
2678+ !parsedOptions. hasArgument ( . driverExplicitModuleBuild) {
2679+ diagnosticEngine. emit ( Error . optionRequiresAnother ( Option . printExplicitDependencyGraph. spelling,
2680+ Option . driverExplicitModuleBuild. spelling) )
2681+ }
2682+ // '-explicit-dependency-graph-format=' requires '-print-explicit-dependency-graph'
2683+ if parsedOptions. hasArgument ( . explicitDependencyGraphFormat) &&
2684+ !parsedOptions. hasArgument ( . printExplicitDependencyGraph) {
2685+ diagnosticEngine. emit ( Error . optionRequiresAnother ( Option . explicitDependencyGraphFormat. spelling,
2686+ Option . printExplicitDependencyGraph. spelling) )
2687+ }
2688+ // '-explicit-dependency-graph-format=' only supports values 'json' and 'dot'
2689+ if let formatArg = parsedOptions. getLastArgument ( . explicitDependencyGraphFormat) ? . asSingle {
2690+ if formatArg != " json " && formatArg != " dot " {
2691+ diagnosticEngine. emit ( . error_unsupported_argument( argument: formatArg,
2692+ option: . explicitDependencyGraphFormat) )
2693+ }
2694+ }
2695+ }
26492696
26502697 static func validateProfilingArgs( _ parsedOptions: inout ParsedOptions ,
26512698 fileSystem: FileSystem ,
0 commit comments