@@ -194,7 +194,8 @@ namespace {
194
194
Importer.addSearchPath (path, /* isFramework*/ false , /* isSystem=*/ false );
195
195
}
196
196
197
- auto PCH = Importer.getOrCreatePCH (ImporterOpts, SwiftPCHHash);
197
+ auto PCH =
198
+ Importer.getOrCreatePCH (ImporterOpts, SwiftPCHHash, /* Cached=*/ true );
198
199
if (PCH.has_value ()) {
199
200
Impl.getClangInstance ()->getPreprocessorOpts ().ImplicitPCHInclude =
200
201
PCH.value ();
@@ -546,8 +547,10 @@ importer::getNormalInvocationArguments(
546
547
});
547
548
}
548
549
549
- if (auto path = getCxxShimModuleMapPath (searchPathOpts, triple)) {
550
- invocationArgStrs.push_back ((Twine (" -fmodule-map-file=" ) + *path).str ());
550
+ if (LangOpts.EnableCXXInterop ) {
551
+ if (auto path = getCxxShimModuleMapPath (searchPathOpts, triple)) {
552
+ invocationArgStrs.push_back ((Twine (" -fmodule-map-file=" ) + *path).str ());
553
+ }
551
554
}
552
555
553
556
// Set C language options.
@@ -953,8 +956,9 @@ ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
953
956
return PCHFilename.str ().str ();
954
957
}
955
958
956
- Optional<std::string> ClangImporter::getOrCreatePCH (
957
- const ClangImporterOptions &ImporterOptions, StringRef SwiftPCHHash) {
959
+ Optional<std::string>
960
+ ClangImporter::getOrCreatePCH (const ClangImporterOptions &ImporterOptions,
961
+ StringRef SwiftPCHHash, bool Cached) {
958
962
bool isExplicit;
959
963
auto PCHFilename = getPCHFilename (ImporterOptions, SwiftPCHHash,
960
964
isExplicit);
@@ -970,8 +974,8 @@ Optional<std::string> ClangImporter::getOrCreatePCH(
970
974
<< EC.message ();
971
975
return None;
972
976
}
973
- auto FailedToEmit =
974
- emitBridgingPCH (ImporterOptions. BridgingHeader , PCHFilename.value ());
977
+ auto FailedToEmit = emitBridgingPCH (ImporterOptions. BridgingHeader ,
978
+ PCHFilename.value (), Cached );
975
979
if (FailedToEmit) {
976
980
return None;
977
981
}
@@ -983,9 +987,10 @@ Optional<std::string> ClangImporter::getOrCreatePCH(
983
987
std::vector<std::string>
984
988
ClangImporter::getClangArguments (ASTContext &ctx, bool ignoreClangTarget) {
985
989
std::vector<std::string> invocationArgStrs;
986
- // Clang expects this to be like an actual command line. So we need to pass in
987
- // "clang" for argv[0]
988
- invocationArgStrs.push_back (ctx.ClangImporterOpts .clangPath );
990
+ // When creating from driver commands, clang expects this to be like an actual
991
+ // command line. So we need to pass in "clang" for argv[0]
992
+ if (!ctx.ClangImporterOpts .DirectClangCC1ModuleBuild )
993
+ invocationArgStrs.push_back (ctx.ClangImporterOpts .clangPath );
989
994
if (ctx.ClangImporterOpts .ExtraArgsOnly ) {
990
995
invocationArgStrs.insert (invocationArgStrs.end (),
991
996
ctx.ClangImporterOpts .ExtraArgs .begin (),
@@ -1734,13 +1739,13 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
1734
1739
}
1735
1740
1736
1741
bool ClangImporter::emitBridgingPCH (
1737
- StringRef headerPath, StringRef outputPCHPath) {
1742
+ StringRef headerPath, StringRef outputPCHPath, bool cached ) {
1738
1743
auto emitInstance = cloneCompilerInstanceForPrecompiling ();
1739
1744
auto &invocation = emitInstance->getInvocation ();
1740
1745
1741
1746
auto LangOpts = invocation.getLangOpts ();
1742
1747
LangOpts->NeededByPCHOrCompilationUsesPCH = true ;
1743
- LangOpts->CacheGeneratedPCH = true ;
1748
+ LangOpts->CacheGeneratedPCH = cached ;
1744
1749
1745
1750
auto language = getLanguageFromOptions (LangOpts);
1746
1751
auto inputFile = clang::FrontendInputFile (headerPath, language);
@@ -1991,12 +1996,16 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
1991
1996
auto &clangHeaderSearch = getClangPreprocessor ().getHeaderSearchInfo ();
1992
1997
auto realModuleName = SwiftContext.getRealModuleName (path.front ().Item ).str ();
1993
1998
1994
- // Look up the top-level module first, to see if it exists at all.
1995
- clang::Module *clangModule = clangHeaderSearch.lookupModule (
1996
- realModuleName, /* ImportLoc=*/ clang::SourceLocation (),
1997
- /* AllowSearch=*/ true , /* AllowExtraModuleMapSearch=*/ true );
1998
- if (!clangModule)
1999
- return nullptr ;
1999
+ // For explicit module build, module should always exist but module map might
2000
+ // not be exist. Go straight to module loader.
2001
+ if (Instance->getInvocation ().getLangOpts ()->ImplicitModules ) {
2002
+ // Look up the top-level module first, to see if it exists at all.
2003
+ clang::Module *clangModule = clangHeaderSearch.lookupModule (
2004
+ realModuleName, /* ImportLoc=*/ clang::SourceLocation (),
2005
+ /* AllowSearch=*/ true , /* AllowExtraModuleMapSearch=*/ true );
2006
+ if (!clangModule)
2007
+ return nullptr ;
2008
+ }
2000
2009
2001
2010
// Convert the Swift import path over to a Clang import path.
2002
2011
SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4 >
@@ -2051,7 +2060,7 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
2051
2060
2052
2061
// Now load the top-level module, so that we can check if the submodule
2053
2062
// exists without triggering a fatal error.
2054
- clangModule = loadModule (clangPath.front (), clang::Module::AllVisible);
2063
+ auto clangModule = loadModule (clangPath.front (), clang::Module::AllVisible);
2055
2064
if (!clangModule)
2056
2065
return nullptr ;
2057
2066
0 commit comments