diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-09-12 20:41:59 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-09-12 20:41:59 +0000 |
commit | 1e44e0229288aa4826bdd2e62546b9156032f718 (patch) | |
tree | a396ecf7fd708f29746c6339a5c01fb0c0c0cf8e /clang/lib | |
parent | 4a9eb5f8dc613a9afe925ce3c277a7078e1bb8a1 (diff) | |
download | bcm5719-llvm-1e44e0229288aa4826bdd2e62546b9156032f718.tar.gz bcm5719-llvm-1e44e0229288aa4826bdd2e62546b9156032f718.zip |
Introduce a cc1-level option to provide the path to the module cache,
where the compiler will look for module files. Eliminates the
egregious hack where we looked into the header search paths for
modules.
llvm-svn: 139538
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Frontend/InitHeaderSearch.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 10 |
4 files changed, 20 insertions, 9 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index bd019e0cf23..1106e48e910 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -636,14 +636,8 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, CurFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()); // Search for a module with the given name. - std::string Filename = ModuleName.getName().str(); - Filename += ".pcm"; - const DirectoryLookup *CurDir = 0; const FileEntry *ModuleFile - = PP->getHeaderSearchInfo().LookupFile(Filename, /*isAngled=*/false, - /*FromDir=*/0, CurDir, CurFile, - /*SearchPath=*/0, - /*RelativePath=*/0); + = PP->getHeaderSearchInfo().lookupModule(ModuleName.getName()); if (!ModuleFile) { getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found) << ModuleName.getName() diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 7ea31613bd3..e7b88542241 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -576,6 +576,10 @@ static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts, Res.push_back("-resource-dir"); Res.push_back(Opts.ResourceDir); } + if (!Opts.ModuleCachePath.empty()) { + Res.push_back("-fmodule-cache-path"); + Res.push_back(Opts.ModuleCachePath); + } if (!Opts.UseStandardIncludes) Res.push_back("-nostdinc"); if (!Opts.UseStandardCXXIncludes) @@ -1378,7 +1382,8 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ)) Opts.UseLibcxx = (strcmp(A->getValue(Args), "libc++") == 0); Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir); - + Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodule_cache_path); + // Add -I..., -F..., and -index-header-map options in order. bool IsIndexHeaderMap = false; for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F, @@ -1426,7 +1431,7 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { ((*it)->getOption().matches(OPT_cxx_isystem) ? frontend::CXXSystem : frontend::System), true, false, !(*it)->getOption().matches(OPT_iwithsysroot)); - + // FIXME: Need options for the various environment variables! } diff --git a/clang/lib/Frontend/InitHeaderSearch.cpp b/clang/lib/Frontend/InitHeaderSearch.cpp index 08af5322675..05152a77b2f 100644 --- a/clang/lib/Frontend/InitHeaderSearch.cpp +++ b/clang/lib/Frontend/InitHeaderSearch.cpp @@ -1161,5 +1161,7 @@ void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, if (HSOpts.UseStandardIncludes) Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts); + HS.setModuleCachePath(HSOpts.ModuleCachePath); + Init.Realize(Lang); } diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 0ba76327421..36826756b8b 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -98,6 +98,16 @@ const HeaderMap *HeaderSearch::CreateHeaderMap(const FileEntry *FE) { return 0; } +const FileEntry *HeaderSearch::lookupModule(StringRef ModuleName) { + // If we don't have a module cache path, we can't do anything. + if (ModuleCachePath.empty()) + return 0; + + llvm::SmallString<256> FileName(ModuleCachePath); + llvm::sys::path::append(FileName, ModuleName + ".pcm"); + return getFileMgr().getFile(FileName); +} + //===----------------------------------------------------------------------===// // File lookup within a DirectoryLookup scope //===----------------------------------------------------------------------===// |