@@ -250,7 +250,7 @@ public struct Driver {
250
250
self . objcGeneratedHeaderPath = try Self . computeSupplementaryOutputPath ( & parsedOptions, type: . objcHeader, isOutput: . emit_objc_header, outputPath: . emit_objc_header_path, compilerOutputType: compilerOutputType, moduleName: moduleName)
251
251
self . loadedModuleTracePath = try Self . computeSupplementaryOutputPath ( & parsedOptions, type: . moduleTrace, isOutput: . emit_loaded_module_trace, outputPath: . emit_loaded_module_trace_path, compilerOutputType: compilerOutputType, moduleName: moduleName)
252
252
self . tbdPath = try Self . computeSupplementaryOutputPath ( & parsedOptions, type: . tbd, isOutput: . emit_tbd, outputPath: . emit_tbd_path, compilerOutputType: compilerOutputType, moduleName: moduleName)
253
- self . moduleDocOutputPath = try Self . computeSupplementaryOutputPath ( & parsedOptions, type : . swiftDocumentation , isOutput : . emit_module_doc , outputPath: . emit_module_doc_path , compilerOutputType: compilerOutputType, moduleName: moduleName)
253
+ self . moduleDocOutputPath = try Self . computeModuleDocOutputPath ( & parsedOptions, moduleOutputPath : self . moduleOutput ? . outputPath, compilerOutputType: compilerOutputType, moduleName: moduleName)
254
254
self . swiftInterfacePath = try Self . computeSupplementaryOutputPath ( & parsedOptions, type: . swiftInterface, isOutput: . emit_module_interface, outputPath: . emit_module_interface_path, compilerOutputType: compilerOutputType, moduleName: moduleName)
255
255
self . optimizationRecordPath = try Self . computeSupplementaryOutputPath ( & parsedOptions, type: . optimizationRecord, isOutput: . save_optimization_record, outputPath: . save_optimization_record_path, compilerOutputType: compilerOutputType, moduleName: moduleName)
256
256
}
@@ -919,7 +919,8 @@ extension Driver {
919
919
isOutput: Option ? ,
920
920
outputPath: Option ,
921
921
compilerOutputType: FileType ? ,
922
- moduleName: String
922
+ moduleName: String ,
923
+ patternOutputFile: VirtualPath ? = nil
923
924
) throws -> VirtualPath ? {
924
925
// FIXME: Do we need to check the output file map?
925
926
@@ -946,17 +947,56 @@ extension Driver {
946
947
return path
947
948
}
948
949
949
- // Otherwise, put this output alongside the requested output.
950
- let pathString : String
951
- if let ext = path. extension {
952
- pathString = String ( path. name. dropLast ( ext. count + 1 ) )
953
- } else {
954
- pathString = path. name
950
+ return try path. replacingExtension ( with: type)
951
+ }
952
+
953
+ return try VirtualPath ( path: moduleName. appendingFileTypeExtension ( type) )
954
+ }
955
+
956
+ /// Determine the output path for a module documentation.
957
+ static func computeModuleDocOutputPath(
958
+ _ parsedOptions: inout ParsedOptions ,
959
+ moduleOutputPath: VirtualPath ? ,
960
+ compilerOutputType: FileType ? ,
961
+ moduleName: String
962
+ ) throws -> VirtualPath ? {
963
+ // FIXME: Do we need to check the output file map?
964
+
965
+ // If there is an explicit argument for the output path, use that
966
+ if let outputPathArg = parsedOptions. getLastArgument ( . emit_module_doc_path) {
967
+ // Consume -emit-module-doc if it's there.
968
+ _ = parsedOptions. hasArgument ( . emit_module_doc)
969
+
970
+ return try VirtualPath ( path: outputPathArg. asSingle)
971
+ }
972
+
973
+ // If there's a known module output path, put the .swiftdoc file next
974
+ // to it.
975
+ if let moduleOutputPath = moduleOutputPath {
976
+ // Consume -emit-module-doc if it's there.
977
+ _ = parsedOptions. hasArgument ( . emit_module_doc)
978
+
979
+ return try moduleOutputPath. replacingExtension ( with: . swiftDocumentation)
980
+ }
981
+
982
+ // If not specifically asked to emit Swift module documentation, don't.
983
+ if !parsedOptions. hasArgument ( . emit_module_doc) {
984
+ return nil
985
+ }
986
+
987
+ // If there is an output argument, derive the name from there.
988
+ if let outputPathArg = parsedOptions. getLastArgument ( . o) {
989
+ let path = try VirtualPath ( path: outputPathArg. asSingle)
990
+
991
+ // If the compiler output is of this type, use the argument directly.
992
+ if compilerOutputType == . swiftDocumentation {
993
+ return path
955
994
}
956
995
957
- return try VirtualPath ( path: pathString. appendingFileTypeExtension ( type) )
996
+ // Otherwise, put this output alongside the requested output.
997
+ return try path. replacingExtension ( with: . swiftDocumentation)
958
998
}
959
999
960
- return try VirtualPath ( path: moduleName. appendingFileTypeExtension ( type ) )
1000
+ return try VirtualPath ( path: moduleName. appendingFileTypeExtension ( . swiftDocumentation ) )
961
1001
}
962
1002
}
0 commit comments