r191284 - Add -fmodule-map-file option.
Daniel Jasper
djasper at google.com
Tue Sep 24 02:27:14 PDT 2013
Author: djasper
Date: Tue Sep 24 04:27:13 2013
New Revision: 191284
URL: http://llvm.org/viewvc/llvm-project?rev=191284&view=rev
Log:
Add -fmodule-map-file option.
With this option, arbitrarily named module map files can be specified
to be loaded as required for headers in the respective (sub)directories.
This, together with the extern module declaration allows for specifying
module maps in a modular fashion without the need for files called
"module.map".
Among other things, this allows a directory to contain two modules that
are completely independent of one another.
Review: http://llvm-reviews.chandlerc.com/D1697.
Added:
cfe/trunk/test/Modules/Inputs/modular_maps/modulea.map
- copied, changed from r191283, cfe/trunk/test/Modules/Inputs/modular_maps/module.map
Removed:
cfe/trunk/test/Modules/Inputs/modular_maps/module.map
Modified:
cfe/trunk/docs/Modules.rst
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/test/Modules/modular_maps.cpp
Modified: cfe/trunk/docs/Modules.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Modules.rst?rev=191284&r1=191283&r2=191284&view=diff
==============================================================================
--- cfe/trunk/docs/Modules.rst (original)
+++ cfe/trunk/docs/Modules.rst Tue Sep 24 04:27:13 2013
@@ -194,6 +194,9 @@ Command-line parameters
``-fmodule-name=module-id``
Consider a source file as a part of the given module.
+``-fmodule-map-file=<file>``
+ Load the given module map file if a header from its directory or one of its subdirectories is loaded.
+
Module Map Language
===================
Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=191284&r1=191283&r2=191284&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Sep 24 04:27:13 2013
@@ -483,9 +483,12 @@ def fno_deprecated_macro : Flag<["-"], "
def nostdsysteminc : Flag<["-"], "nostdsysteminc">,
HelpText<"Disable standard system #include directories">;
-def fmodule_name : Joined<["-"], "fmodule-name=">,
+def fmodule_name : Joined<["-"], "fmodule-name=">,
MetaVarName<"<name>">,
- HelpText<"Specify the name of the module to build">;
+ HelpText<"Specify the name of the module to build">;
+def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
+ MetaVarName<"<file>">,
+ HelpText<"Load this module map file">;
def fdisable_module_hash : Flag<["-"], "fdisable-module-hash">,
HelpText<"Disable the module hash">;
def c_isystem : JoinedOrSeparate<["-"], "c-isystem">, MetaVarName<"<directory>">,
Modified: cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearchOptions.h?rev=191284&r1=191283&r2=191284&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearchOptions.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearchOptions.h Tue Sep 24 04:27:13 2013
@@ -120,6 +120,9 @@ public:
/// of computing the module hash.
llvm::SetVector<std::string> ModulesIgnoreMacros;
+ /// \brief The set of user-provided module-map-files.
+ llvm::SetVector<std::string> ModuleMapFiles;
+
/// Include the compiler builtin includes.
unsigned UseBuiltinIncludes : 1;
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=191284&r1=191283&r2=191284&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Sep 24 04:27:13 2013
@@ -896,6 +896,9 @@ static void ParseHeaderSearchArgs(Header
StringRef MacroDef = (*it)->getValue();
Opts.ModulesIgnoreMacros.insert(MacroDef.split('=').first);
}
+ std::vector<std::string> ModuleMapFiles =
+ Args.getAllArgValues(OPT_fmodule_map_file);
+ Opts.ModuleMapFiles.insert(ModuleMapFiles.begin(), ModuleMapFiles.end());
// Add -I..., -F..., and -index-header-map options in order.
bool IsIndexHeaderMap = false;
Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=191284&r1=191283&r2=191284&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Tue Sep 24 04:27:13 2013
@@ -941,26 +941,48 @@ bool HeaderSearch::hasModuleMap(StringRe
DirName = llvm::sys::path::parent_path(DirName);
if (DirName.empty())
return false;
-
+
// Determine whether this directory exists.
const DirectoryEntry *Dir = FileMgr.getDirectory(DirName);
if (!Dir)
return false;
- // Try to load the module map file in this directory.
+ // Load user-specified module map files in 'Dir'.
+ bool ModuleMapFound = false;
+ for (llvm::SetVector<std::string>::iterator
+ I = HSOpts->ModuleMapFiles.begin(),
+ E = HSOpts->ModuleMapFiles.end();
+ I != E; ++I) {
+ StringRef ModuleMapFileDir = llvm::sys::path::parent_path(*I);
+ if (!llvm::sys::fs::equivalent(ModuleMapFileDir, DirName))
+ continue;
+
+ const FileEntry *File = FileMgr.getFile(*I);
+ if (!File)
+ continue;
+
+ loadModuleMapFile(File, /*IsSystem=*/false);
+ ModuleMapFound = true;
+ }
+
+ // Try to load the "module.map" file in this directory.
switch (loadModuleMapFile(Dir, IsSystem)) {
case LMM_NewlyLoaded:
case LMM_AlreadyLoaded:
+ ModuleMapFound = true;
+ break;
+
+ case LMM_NoDirectory:
+ case LMM_InvalidModuleMap:
+ break;
+ }
+
+ if (ModuleMapFound) {
// Success. All of the directories we stepped through inherit this module
// map file.
for (unsigned I = 0, N = FixUpDirectories.size(); I != N; ++I)
DirectoryHasModuleMap[FixUpDirectories[I]] = true;
-
return true;
-
- case LMM_NoDirectory:
- case LMM_InvalidModuleMap:
- break;
}
// If we hit the top of our search, we're done.
Removed: cfe/trunk/test/Modules/Inputs/modular_maps/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/modular_maps/module.map?rev=191283&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/modular_maps/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/modular_maps/module.map (removed)
@@ -1,6 +0,0 @@
-module A {
- header "a.h"
-}
-
-extern module B "moduleb.map"
-
Copied: cfe/trunk/test/Modules/Inputs/modular_maps/modulea.map (from r191283, cfe/trunk/test/Modules/Inputs/modular_maps/module.map)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/modular_maps/modulea.map?p2=cfe/trunk/test/Modules/Inputs/modular_maps/modulea.map&p1=cfe/trunk/test/Modules/Inputs/modular_maps/module.map&r1=191283&r2=191284&rev=191284&view=diff
==============================================================================
(empty)
Modified: cfe/trunk/test/Modules/modular_maps.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/modular_maps.cpp?rev=191284&r1=191283&r2=191284&view=diff
==============================================================================
--- cfe/trunk/test/Modules/modular_maps.cpp (original)
+++ cfe/trunk/test/Modules/modular_maps.cpp Tue Sep 24 04:27:13 2013
@@ -1,5 +1,5 @@
// RUN: rm -rf %t
-// RUN: %clang_cc1 -x objective-c++ -fmodules-cache-path=%t -fmodules -I %S/Inputs/modular_maps %s -verify
+// RUN: %clang_cc1 -x objective-c++ -fmodules-cache-path=%t -fmodules -fmodule-map-file=%S/Inputs/modular_maps/modulea.map -I %S/Inputs/modular_maps %s -verify
#include "a.h"
#include "b.h" // expected-error {{private header}}
More information about the cfe-commits
mailing list