@@ -2019,7 +2019,7 @@ static void formFilenameFromBaseAndExt(StringRef base, StringRef newExt,
2019
2019
static Optional<StringRef> getOutputFilenameFromPathArgOrAsTopLevel (
2020
2020
const OutputInfo &OI, const llvm::opt::DerivedArgList &Args,
2021
2021
llvm::opt::OptSpecifier PathArg, file_types::ID ExpectedOutputType,
2022
- bool TreatAsTopLevelOutput, StringRef workingDirectory, StringRef ext,
2022
+ bool TreatAsTopLevelOutput, StringRef workingDirectory,
2023
2023
llvm::SmallString<128 > &Buffer) {
2024
2024
if (const Arg *A = Args.getLastArg (PathArg))
2025
2025
return StringRef (A->getValue ());
@@ -2033,13 +2033,17 @@ static Optional<StringRef> getOutputFilenameFromPathArgOrAsTopLevel(
2033
2033
Buffer = A->getValue ();
2034
2034
llvm::sys::path::remove_filename (Buffer);
2035
2035
llvm::sys::path::append (Buffer, OI.ModuleName );
2036
- llvm::sys::path::replace_extension (Buffer, ext);
2036
+ llvm::sys::path::replace_extension (
2037
+ Buffer, file_types::getExtension (ExpectedOutputType));
2037
2038
return Buffer.str ();
2038
2039
}
2039
2040
2040
2041
// A top-level output wasn't specified, so just output to
2041
2042
// <ModuleName>.<ext>.
2042
- formFilenameFromBaseAndExt (OI.ModuleName , ext, workingDirectory, Buffer);
2043
+ formFilenameFromBaseAndExt (OI.ModuleName ,
2044
+ file_types::getExtension (ExpectedOutputType),
2045
+ workingDirectory,
2046
+ Buffer);
2043
2047
return Buffer.str ();
2044
2048
}
2045
2049
@@ -2118,8 +2122,7 @@ static StringRef getOutputFilename(Compilation &C,
2118
2122
if (isa<MergeModuleJobAction>(JA)) {
2119
2123
auto optFilename = getOutputFilenameFromPathArgOrAsTopLevel (
2120
2124
OI, Args, options::OPT_emit_module_path, file_types::TY_SwiftModuleFile,
2121
- OI.ShouldTreatModuleAsTopLevelOutput , workingDirectory,
2122
- SERIALIZED_MODULE_EXTENSION, Buffer);
2125
+ OI.ShouldTreatModuleAsTopLevelOutput , workingDirectory, Buffer);
2123
2126
if (optFilename)
2124
2127
return *optFilename;
2125
2128
}
@@ -2627,17 +2630,16 @@ void Driver::chooseSwiftModuleOutputPath(Compilation &C, const OutputInfo &OI,
2627
2630
}
2628
2631
2629
2632
const Arg *A = C.getArgs ().getLastArg (options::OPT_emit_module_path);
2633
+ using file_types::TY_SwiftModuleFile;
2630
2634
2631
2635
if (!OFMModuleOutputPath.empty ()) {
2632
2636
// Prefer a path from the OutputMap.
2633
- Output->setAdditionalOutputForType (file_types::TY_SwiftModuleFile,
2634
- OFMModuleOutputPath);
2637
+ Output->setAdditionalOutputForType (TY_SwiftModuleFile, OFMModuleOutputPath);
2635
2638
} else if (A && OI.CompilerMode == OutputInfo::Mode::SingleCompile) {
2636
2639
// We're performing a single compilation (and thus no merge module step),
2637
2640
// so prefer to use -emit-module-path, if present.
2638
- Output->setAdditionalOutputForType (file_types::TY_SwiftModuleFile,
2639
- A->getValue ());
2640
- } else if (Output->getPrimaryOutputType () == file_types::TY_SwiftModuleFile) {
2641
+ Output->setAdditionalOutputForType (TY_SwiftModuleFile, A->getValue ());
2642
+ } else if (Output->getPrimaryOutputType () == TY_SwiftModuleFile) {
2641
2643
// If the primary type is already a module type, we're out of
2642
2644
// options for overriding the primary name choice: stop now.
2643
2645
assert (!Output->getPrimaryOutputFilename ().empty ());
@@ -2647,29 +2649,28 @@ void Driver::chooseSwiftModuleOutputPath(Compilation &C, const OutputInfo &OI,
2647
2649
// We're performing a single compile and don't have -emit-module-path,
2648
2650
// but have been told to treat the module as a top-level output.
2649
2651
// Determine an appropriate path.
2652
+ llvm::SmallString<128 > Path;
2650
2653
if (const Arg *A = C.getArgs ().getLastArg (options::OPT_o)) {
2651
2654
// Put the module next to the top-level output.
2652
- llvm::SmallString< 128 > Path ( A->getValue () );
2655
+ Path = A->getValue ();
2653
2656
llvm::sys::path::remove_filename (Path);
2654
- llvm::sys::path::append (Path, OI.ModuleName );
2655
- llvm::sys::path::replace_extension (Path, SERIALIZED_MODULE_EXTENSION);
2656
- Output->setAdditionalOutputForType (file_types::TY_SwiftModuleFile, Path);
2657
2657
} else {
2658
2658
// A top-level output wasn't specified, so just output to
2659
- // <ModuleName>.swiftmodule.
2660
- llvm::SmallString<128 > Path (OI.ModuleName );
2661
- llvm::sys::path::replace_extension (Path, SERIALIZED_MODULE_EXTENSION);
2662
- Output->setAdditionalOutputForType (file_types::TY_SwiftModuleFile, Path);
2659
+ // <ModuleName>.swiftmodule in the current directory.
2663
2660
}
2661
+ llvm::sys::path::append (Path, OI.ModuleName );
2662
+ llvm::sys::path::replace_extension (
2663
+ Path, file_types::getExtension (TY_SwiftModuleFile));
2664
+ Output->setAdditionalOutputForType (TY_SwiftModuleFile, Path);
2664
2665
} else if (Output->getPrimaryOutputType () != file_types::TY_Nothing) {
2665
2666
// We're only generating the module as an intermediate, so put it next
2666
2667
// to the primary output of the compile command.
2667
2668
llvm::SmallString<128 > Path (Output->getPrimaryOutputFilenames ()[0 ]);
2668
2669
assert (!Path.empty ());
2669
2670
bool isTempFile = C.isTemporaryFile (Path);
2670
- llvm::sys::path::replace_extension (Path, SERIALIZED_MODULE_EXTENSION);
2671
- Output-> setAdditionalOutputForType ( file_types::ID:: TY_SwiftModuleFile,
2672
- Path);
2671
+ llvm::sys::path::replace_extension (
2672
+ Path, file_types::getExtension ( TY_SwiftModuleFile));
2673
+ Output-> setAdditionalOutputForType (TY_SwiftModuleFile, Path);
2673
2674
if (isTempFile)
2674
2675
C.addTemporaryFile (Path);
2675
2676
}
@@ -2698,7 +2699,8 @@ void Driver::chooseSwiftModuleDocOutputPath(Compilation &C,
2698
2699
llvm::SmallString<128 > Path (
2699
2700
Output->getAnyOutputForType (file_types::TY_SwiftModuleFile));
2700
2701
bool isTempFile = C.isTemporaryFile (Path);
2701
- llvm::sys::path::replace_extension (Path, SERIALIZED_MODULE_DOC_EXTENSION);
2702
+ llvm::sys::path::replace_extension (
2703
+ Path, file_types::getExtension (file_types::TY_SwiftModuleDocFile));
2702
2704
Output->setAdditionalOutputForType (file_types::TY_SwiftModuleDocFile, Path);
2703
2705
if (isTempFile)
2704
2706
C.addTemporaryFile (Path);
@@ -2799,7 +2801,7 @@ void Driver::chooseLoadedModuleTracePath(Compilation &C, const OutputInfo &OI,
2799
2801
filename = *getOutputFilenameFromPathArgOrAsTopLevel (
2800
2802
OI, C.getArgs (), options::OPT_emit_loaded_module_trace_path,
2801
2803
file_types::TY_ModuleTrace,
2802
- /* TreatAsTopLevelOutput=*/ true , workingDirectory, " trace.json " , Buf);
2804
+ /* TreatAsTopLevelOutput=*/ true , workingDirectory, Buf);
2803
2805
}
2804
2806
2805
2807
Output->setAdditionalOutputForType (file_types::TY_ModuleTrace, filename);
@@ -2829,7 +2831,7 @@ void Driver::chooseOptimizationRecordPath(Compilation &C, const OutputInfo &OI,
2829
2831
auto filename = *getOutputFilenameFromPathArgOrAsTopLevel (
2830
2832
OI, C.getArgs (), options::OPT_save_optimization_record_path,
2831
2833
file_types::TY_OptRecord, /* TreatAsTopLevelOutput=*/ true ,
2832
- workingDirectory, " opt.yaml " , Buf);
2834
+ workingDirectory, Buf);
2833
2835
2834
2836
Output->setAdditionalOutputForType (file_types::TY_OptRecord, filename);
2835
2837
} else
0 commit comments