Skip to content

Commit 569fe92

Browse files
committed
[Dependency Scannning] Handle special case import of Clang Private "submodules"
There is a special case that already exists in 'ClangImporter' for implicit module loading: Import of a "submodule" named "Foo.Private" is treated as a top-level module named "Foo_Private". Clang has special support for this. Resolves rdar://108287140
1 parent 82b3e75 commit 569fe92

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,18 @@ class ModuleDependencyInfo {
525525
/// Add a dependency on the given module, if it was not already in the set.
526526
void addModuleImport(ImportPath::Module module,
527527
llvm::StringSet<> *alreadyAddedModules = nullptr) {
528-
addModuleImport(module.front().Item.str(), alreadyAddedModules);
528+
std::string ImportedModuleName = module.front().Item.str().str();
529+
auto submodulePath = module.getSubmodulePath();
530+
if (submodulePath.size() > 0 && !submodulePath[0].Item.empty()) {
531+
assert(submodulePath.size() == 1 && "Unsupported Clang submodule import");
532+
auto submoduleComponent = submodulePath[0];
533+
// Special case: a submodule named "Foo.Private" can be moved to a top-level
534+
// module named "Foo_Private". ClangImporter has special support for this.
535+
if (submoduleComponent.Item.str() == "Private")
536+
ImportedModuleName = ImportedModuleName + "_Private";
537+
}
538+
539+
addModuleImport(ImportedModuleName, alreadyAddedModules);
529540
}
530541

531542
/// Add all of the module imports in the given source
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void funcXPrivate(void);

test/ScanDependencies/Inputs/CHeaders/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ module X {
4242
header "X.h"
4343
export *
4444
}
45+
module X_Private {
46+
header "X_Private.h"
47+
export *
48+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %empty-directory(%t.module-cache)
2+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t.module-cache %s -o %t.deps.json -I %S/Inputs/CHeaders
3+
4+
// RUN: %FileCheck %s < %t.deps.json
5+
// CHECK: "clang": "X_Private"
6+
import X.Private
7+

0 commit comments

Comments
 (0)