From 08ebd61a80b3a0c68675a75bdff984fd2b7c6b39 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Tue, 21 Mar 2017 16:43:51 +0000 Subject: [PATCH] [Modules] Find PrivateHeaders when looking into subframeworks Fix the current parsing of subframeworks in modulemaps to lookup for headers based on whether they are frameworks. rdar://problem/30563982 llvm-svn: 298391 --- clang/lib/Lex/ModuleMap.cpp | 20 +++++++++++++------- .../Frameworks/Sub.framework/Headers/B.h | 1 + .../Frameworks/Sub.framework/Headers/Sub.h | 2 ++ .../Frameworks/Sub.framework/PrivateHeaders/BPriv.h | 1 + .../Sub.framework/PrivateHeaders/SubPriv.h | 1 + clang/test/Modules/Inputs/Main.framework/Headers/A.h | 1 + .../Modules/Inputs/Main.framework/Headers/Main.h | 2 ++ .../Inputs/Main.framework/Modules/module.modulemap | 12 ++++++++++++ .../Main.framework/Modules/module.private.modulemap | 11 +++++++++++ .../Inputs/Main.framework/PrivateHeaders/APriv.h | 1 + .../Inputs/Main.framework/PrivateHeaders/MainPriv.h | 1 + clang/test/Modules/find-privateheaders.m | 2 ++ 12 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/Headers/B.h create mode 100644 clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/Headers/Sub.h create mode 100644 clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/PrivateHeaders/BPriv.h create mode 100644 clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/PrivateHeaders/SubPriv.h create mode 100644 clang/test/Modules/Inputs/Main.framework/Headers/A.h create mode 100644 clang/test/Modules/Inputs/Main.framework/Headers/Main.h create mode 100644 clang/test/Modules/Inputs/Main.framework/Modules/module.modulemap create mode 100644 clang/test/Modules/Inputs/Main.framework/Modules/module.private.modulemap create mode 100644 clang/test/Modules/Inputs/Main.framework/PrivateHeaders/APriv.h create mode 100644 clang/test/Modules/Inputs/Main.framework/PrivateHeaders/MainPriv.h create mode 100644 clang/test/Modules/find-privateheaders.m diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 384e570..61ad5948 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1841,7 +1841,7 @@ void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind LeadingToken, Module::UnresolvedHeaderDirective Header; Header.FileName = Tok.getString(); Header.FileNameLoc = consumeToken(); - + // Check whether we already have an umbrella. if (LeadingToken == MMToken::UmbrellaKeyword && ActiveModule->Umbrella) { Diags.Report(Header.FileNameLoc, diag::err_mmap_umbrella_clash) @@ -1861,19 +1861,25 @@ void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind LeadingToken, // Search for the header file within the search directory. SmallString<128> FullPathName(Directory->getName()); unsigned FullPathLength = FullPathName.size(); - + if (ActiveModule->isPartOfFramework()) { appendSubframeworkPaths(ActiveModule, RelativePathName); - + unsigned RelativePathLength = RelativePathName.size(); + // Check whether this file is in the public headers. llvm::sys::path::append(RelativePathName, "Headers", Header.FileName); llvm::sys::path::append(FullPathName, RelativePathName); File = SourceMgr.getFileManager().getFile(FullPathName); - + + // Check whether this file is in the private headers. if (!File) { - // Check whether this file is in the private headers. - // FIXME: Should we retain the subframework paths here? - RelativePathName.clear(); + // Ideally, private modules in the form 'FrameworkName.Private' should + // be defined as 'module FrameworkName.Private', and not as + // 'framework module FrameworkName.Private', since a 'Private.Framework' + // does not usually exist. However, since both are currently widely used + // for private modules, make sure we find the right path in both cases. + RelativePathName.resize(ActiveModule->IsFramework ? 0 + : RelativePathLength); FullPathName.resize(FullPathLength); llvm::sys::path::append(RelativePathName, "PrivateHeaders", Header.FileName); diff --git a/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/Headers/B.h b/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/Headers/B.h new file mode 100644 index 0000000..761540b --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/Headers/B.h @@ -0,0 +1 @@ +// B.h diff --git a/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/Headers/Sub.h b/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/Headers/Sub.h new file mode 100644 index 0000000..fd86e3c --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/Headers/Sub.h @@ -0,0 +1,2 @@ +// Sub.h +#import "B.h" diff --git a/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/PrivateHeaders/BPriv.h b/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/PrivateHeaders/BPriv.h new file mode 100644 index 0000000..4ab49b7 --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/PrivateHeaders/BPriv.h @@ -0,0 +1 @@ +// BPriv.h diff --git a/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/PrivateHeaders/SubPriv.h b/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/PrivateHeaders/SubPriv.h new file mode 100644 index 0000000..f6ac618 --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/Frameworks/Sub.framework/PrivateHeaders/SubPriv.h @@ -0,0 +1 @@ +#import "BPriv.h" diff --git a/clang/test/Modules/Inputs/Main.framework/Headers/A.h b/clang/test/Modules/Inputs/Main.framework/Headers/A.h new file mode 100644 index 0000000..975f1f0 --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/Headers/A.h @@ -0,0 +1 @@ +// A.h diff --git a/clang/test/Modules/Inputs/Main.framework/Headers/Main.h b/clang/test/Modules/Inputs/Main.framework/Headers/Main.h new file mode 100644 index 0000000..cb8cc00 --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/Headers/Main.h @@ -0,0 +1,2 @@ +// Main.h +#import "A.h" diff --git a/clang/test/Modules/Inputs/Main.framework/Modules/module.modulemap b/clang/test/Modules/Inputs/Main.framework/Modules/module.modulemap new file mode 100644 index 0000000..9fab5d3 --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/Modules/module.modulemap @@ -0,0 +1,12 @@ +framework module Main { + umbrella header "Main.h" + + module * { export * } + export * + + framework module Sub { + umbrella header "Sub.h" + module * { export * } + export * + } +} diff --git a/clang/test/Modules/Inputs/Main.framework/Modules/module.private.modulemap b/clang/test/Modules/Inputs/Main.framework/Modules/module.private.modulemap new file mode 100644 index 0000000..54e8be7 --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/Modules/module.private.modulemap @@ -0,0 +1,11 @@ +module Main.Private { + umbrella header "MainPriv.h" + module * { export * } + export * +} + +module Main.Sub.Private { + umbrella header "SubPriv.h" + module * { export * } + export * +} diff --git a/clang/test/Modules/Inputs/Main.framework/PrivateHeaders/APriv.h b/clang/test/Modules/Inputs/Main.framework/PrivateHeaders/APriv.h new file mode 100644 index 0000000..6ac683c --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/PrivateHeaders/APriv.h @@ -0,0 +1 @@ +// APriv.h diff --git a/clang/test/Modules/Inputs/Main.framework/PrivateHeaders/MainPriv.h b/clang/test/Modules/Inputs/Main.framework/PrivateHeaders/MainPriv.h new file mode 100644 index 0000000..6810301 --- /dev/null +++ b/clang/test/Modules/Inputs/Main.framework/PrivateHeaders/MainPriv.h @@ -0,0 +1 @@ +#import "APriv.h" diff --git a/clang/test/Modules/find-privateheaders.m b/clang/test/Modules/find-privateheaders.m new file mode 100644 index 0000000..c5e82ac7 --- /dev/null +++ b/clang/test/Modules/find-privateheaders.m @@ -0,0 +1,2 @@ +// RUN: %clang_cc1 -fmodules -fsyntax-only -F%S/Inputs %s +#import "Main/Main.h" -- 2.7.4