r177621 - <rdar://problem/13037793> Allow the names of modules to differ from the name of their subdirectory in the include path.
Douglas Gregor
dgregor at apple.com
Wed Mar 20 18:08:50 PDT 2013
Author: dgregor
Date: Wed Mar 20 20:08:50 2013
New Revision: 177621
URL: http://llvm.org/viewvc/llvm-project?rev=177621&view=rev
Log:
<rdar://problem/13037793> Allow the names of modules to differ from the name of their subdirectory in the include path.
Added:
cfe/trunk/test/Modules/Inputs/oldname/
cfe/trunk/test/Modules/Inputs/oldname/module.map
cfe/trunk/test/Modules/Inputs/oldname/new_name.h
cfe/trunk/test/Modules/renamed.m
Modified:
cfe/trunk/include/clang/Lex/DirectoryLookup.h
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/test/Modules/Inputs/Modified/B.h
cfe/trunk/test/Modules/Inputs/Modified/module.map
cfe/trunk/test/Modules/modify-module.m
Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=177621&r1=177620&r2=177621&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/DirectoryLookup.h (original)
+++ cfe/trunk/include/clang/Lex/DirectoryLookup.h Wed Mar 20 20:08:50 2013
@@ -56,6 +56,10 @@ private:
/// \brief Whether this is a header map used when building a framework.
unsigned IsIndexHeaderMap : 1;
+
+ /// \brief Whether we've performed an exhaustive search for module maps
+ /// within the subdirectories of this directory.
+ unsigned SearchedAllModuleMaps : 1;
public:
/// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
@@ -64,7 +68,7 @@ public:
bool isFramework)
: DirCharacteristic(DT),
LookupType(isFramework ? LT_Framework : LT_NormalDir),
- IsIndexHeaderMap(false) {
+ IsIndexHeaderMap(false), SearchedAllModuleMaps(false) {
u.Dir = dir;
}
@@ -73,7 +77,7 @@ public:
DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
bool isIndexHeaderMap)
: DirCharacteristic(DT), LookupType(LT_HeaderMap),
- IsIndexHeaderMap(isIndexHeaderMap) {
+ IsIndexHeaderMap(isIndexHeaderMap), SearchedAllModuleMaps(false) {
u.Map = map;
}
@@ -109,6 +113,16 @@ public:
/// isHeaderMap - Return true if this is a header map, not a normal directory.
bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
+ /// \brief Determine whether we have already searched this entire
+ /// directory for module maps.
+ bool haveSearchedAllModuleMaps() const { return SearchedAllModuleMaps; }
+
+ /// \brief Specify whether we have already searched all of the subdirectories
+ /// for module maps.
+ void setSearchedAllModuleMaps(bool SAMM) {
+ SearchedAllModuleMaps = SAMM;
+ }
+
/// DirCharacteristic - The type of directory this is, one of the DirType enum
/// values.
SrcMgr::CharacteristicKind getDirCharacteristic() const {
Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=177621&r1=177620&r2=177621&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Mar 20 20:08:50 2013
@@ -505,7 +505,11 @@ private:
Module *loadFrameworkModule(StringRef Name,
const DirectoryEntry *Dir,
bool IsSystem);
-
+
+ /// \brief Load all of the module maps within the immediate subdirectories
+ /// of the given search directory.
+ void loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir);
+
public:
/// \brief Retrieve the module map.
ModuleMap &getModuleMap() { return ModMap; }
Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=177621&r1=177620&r2=177621&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Mar 20 20:08:50 2013
@@ -181,8 +181,22 @@ Module *HeaderSearch::lookupModule(Strin
if (Module)
break;
}
+
+ // If we've already performed the exhaustive search for module maps in this
+ // search directory, don't do it again.
+ if (SearchDirs[Idx].haveSearchedAllModuleMaps())
+ continue;
+
+ // Load all module maps in the immediate subdirectories of this search
+ // directory.
+ loadSubdirectoryModuleMaps(SearchDirs[Idx]);
+
+ // Look again for the module.
+ Module = ModMap.findModule(ModuleName);
+ if (Module)
+ break;
}
-
+
return Module;
}
@@ -1126,13 +1140,7 @@ void HeaderSearch::collectAllModules(Sma
// Try to load module map files for immediate subdirectories of this search
// directory.
- llvm::error_code EC;
- SmallString<128> DirNative;
- llvm::sys::path::native(SearchDirs[Idx].getDir()->getName(), DirNative);
- for (llvm::sys::fs::directory_iterator Dir(DirNative.str(), EC), DirEnd;
- Dir != DirEnd && !EC; Dir.increment(EC)) {
- loadModuleMapFile(Dir->path());
- }
+ loadSubdirectoryModuleMaps(SearchDirs[Idx]);
}
// Populate the list of modules.
@@ -1142,3 +1150,18 @@ void HeaderSearch::collectAllModules(Sma
Modules.push_back(M->getValue());
}
}
+
+void HeaderSearch::loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir) {
+ if (SearchDir.haveSearchedAllModuleMaps())
+ return;
+
+ llvm::error_code EC;
+ SmallString<128> DirNative;
+ llvm::sys::path::native(SearchDir.getDir()->getName(), DirNative);
+ for (llvm::sys::fs::directory_iterator Dir(DirNative.str(), EC), DirEnd;
+ Dir != DirEnd && !EC; Dir.increment(EC)) {
+ loadModuleMapFile(Dir->path());
+ }
+
+ SearchDir.setSearchedAllModuleMaps(true);
+}
Modified: cfe/trunk/test/Modules/Inputs/Modified/B.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/Modified/B.h?rev=177621&r1=177620&r2=177621&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/Modified/B.h (original)
+++ cfe/trunk/test/Modules/Inputs/Modified/B.h Wed Mar 20 20:08:50 2013
@@ -1,3 +1,3 @@
- at import A;
+ at import ModA;
int getB();
Modified: cfe/trunk/test/Modules/Inputs/Modified/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/Modified/module.map?rev=177621&r1=177620&r2=177621&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/Modified/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/Modified/module.map Wed Mar 20 20:08:50 2013
@@ -1,5 +1,5 @@
-module A { header "A.h" }
-module B {
+module ModA { header "A.h" }
+module ModB {
header "B.h"
export *
}
Added: cfe/trunk/test/Modules/Inputs/oldname/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/oldname/module.map?rev=177621&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/oldname/module.map (added)
+++ cfe/trunk/test/Modules/Inputs/oldname/module.map Wed Mar 20 20:08:50 2013
@@ -0,0 +1,4 @@
+module NewName {
+ header "new_name.h"
+ export *
+}
Added: cfe/trunk/test/Modules/Inputs/oldname/new_name.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/oldname/new_name.h?rev=177621&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/oldname/new_name.h (added)
+++ cfe/trunk/test/Modules/Inputs/oldname/new_name.h Wed Mar 20 20:08:50 2013
@@ -0,0 +1 @@
+int same_api;
Modified: cfe/trunk/test/Modules/modify-module.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/modify-module.m?rev=177621&r1=177620&r2=177621&view=diff
==============================================================================
--- cfe/trunk/test/Modules/modify-module.m (original)
+++ cfe/trunk/test/Modules/modify-module.m Wed Mar 20 20:08:50 2013
@@ -11,9 +11,9 @@
// RUN: %clang_cc1 -fdisable-module-hash -fmodules-cache-path=%t/cache -fmodules -I %t/include %s -verify
// RUN: echo 'int getA(); int getA2();' > %t/include/A.h
// RUN: %clang_cc1 -fdisable-module-hash -fmodules-cache-path=%t/cache -fmodules -I %t/include %s -verify
-// RUN: rm %t/cache/A.pcm
+// RUN: rm %t/cache/ModA.pcm
// RUN: %clang_cc1 -fdisable-module-hash -fmodules-cache-path=%t/cache -fmodules -I %t/include %s -verify
-// RUN: touch %t/cache/A.pcm
+// RUN: touch %t/cache/ModA.pcm
// RUN: %clang_cc1 -fdisable-module-hash -fmodules-cache-path=%t/cache -fmodules -I %t/include %s -verify
// expected-no-diagnostics
@@ -21,7 +21,7 @@
// FIXME: It is intended to suppress this on win32.
// REQUIRES: ansi-escape-sequences
- at import B;
+ at import ModB;
int getValue() { return getA() + getB(); }
Added: cfe/trunk/test/Modules/renamed.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/renamed.m?rev=177621&view=auto
==============================================================================
--- cfe/trunk/test/Modules/renamed.m (added)
+++ cfe/trunk/test/Modules/renamed.m Wed Mar 20 20:08:50 2013
@@ -0,0 +1,8 @@
+ at import NewName;
+
+int f() { return same_api; }
+
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -I %S/Inputs -fmodules-cache-path=%t %s -verify
+
+// expected-no-diagnostics
More information about the cfe-commits
mailing list