Add flag -f(no-)modules-implicit-maps.

This suppresses the implicit search for files called 'module.modulemap' and
similar.

llvm-svn: 222745
This commit is contained in:
Daniel Jasper 2014-11-25 09:45:48 +00:00
parent c27023c622
commit 21a0f55755
7 changed files with 75 additions and 46 deletions

View File

@ -207,6 +207,9 @@ Command-line parameters
``-fmodules-search-all``
If a symbol is not found, search modules referenced in the current module maps but not imported for symbols, so the error message can reference the module by name. Note that if the global module index has not been built before, this might take some time as it needs to build all the modules. Note that this option doesn't apply in module builds, to avoid the recursion.
``-fno-modules-implicit-maps``
Suppresses the implicit search for files called ``module.modulemap`` and similar. Instead, module files need to be explicitly specified via ``-fmodule-map-file`` or transitively used.
Module Semantics
================

View File

@ -126,6 +126,7 @@ LANGOPT(ModulesDeclUse , 1, 0, "require declaration of module uses")
LANGOPT(ModulesSearchAll , 1, 1, "search even non-imported modules to find unresolved references")
LANGOPT(ModulesStrictDeclUse, 1, 0, "require declaration of module uses and all headers to be in modules")
LANGOPT(ModulesErrorRecovery, 1, 1, "automatically import modules as needed when performing error recovery")
BENIGN_LANGOPT(ModulesImplicitMaps, 1, 1, "use files called module.modulemap implicitly as module maps")
COMPATIBLE_LANGOPT(Optimize , 1, 0, "__OPTIMIZE__ predefined macro")
COMPATIBLE_LANGOPT(OptimizeSize , 1, 0, "__OPTIMIZE_SIZE__ predefined macro")
LANGOPT(Static , 1, 0, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)")

View File

@ -675,6 +675,12 @@ def fmodules_strict_decluse : Flag <["-"], "fmodules-strict-decluse">, Group<f_G
HelpText<"Like -fmodules-decluse but requires all headers to be in modules">;
def fno_modules_search_all : Flag <["-"], "fno-modules-search-all">, Group<f_Group>,
Flags<[DriverOption, CC1Option]>;
def fmodules_implicit_maps :
Flag <["-"], "fmodules-implicit-maps">,
Group<f_Group>, Flags<[DriverOption, CC1Option]>;
def fno_modules_implicit_maps :
Flag <["-"], "fno-modules-implicit-maps">,
Group<f_Group>, Flags<[DriverOption, CC1Option]>;
def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-system-headers">, Group<f_Group>, Flags<[CC1Option]>;
def fmudflapth : Flag<["-"], "fmudflapth">, Group<f_Group>;

View File

@ -252,7 +252,7 @@ class HeaderSearch {
unsigned NumMultiIncludeFileOptzn;
unsigned NumFrameworkLookups, NumSubFrameworkLookups;
bool EnabledModules;
const LangOptions &LangOpts;
// HeaderSearch doesn't support default or copy construction.
HeaderSearch(const HeaderSearch&) LLVM_DELETED_FUNCTION;
@ -479,7 +479,7 @@ public:
const HeaderMap *CreateHeaderMap(const FileEntry *FE);
/// Returns true if modules are enabled.
bool enabledModules() const { return EnabledModules; }
bool enabledModules() const { return LangOpts.Modules; }
/// \brief Retrieve the name of the module file that should be used to
/// load the given module.

View File

@ -1465,6 +1465,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
!Args.hasArg(OPT_fno_modules_search_all) &&
Args.hasArg(OPT_fmodules_search_all);
Opts.ModulesErrorRecovery = !Args.hasArg(OPT_fno_modules_error_recovery);
Opts.ModulesImplicitMaps = Args.hasFlag(OPT_fmodules_implicit_maps,
OPT_fno_modules_implicit_maps, true);
Opts.CharIsSigned = Opts.OpenCL || !Args.hasArg(OPT_fno_signed_char);
Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar);
Opts.ShortWChar = Args.hasFlag(OPT_fshort_wchar, OPT_fno_short_wchar, false);

View File

