mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Consistently get extensions from swift/Basic/FileTypes.h (part 2)
Remove the last few literal extension strings from Strings.h in favor of the file_types APIs, and use those APIs in a few more places.
This commit is contained in:
@@ -2019,7 +2019,7 @@ static void formFilenameFromBaseAndExt(StringRef base, StringRef newExt,
|
||||
static Optional<StringRef> getOutputFilenameFromPathArgOrAsTopLevel(
|
||||
const OutputInfo &OI, const llvm::opt::DerivedArgList &Args,
|
||||
llvm::opt::OptSpecifier PathArg, file_types::ID ExpectedOutputType,
|
||||
bool TreatAsTopLevelOutput, StringRef workingDirectory, StringRef ext,
|
||||
bool TreatAsTopLevelOutput, StringRef workingDirectory,
|
||||
llvm::SmallString<128> &Buffer) {
|
||||
if (const Arg *A = Args.getLastArg(PathArg))
|
||||
return StringRef(A->getValue());
|
||||
@@ -2033,13 +2033,17 @@ static Optional<StringRef> getOutputFilenameFromPathArgOrAsTopLevel(
|
||||
Buffer = A->getValue();
|
||||
llvm::sys::path::remove_filename(Buffer);
|
||||
llvm::sys::path::append(Buffer, OI.ModuleName);
|
||||
llvm::sys::path::replace_extension(Buffer, ext);
|
||||
llvm::sys::path::replace_extension(
|
||||
Buffer, file_types::getExtension(ExpectedOutputType));
|
||||
return Buffer.str();
|
||||
}
|
||||
|
||||
// A top-level output wasn't specified, so just output to
|
||||
// <ModuleName>.<ext>.
|
||||
formFilenameFromBaseAndExt(OI.ModuleName, ext, workingDirectory, Buffer);
|
||||
formFilenameFromBaseAndExt(OI.ModuleName,
|
||||
file_types::getExtension(ExpectedOutputType),
|
||||
workingDirectory,
|
||||
Buffer);
|
||||
return Buffer.str();
|
||||
}
|
||||
|
||||
@@ -2118,8 +2122,7 @@ static StringRef getOutputFilename(Compilation &C,
|
||||
if (isa<MergeModuleJobAction>(JA)) {
|
||||
auto optFilename = getOutputFilenameFromPathArgOrAsTopLevel(
|
||||
OI, Args, options::OPT_emit_module_path, file_types::TY_SwiftModuleFile,
|
||||
OI.ShouldTreatModuleAsTopLevelOutput, workingDirectory,
|
||||
SERIALIZED_MODULE_EXTENSION, Buffer);
|
||||
OI.ShouldTreatModuleAsTopLevelOutput, workingDirectory, Buffer);
|
||||
if (optFilename)
|
||||
return *optFilename;
|
||||
}
|
||||
@@ -2627,17 +2630,16 @@ void Driver::chooseSwiftModuleOutputPath(Compilation &C, const OutputInfo &OI,
|
||||
}
|
||||
|
||||
const Arg *A = C.getArgs().getLastArg(options::OPT_emit_module_path);
|
||||
using file_types::TY_SwiftModuleFile;
|
||||
|
||||
if (!OFMModuleOutputPath.empty()) {
|
||||
// Prefer a path from the OutputMap.
|
||||
Output->setAdditionalOutputForType(file_types::TY_SwiftModuleFile,
|
||||
OFMModuleOutputPath);
|
||||
Output->setAdditionalOutputForType(TY_SwiftModuleFile, OFMModuleOutputPath);
|
||||
} else if (A && OI.CompilerMode == OutputInfo::Mode::SingleCompile) {
|
||||
// We're performing a single compilation (and thus no merge module step),
|
||||
// so prefer to use -emit-module-path, if present.
|
||||
Output->setAdditionalOutputForType(file_types::TY_SwiftModuleFile,
|
||||
A->getValue());
|
||||
} else if (Output->getPrimaryOutputType() == file_types::TY_SwiftModuleFile) {
|
||||
Output->setAdditionalOutputForType(TY_SwiftModuleFile, A->getValue());
|
||||
} else if (Output->getPrimaryOutputType() == TY_SwiftModuleFile) {
|
||||
// If the primary type is already a module type, we're out of
|
||||
// options for overriding the primary name choice: stop now.
|
||||
assert(!Output->getPrimaryOutputFilename().empty());
|
||||
@@ -2647,29 +2649,28 @@ void Driver::chooseSwiftModuleOutputPath(Compilation &C, const OutputInfo &OI,
|
||||
// We're performing a single compile and don't have -emit-module-path,
|
||||
// but have been told to treat the module as a top-level output.
|
||||
// Determine an appropriate path.
|
||||
llvm::SmallString<128> Path;
|
||||
if (const Arg *A = C.getArgs().getLastArg(options::OPT_o)) {
|
||||
// Put the module next to the top-level output.
|
||||
llvm::SmallString<128> Path(A->getValue());
|
||||
Path = A->getValue();
|
||||
llvm::sys::path::remove_filename(Path);
|
||||
llvm::sys::path::append(Path, OI.ModuleName);
|
||||
llvm::sys::path::replace_extension(Path, SERIALIZED_MODULE_EXTENSION);
|
||||
Output->setAdditionalOutputForType(file_types::TY_SwiftModuleFile, Path);
|
||||
} else {
|
||||
// A top-level output wasn't specified, so just output to
|
||||
// <ModuleName>.swiftmodule.
|
||||
llvm::SmallString<128> Path(OI.ModuleName);
|
||||
llvm::sys::path::replace_extension(Path, SERIALIZED_MODULE_EXTENSION);
|
||||
Output->setAdditionalOutputForType(file_types::TY_SwiftModuleFile, Path);
|
||||
// <ModuleName>.swiftmodule in the current directory.
|
||||
}
|
||||
llvm::sys::path::append(Path, OI.ModuleName);
|
||||
llvm::sys::path::replace_extension(
|
||||
Path, file_types::getExtension(TY_SwiftModuleFile));
|
||||
Output->setAdditionalOutputForType(TY_SwiftModuleFile, Path);
|
||||
} else if (Output->getPrimaryOutputType() != file_types::TY_Nothing) {
|
||||
// We're only generating the module as an intermediate, so put it next
|
||||
// to the primary output of the compile command.
|
||||
llvm::SmallString<128> Path(Output->getPrimaryOutputFilenames()[0]);
|
||||
assert(!Path.empty());
|
||||
bool isTempFile = C.isTemporaryFile(Path);
|
||||
llvm::sys::path::replace_extension(Path, SERIALIZED_MODULE_EXTENSION);
|
||||
Output->setAdditionalOutputForType(file_types::ID::TY_SwiftModuleFile,
|
||||
Path);
|
||||
llvm::sys::path::replace_extension(
|
||||
Path, file_types::getExtension(TY_SwiftModuleFile));
|
||||
Output->setAdditionalOutputForType(TY_SwiftModuleFile, Path);
|
||||
if (isTempFile)
|
||||
C.addTemporaryFile(Path);
|
||||
}
|
||||
@@ -2698,7 +2699,8 @@ void Driver::chooseSwiftModuleDocOutputPath(Compilation &C,
|
||||
llvm::SmallString<128> Path(
|
||||
Output->getAnyOutputForType(file_types::TY_SwiftModuleFile));
|
||||
bool isTempFile = C.isTemporaryFile(Path);
|
||||
llvm::sys::path::replace_extension(Path, SERIALIZED_MODULE_DOC_EXTENSION);
|
||||
llvm::sys::path::replace_extension(
|
||||
Path, file_types::getExtension(file_types::TY_SwiftModuleDocFile));
|
||||
Output->setAdditionalOutputForType(file_types::TY_SwiftModuleDocFile, Path);
|
||||
if (isTempFile)
|
||||
C.addTemporaryFile(Path);
|
||||
@@ -2799,7 +2801,7 @@ void Driver::chooseLoadedModuleTracePath(Compilation &C, const OutputInfo &OI,
|
||||
filename = *getOutputFilenameFromPathArgOrAsTopLevel(
|
||||
OI, C.getArgs(), options::OPT_emit_loaded_module_trace_path,
|
||||
file_types::TY_ModuleTrace,
|
||||
/*TreatAsTopLevelOutput=*/true, workingDirectory, "trace.json", Buf);
|
||||
/*TreatAsTopLevelOutput=*/true, workingDirectory, Buf);
|
||||
}
|
||||
|
||||
Output->setAdditionalOutputForType(file_types::TY_ModuleTrace, filename);
|
||||
@@ -2829,7 +2831,7 @@ void Driver::chooseOptimizationRecordPath(Compilation &C, const OutputInfo &OI,
|
||||
auto filename = *getOutputFilenameFromPathArgOrAsTopLevel(
|
||||
OI, C.getArgs(), options::OPT_save_optimization_record_path,
|
||||
file_types::TY_OptRecord, /*TreatAsTopLevelOutput=*/true,
|
||||
workingDirectory, "opt.yaml", Buf);
|
||||
workingDirectory, Buf);
|
||||
|
||||
Output->setAdditionalOutputForType(file_types::TY_OptRecord, filename);
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user