зеркало из https://github.com/microsoft/clang.git
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139538 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
48822fbd08
Коммит
9a6da69306
|
@ -605,6 +605,10 @@ def nostdincxx : Flag<"-nostdinc++">,
|
||||||
HelpText<"Disable standard #include directories for the C++ standard library">;
|
HelpText<"Disable standard #include directories for the C++ standard library">;
|
||||||
def nobuiltininc : Flag<"-nobuiltininc">,
|
def nobuiltininc : Flag<"-nobuiltininc">,
|
||||||
HelpText<"Disable builtin #include directories">;
|
HelpText<"Disable builtin #include directories">;
|
||||||
|
def fmodule_cache_path : JoinedOrSeparate<"-fmodule-cache-path">,
|
||||||
|
MetaVarName<"<directory>">,
|
||||||
|
HelpText<"Specify the module cache path">;
|
||||||
|
|
||||||
def F : JoinedOrSeparate<"-F">, MetaVarName<"<directory>">,
|
def F : JoinedOrSeparate<"-F">, MetaVarName<"<directory>">,
|
||||||
HelpText<"Add directory to framework include search path">;
|
HelpText<"Add directory to framework include search path">;
|
||||||
def I : JoinedOrSeparate<"-I">, MetaVarName<"<directory>">,
|
def I : JoinedOrSeparate<"-I">, MetaVarName<"<directory>">,
|
||||||
|
|
|
@ -75,6 +75,9 @@ public:
|
||||||
/// etc.).
|
/// etc.).
|
||||||
std::string ResourceDir;
|
std::string ResourceDir;
|
||||||
|
|
||||||
|
/// \brief The directory used for the module cache.
|
||||||
|
std::string ModuleCachePath;
|
||||||
|
|
||||||
/// Include the compiler builtin includes.
|
/// Include the compiler builtin includes.
|
||||||
unsigned UseBuiltinIncludes : 1;
|
unsigned UseBuiltinIncludes : 1;
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,9 @@ class HeaderSearch {
|
||||||
unsigned SystemDirIdx;
|
unsigned SystemDirIdx;
|
||||||
bool NoCurDirSearch;
|
bool NoCurDirSearch;
|
||||||
|
|
||||||
|
/// \brief The path to the module cache.
|
||||||
|
std::string ModuleCachePath;
|
||||||
|
|
||||||
/// FileInfo - This contains all of the preprocessor-specific data about files
|
/// FileInfo - This contains all of the preprocessor-specific data about files
|
||||||
/// that are included. The vector is indexed by the FileEntry's UID.
|
/// that are included. The vector is indexed by the FileEntry's UID.
|
||||||
///
|
///
|
||||||
|
@ -193,6 +196,11 @@ public:
|
||||||
//LookupFileCache.clear();
|
//LookupFileCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Set the path to the module cache.
|
||||||
|
void setModuleCachePath(StringRef Path) {
|
||||||
|
ModuleCachePath = Path;
|
||||||
|
}
|
||||||
|
|
||||||
/// ClearFileInfo - Forget everything we know about headers so far.
|
/// ClearFileInfo - Forget everything we know about headers so far.
|
||||||
void ClearFileInfo() {
|
void ClearFileInfo() {
|
||||||
FileInfo.clear();
|
FileInfo.clear();
|
||||||
|
@ -308,6 +316,13 @@ public:
|
||||||
/// FileEntry, uniquing them through the the 'HeaderMaps' datastructure.
|
/// FileEntry, uniquing them through the the 'HeaderMaps' datastructure.
|
||||||
const HeaderMap *CreateHeaderMap(const FileEntry *FE);
|
const HeaderMap *CreateHeaderMap(const FileEntry *FE);
|
||||||
|
|
||||||
|
/// \brief Search in the module cache path for a module with the given
|
||||||
|
/// name.
|
||||||
|
///
|
||||||
|
/// \returns A file describing the named module, if available, or NULL to
|
||||||
|
/// indicate that the module could not be found.
|
||||||
|
const FileEntry *lookupModule(StringRef ModuleName);
|
||||||
|
|
||||||
void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
|
void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
|
||||||
|
|
||||||
typedef std::vector<HeaderFileInfo>::const_iterator header_file_iterator;
|
typedef std::vector<HeaderFileInfo>::const_iterator header_file_iterator;
|
||||||
|
|
|
@ -636,14 +636,8 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc,
|
||||||
CurFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
|
CurFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
|
||||||
|
|
||||||
// Search for a module with the given name.
|
// Search for a module with the given name.
|
||||||
std::string Filename = ModuleName.getName().str();
|
|
||||||
Filename += ".pcm";
|
|
||||||
const DirectoryLookup *CurDir = 0;
|
|
||||||
const FileEntry *ModuleFile
|
const FileEntry *ModuleFile
|
||||||
= PP->getHeaderSearchInfo().LookupFile(Filename, /*isAngled=*/false,
|
= PP->getHeaderSearchInfo().lookupModule(ModuleName.getName());
|
||||||
/*FromDir=*/0, CurDir, CurFile,
|
|
||||||
/*SearchPath=*/0,
|
|
||||||
/*RelativePath=*/0);
|
|
||||||
if (!ModuleFile) {
|
if (!ModuleFile) {
|
||||||
getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found)
|
getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found)
|
||||||
<< ModuleName.getName()
|
<< ModuleName.getName()
|
||||||
|
|
|
@ -576,6 +576,10 @@ static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts,
|
||||||
Res.push_back("-resource-dir");
|
Res.push_back("-resource-dir");
|
||||||
Res.push_back(Opts.ResourceDir);
|
Res.push_back(Opts.ResourceDir);
|
||||||
}
|
}
|
||||||
|
if (!Opts.ModuleCachePath.empty()) {
|
||||||
|
Res.push_back("-fmodule-cache-path");
|
||||||
|
Res.push_back(Opts.ModuleCachePath);
|
||||||
|
}
|
||||||
if (!Opts.UseStandardIncludes)
|
if (!Opts.UseStandardIncludes)
|
||||||
Res.push_back("-nostdinc");
|
Res.push_back("-nostdinc");
|
||||||
if (!Opts.UseStandardCXXIncludes)
|
if (!Opts.UseStandardCXXIncludes)
|
||||||
|
@ -1378,7 +1382,8 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
|
||||||
if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
|
if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
|
||||||
Opts.UseLibcxx = (strcmp(A->getValue(Args), "libc++") == 0);
|
Opts.UseLibcxx = (strcmp(A->getValue(Args), "libc++") == 0);
|
||||||
Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir);
|
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.
|
// Add -I..., -F..., and -index-header-map options in order.
|
||||||
bool IsIndexHeaderMap = false;
|
bool IsIndexHeaderMap = false;
|
||||||
for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F,
|
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) ?
|
((*it)->getOption().matches(OPT_cxx_isystem) ?
|
||||||
frontend::CXXSystem : frontend::System),
|
frontend::CXXSystem : frontend::System),
|
||||||
true, false, !(*it)->getOption().matches(OPT_iwithsysroot));
|
true, false, !(*it)->getOption().matches(OPT_iwithsysroot));
|
||||||
|
|
||||||
// FIXME: Need options for the various environment variables!
|
// FIXME: Need options for the various environment variables!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1161,5 +1161,7 @@ void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
|
||||||
if (HSOpts.UseStandardIncludes)
|
if (HSOpts.UseStandardIncludes)
|
||||||
Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts);
|
Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts);
|
||||||
|
|
||||||
|
HS.setModuleCachePath(HSOpts.ModuleCachePath);
|
||||||
|
|
||||||
Init.Realize(Lang);
|
Init.Realize(Lang);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,16 @@ const HeaderMap *HeaderSearch::CreateHeaderMap(const FileEntry *FE) {
|
||||||
return 0;
|
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
|
// File lookup within a DirectoryLookup scope
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -21,7 +21,7 @@ void test_diamond(int i, float f, double d, char c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RUN: %clang_cc1 -emit-module -o %T/diamond_top.pcm %S/Inputs/diamond_top.h
|
// RUN: %clang_cc1 -emit-module -o %T/diamond_top.pcm %S/Inputs/diamond_top.h
|
||||||
// RUN: %clang_cc1 -I %T -emit-module -o %T/diamond_left.pcm %S/Inputs/diamond_left.h
|
// RUN: %clang_cc1 -fmodule-cache-path %T -emit-module -o %T/diamond_left.pcm %S/Inputs/diamond_left.h
|
||||||
// RUN: %clang_cc1 -I %T -emit-module -o %T/diamond_right.pcm %S/Inputs/diamond_right.h
|
// RUN: %clang_cc1 -fmodule-cache-path %T -emit-module -o %T/diamond_right.pcm %S/Inputs/diamond_right.h
|
||||||
// RUN: %clang_cc1 -I %T -emit-module -o %T/diamond_bottom.pcm %S/Inputs/diamond_bottom.h
|
// RUN: %clang_cc1 -fmodule-cache-path %T -emit-module -o %T/diamond_bottom.pcm %S/Inputs/diamond_bottom.h
|
||||||
// RUN: %clang_cc1 -I %T %s -verify
|
// RUN: %clang_cc1 -fmodule-cache-path %T %s -verify
|
||||||
|
|
|
@ -7,10 +7,10 @@ __import_module__ load_failure;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// RUN: %clang_cc1 -x c++ -emit-module -o %T/load_failure.pcm %S/Inputs/load_failure.h
|
// RUN: %clang_cc1 -x c++ -emit-module -o %T/load_failure.pcm %S/Inputs/load_failure.h
|
||||||
// RUN: %clang_cc1 -I %T %s -DNONEXISTENT 2>&1 | FileCheck -check-prefix=CHECK-NONEXISTENT %s
|
// RUN: %clang_cc1 -fmodule-cache-path %T %s -DNONEXISTENT 2>&1 | FileCheck -check-prefix=CHECK-NONEXISTENT %s
|
||||||
// CHECK-NONEXISTENT: load_failure.c:2:19: fatal error: module 'load_nonexistent' not found
|
// CHECK-NONEXISTENT: load_failure.c:2:19: fatal error: module 'load_nonexistent' not found
|
||||||
|
|
||||||
// RUN: not %clang_cc1 -I %T %s -DFAILURE 2> %t
|
// RUN: not %clang_cc1 -fmodule-cache-path %T %s -DFAILURE 2> %t
|
||||||
// RUN: FileCheck -check-prefix=CHECK-FAILURE %s < %t
|
// RUN: FileCheck -check-prefix=CHECK-FAILURE %s < %t
|
||||||
|
|
||||||
// FIXME: Clean up diagnostic text below and give it a location
|
// FIXME: Clean up diagnostic text below and give it a location
|
||||||
|
|
|
@ -16,8 +16,8 @@ void test(int i, float f) {
|
||||||
|
|
||||||
// RUN: %clang_cc1 -emit-module -x c++ -verify -o %T/lookup_left_cxx.pcm %S/Inputs/lookup_left.hpp
|
// RUN: %clang_cc1 -emit-module -x c++ -verify -o %T/lookup_left_cxx.pcm %S/Inputs/lookup_left.hpp
|
||||||
// RUN: %clang_cc1 -emit-module -x c++ -o %T/lookup_right_cxx.pcm %S/Inputs/lookup_right.hpp
|
// RUN: %clang_cc1 -emit-module -x c++ -o %T/lookup_right_cxx.pcm %S/Inputs/lookup_right.hpp
|
||||||
// RUN: %clang_cc1 -x c++ -I %T %s -verify
|
// RUN: %clang_cc1 -x c++ -fmodule-cache-path %T %s -verify
|
||||||
// RUN: %clang_cc1 -ast-print -x c++ -I %T %s | FileCheck -check-prefix=CHECK-PRINT %s
|
// RUN: %clang_cc1 -ast-print -x c++ -fmodule-cache-path %T %s | FileCheck -check-prefix=CHECK-PRINT %s
|
||||||
|
|
||||||
// CHECK-PRINT: int *f0(int *);
|
// CHECK-PRINT: int *f0(int *);
|
||||||
// CHECK-PRINT: float *f0(float *);
|
// CHECK-PRINT: float *f0(float *);
|
||||||
|
|
|
@ -10,8 +10,8 @@ void test(id x) {
|
||||||
|
|
||||||
// RUN: %clang_cc1 -emit-module -x objective-c -o %T/lookup_left_objc.pcm %S/Inputs/lookup_left.h
|
// RUN: %clang_cc1 -emit-module -x objective-c -o %T/lookup_left_objc.pcm %S/Inputs/lookup_left.h
|
||||||
// RUN: %clang_cc1 -emit-module -x objective-c -o %T/lookup_right_objc.pcm %S/Inputs/lookup_right.h
|
// RUN: %clang_cc1 -emit-module -x objective-c -o %T/lookup_right_objc.pcm %S/Inputs/lookup_right.h
|
||||||
// RUN: %clang_cc1 -x objective-c -I %T -verify %s
|
// RUN: %clang_cc1 -x objective-c -fmodule-cache-path %T -verify %s
|
||||||
// RUN: %clang_cc1 -ast-print -x objective-c -I %T %s | FileCheck -check-prefix=CHECK-PRINT %s
|
// RUN: %clang_cc1 -ast-print -x objective-c -fmodule-cache-path %T %s | FileCheck -check-prefix=CHECK-PRINT %s
|
||||||
|
|
||||||
// CHECK-PRINT: - (int) method;
|
// CHECK-PRINT: - (int) method;
|
||||||
// CHECK-PRINT: - (double) method
|
// CHECK-PRINT: - (double) method
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// RUN: %clang_cc1 -emit-module -o %t/macros.pcm -DMODULE %s
|
// RUN: %clang_cc1 -emit-module -o %t/macros.pcm -DMODULE %s
|
||||||
// RUN: %clang_cc1 -verify -I %t %s
|
// RUN: %clang_cc1 -verify -fmodule-cache-path %t %s
|
||||||
|
|
||||||
#if defined(MODULE)
|
#if defined(MODULE)
|
||||||
#define INTEGER(X) int
|
#define INTEGER(X) int
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// RUN: mkdir -p %t
|
// RUN: mkdir -p %t
|
||||||
// RUN: %clang_cc1 -x c++ -emit-module -o %t/left.pcm %s -D MODULE_LEFT
|
// RUN: %clang_cc1 -x c++ -emit-module -o %t/left.pcm %s -D MODULE_LEFT
|
||||||
// RUN: %clang_cc1 -x c++ -emit-module -o %t/right.pcm %s -D MODULE_RIGHT
|
// RUN: %clang_cc1 -x c++ -emit-module -o %t/right.pcm %s -D MODULE_RIGHT
|
||||||
// RUN: %clang_cc1 -I %t %s -verify
|
// RUN: %clang_cc1 -fmodule-cache-path %t %s -verify
|
||||||
|
|
||||||
#if defined(MODULE_LEFT)
|
#if defined(MODULE_LEFT)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// RUN: mkdir -p %t
|
// RUN: mkdir -p %t
|
||||||
// RUN: %clang_cc1 -emit-module -o %t/diamond_top.pcm %s -D MODULE_TOP
|
// RUN: %clang_cc1 -emit-module -o %t/diamond_top.pcm %s -D MODULE_TOP
|
||||||
// RUN: %clang_cc1 -I %t -emit-module -o %t/diamond_left.pcm %s -D MODULE_LEFT
|
// RUN: %clang_cc1 -fmodule-cache-path %t -emit-module -o %t/diamond_left.pcm %s -D MODULE_LEFT
|
||||||
// RUN: %clang_cc1 -I %t -emit-module -o %t/diamond_right.pcm %s -D MODULE_RIGHT
|
// RUN: %clang_cc1 -fmodule-cache-path %t -emit-module -o %t/diamond_right.pcm %s -D MODULE_RIGHT
|
||||||
// RUN: %clang_cc1 -I %t -emit-module -o %t/diamond_bottom.pcm %s -D MODULE_BOTTOM
|
// RUN: %clang_cc1 -fmodule-cache-path %t -emit-module -o %t/diamond_bottom.pcm %s -D MODULE_BOTTOM
|
||||||
// RUN: %clang_cc1 -I %t %s -verify
|
// RUN: %clang_cc1 -fmodule-cache-path %t %s -verify
|
||||||
|
|
||||||
/*============================================================================*/
|
/*============================================================================*/
|
||||||
#ifdef MODULE_TOP
|
#ifdef MODULE_TOP
|
||||||
|
|
Загрузка…
Ссылка в новой задаче