Skip to content

Commit 7013725

Browse files
committed
Address Jordan's code review comments
1 parent ec9cf33 commit 7013725

File tree

4 files changed

+34
-49
lines changed

4 files changed

+34
-49
lines changed

include/swift/Driver/Driver.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "swift/Basic/OutputFileMap.h"
2525
#include "swift/Basic/Sanitizers.h"
2626
#include "swift/Driver/Util.h"
27-
#include "swift/Option/Options.h"
2827
#include "llvm/ADT/DenseMap.h"
2928
#include "llvm/ADT/StringMap.h"
3029
#include "llvm/ADT/StringRef.h"
@@ -355,12 +354,10 @@ class Driver {
355354
StringRef workingDirectory,
356355
CommandOutput *Output) const;
357356

358-
void choosePrivateOutputFilePath(Compilation &C,
359-
const TypeToPathMap *OutputMap,
360-
StringRef workingDirectory,
361-
CommandOutput *Output,
362-
file_types::ID fileID,
363-
Optional<options::ID> DriverOptForPath = llvm::None) const;
357+
void chooseSwiftSourceInfoOutputPath(Compilation &C,
358+
const TypeToPathMap *OutputMap,
359+
StringRef workingDirectory,
360+
CommandOutput *Output) const;
364361

365362
void chooseModuleInterfacePath(Compilation &C, const JobAction *JA,
366363
StringRef workingDirectory,

lib/Driver/Driver.cpp

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,9 +2544,7 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
25442544
if (OI.ShouldGenerateModule &&
25452545
(isa<CompileJobAction>(JA) || isa<MergeModuleJobAction>(JA))) {
25462546
chooseSwiftModuleDocOutputPath(C, OutputMap, workingDirectory, Output.get());
2547-
choosePrivateOutputFilePath(C, OutputMap, workingDirectory, Output.get(),
2548-
file_types::TY_SwiftSourceInfoFile,
2549-
options::OPT_emit_module_source_info_path);
2547+
chooseSwiftSourceInfoOutputPath(C, OutputMap, workingDirectory, Output.get());
25502548
}
25512549

25522550
if (C.getArgs().hasArg(options::OPT_emit_module_interface,
@@ -2790,12 +2788,13 @@ void Driver::chooseSwiftModuleOutputPath(Compilation &C,
27902788
}
27912789
}
27922790

2793-
void Driver::choosePrivateOutputFilePath(Compilation &C,
2794-
const TypeToPathMap *OutputMap,
2795-
StringRef workingDirectory,
2796-
CommandOutput *Output,
2797-
file_types::ID fileID,
2798-
Optional<options::ID> optId) const {
2791+
static void chooseModuleAuxiliaryOutputFilePath(Compilation &C,
2792+
const TypeToPathMap *OutputMap,
2793+
StringRef workingDirectory,
2794+
CommandOutput *Output,
2795+
file_types::ID fileID,
2796+
bool isPrivate,
2797+
Optional<options::ID> optId = llvm::None) {
27992798
if (hasExistingAdditionalOutput(*Output, fileID))
28002799
return;
28012800
// Honor driver option for this path if it's given
@@ -2820,10 +2819,12 @@ void Driver::choosePrivateOutputFilePath(Compilation &C,
28202819
bool isTempFile = C.isTemporaryFile(ModulePath);
28212820
auto ModuleName = llvm::sys::path::filename(ModulePath);
28222821
llvm::SmallString<128> Path(llvm::sys::path::parent_path(ModulePath));
2823-
llvm::sys::path::append(Path, "Private");
2824-
// If the build system has created a Private dir for us to include the file, use it.
2825-
if (!llvm::sys::fs::exists(Path)) {
2826-
llvm::sys::path::remove_filename(Path);
2822+
if (isPrivate) {
2823+
llvm::sys::path::append(Path, "Private");
2824+
// If the build system has created a Private dir for us to include the file, use it.
2825+
if (!llvm::sys::fs::exists(Path)) {
2826+
llvm::sys::path::remove_filename(Path);
2827+
}
28272828
}
28282829
llvm::sys::path::append(Path, ModuleName);
28292830
llvm::sys::path::replace_extension(Path, file_types::getExtension(fileID));
@@ -2833,35 +2834,21 @@ void Driver::choosePrivateOutputFilePath(Compilation &C,
28332834
}
28342835
}
28352836

2837+
void Driver::chooseSwiftSourceInfoOutputPath(Compilation &C,
2838+
const TypeToPathMap *OutputMap,
2839+
StringRef workingDirectory,
2840+
CommandOutput *Output) const {
2841+
chooseModuleAuxiliaryOutputFilePath(C, OutputMap, workingDirectory, Output,
2842+
file_types::TY_SwiftSourceInfoFile,
2843+
/*isPrivate*/true, options::OPT_emit_module_source_info_path);
2844+
}
2845+
28362846
void Driver::chooseSwiftModuleDocOutputPath(Compilation &C,
28372847
const TypeToPathMap *OutputMap,
28382848
StringRef workingDirectory,
28392849
CommandOutput *Output) const {
2840-
2841-
if (hasExistingAdditionalOutput(*Output, file_types::TY_SwiftModuleDocFile))
2842-
return;
2843-
2844-
StringRef OFMModuleDocOutputPath;
2845-
if (OutputMap) {
2846-
auto iter = OutputMap->find(file_types::TY_SwiftModuleDocFile);
2847-
if (iter != OutputMap->end())
2848-
OFMModuleDocOutputPath = iter->second;
2849-
}
2850-
if (!OFMModuleDocOutputPath.empty()) {
2851-
// Prefer a path from the OutputMap.
2852-
Output->setAdditionalOutputForType(file_types::TY_SwiftModuleDocFile,
2853-
OFMModuleDocOutputPath);
2854-
} else if (Output->getPrimaryOutputType() != file_types::TY_Nothing) {
2855-
// Otherwise, put it next to the swiftmodule file.
2856-
llvm::SmallString<128> Path(
2857-
Output->getAnyOutputForType(file_types::TY_SwiftModuleFile));
2858-
bool isTempFile = C.isTemporaryFile(Path);
2859-
llvm::sys::path::replace_extension(
2860-
Path, file_types::getExtension(file_types::TY_SwiftModuleDocFile));
2861-
Output->setAdditionalOutputForType(file_types::TY_SwiftModuleDocFile, Path);
2862-
if (isTempFile)
2863-
C.addTemporaryFile(Path);
2864-
}
2850+
chooseModuleAuxiliaryOutputFilePath(C, OutputMap, workingDirectory, Output,
2851+
file_types::TY_SwiftModuleDocFile, /*isPrivate*/false);
28652852
}
28662853

28672854
void Driver::chooseRemappingOutputPath(Compilation &C,

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,8 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,
913913
addOutputsOfType(Arguments, context.Output, context.Args,
914914
file_types::TY_SwiftModuleDocFile, "-emit-module-doc-path");
915915
addOutputsOfType(Arguments, context.Output, context.Args,
916-
file_types::TY_SwiftSourceInfoFile, "-emit-module-source-info-path");
916+
file_types::TY_SwiftSourceInfoFile,
917+
"-emit-module-source-info-path");
917918
addOutputsOfType(Arguments, context.Output, context.Args,
918919
file_types::ID::TY_SwiftModuleInterfaceFile,
919920
"-emit-module-interface-path");

lib/Frontend/FrontendInputsAndOutputs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ bool FrontendInputsAndOutputs::hasModuleDocOutputPath() const {
437437
}
438438
bool FrontendInputsAndOutputs::hasModuleSourceInfoOutputPath() const {
439439
return hasSupplementaryOutputPath(
440-
[](const SupplementaryOutputPaths &outs) -> const std::string & {
441-
return outs.ModuleSourceInfoOutputPath;
442-
});
440+
[](const SupplementaryOutputPaths &outs) -> const std::string & {
441+
return outs.ModuleSourceInfoOutputPath;
442+
});
443443
}
444444
bool FrontendInputsAndOutputs::hasModuleInterfaceOutputPath() const {
445445
return hasSupplementaryOutputPath(

0 commit comments

Comments
 (0)