@ -50,7 +50,8 @@ HeaderSearch::HeaderSearch(IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts,
const LangOptions &LangOpts,
const TargetInfo *Target)
: HSOpts(HSOpts), Diags(Diags), FileMgr(SourceMgr.getFileManager()),
FrameworkMap(64), ModMap(SourceMgr, Diags, LangOpts, Target, *this) {
FrameworkMap(64), ModMap(SourceMgr, Diags, LangOpts, Target, *this),
LangOpts(LangOpts) {
AngledDirIdx = 0;
SystemDirIdx = 0;
NoCurDirSearch = false;
@ -60,8 +61,6 @@ HeaderSearch::HeaderSearch(IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts,
NumIncluded = 0;
NumMultiIncludeFileOptzn = 0;
NumFrameworkLookups = NumSubFrameworkLookups = 0;
EnabledModules = LangOpts.Modules;
}
HeaderSearch::~HeaderSearch() {
@ -149,7 +148,7 @@ std::string HeaderSearch::getModuleFileName(StringRef ModuleName,
Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch) {
// Look in the module map to determine if there is a module by this name.
Module *Module = ModMap.findModule(ModuleName);
if (Module || !AllowSearch)
if (Module || !AllowSearch || !LangOpts.ModulesImplicitMaps)
return Module;
// Look through the various header search paths to load any available module
@ -1062,7 +1061,7 @@ StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) {
bool HeaderSearch::hasModuleMap(StringRef FileName,
const DirectoryEntry *Root,
bool IsSystem) {
if (!enabledModules())
if (!enabledModules() || !LangOpts.ModulesImplicitMaps)
return false;
SmallVector<const DirectoryEntry *, 2> FixUpDirectories;
@ -1170,6 +1169,8 @@ HeaderSearch::loadModuleMapFileImpl(const FileEntry *File, bool IsSystem) {
const FileEntry *
HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
if (!LangOpts.ModulesImplicitMaps)
return nullptr;
// For frameworks, the preferred spelling is Modules/module.modulemap, but
// module.map at the framework root is also accepted.
SmallString<128> ModuleMapFileName(Dir->getName());
@ -1190,12 +1191,12 @@ Module *HeaderSearch::loadFrameworkModule(StringRef Name,
bool IsSystem) {
if (Module *Module = ModMap.findModule(Name))
return Module;
// Try to load a module map file.
switch (loadModuleMapFile(Dir, IsSystem, /*IsFramework*/true)) {
case LMM_InvalidModuleMap:
break;
case LMM_AlreadyLoaded:
case LMM_NoDirectory:
return nullptr;
@ -1206,7 +1207,10 @@ Module *HeaderSearch::loadFrameworkModule(StringRef Name,
// Try to infer a module map from the framework directory.
return ModMap.inferFrameworkModule(Name, Dir, IsSystem, /*Parent=*/nullptr);
if (LangOpts.ModulesImplicitMaps)
return ModMap.inferFrameworkModule(Name, Dir, IsSystem, /*Parent=*/nullptr);
return nullptr;
}
@ -1242,45 +1246,49 @@ HeaderSearch::loadModuleMapFile(const DirectoryEntry *Dir, bool IsSystem,
void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) {
Modules.clear();
// Load module maps for each of the header search directories.
for (unsigned Idx = 0, N = SearchDirs.size(); Idx != N; ++Idx) {
bool IsSystem = SearchDirs[Idx].isSystemHeaderDirectory();
if (SearchDirs[Idx].isFramework()) {
std::error_code EC;
SmallString<128> DirNative;
llvm::sys::path::native(SearchDirs[Idx].getFrameworkDir()->getName(),
DirNative);
// Search each of the ".framework" directories to load them as modules.
for (llvm::sys::fs::directory_iterator Dir(DirNative.str(), EC), DirEnd;
Dir != DirEnd && !EC; Dir.increment(EC)) {
if (llvm::sys::path::extension(Dir->path()) != ".framework")
continue;
const DirectoryEntry *FrameworkDir = FileMgr.getDirectory(Dir->path());
if (!FrameworkDir)
continue;
// Load this framework module.
loadFrameworkModule(llvm::sys::path::stem(Dir->path()), FrameworkDir,
IsSystem);
if (LangOpts.ModulesImplicitMaps) {
// Load module maps for each of the header search directories.
for (unsigned Idx = 0, N = SearchDirs.size(); Idx != N; ++Idx) {
bool IsSystem = SearchDirs[Idx].isSystemHeaderDirectory();
if (SearchDirs[Idx].isFramework()) {
std::error_code EC;
SmallString<128> DirNative;
llvm::sys::path::native(SearchDirs[Idx].getFrameworkDir()->getName(),
DirNative);
// Search each of the ".framework" directories to load them as modules.
for (llvm::sys::fs::directory_iterator Dir(DirNative.str(), EC), DirEnd;
Dir != DirEnd && !EC; Dir.increment(EC)) {
if (llvm::sys::path::extension(Dir->path()) != ".framework")
continue;
const DirectoryEntry *FrameworkDir =
FileMgr.getDirectory(Dir->path());
if (!FrameworkDir)
continue;
// Load this framework module.
loadFrameworkModule(llvm::sys::path::stem(Dir->path()), FrameworkDir,
IsSystem);
}
continue;
}
continue;
// FIXME: Deal with header maps.
if (SearchDirs[Idx].isHeaderMap())
continue;
// Try to load a module map file for the search directory.
loadModuleMapFile(SearchDirs[Idx].getDir(), IsSystem,
/*IsFramework*/ false);
// Try to load module map files for immediate subdirectories of this
// search directory.
loadSubdirectoryModuleMaps(SearchDirs[Idx]);
}
// FIXME: Deal with header maps.
if (SearchDirs[Idx].isHeaderMap())
continue;
// Try to load a module map file for the search directory.
loadModuleMapFile(SearchDirs[Idx].getDir(), IsSystem, /*IsFramework*/false);
// Try to load module map files for immediate subdirectories of this search
// directory.
loadSubdirectoryModuleMaps(SearchDirs[Idx]);
}
// Populate the list of modules.
for (ModuleMap::module_iterator M = ModMap.module_begin(),
MEnd = ModMap.module_end();
@ -1290,6 +1298,9 @@ void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) {
}
void HeaderSearch::loadTopLevelSystemModules() {
if (!LangOpts.ModulesImplicitMaps)
return;
// Load module maps for each of the header search directories.
for (unsigned Idx = 0, N = SearchDirs.size(); Idx != N; ++Idx) {
// We only care about normal header directories.
@ -1305,6 +1316,9 @@ void HeaderSearch::loadTopLevelSystemModules() {
}
void HeaderSearch::loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir) {
assert(LangOpts.ModulesImplicitMaps &&
"Should not be loading subdirectory module maps");
if (SearchDir.haveSearchedAllModuleMaps())
return;

View File

@ -0,0 +1,3 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -x objective-c -fno-modules-implicit-maps -fmodules-cache-path=%t -fmodules -I %S/Inputs/private %s -verify
@import libPrivate1; // expected-error {{not found}}