Skip to content

[5.9 🍒][Dependency Scannning] Handle special case import of Clang Private "submodules" #66151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,18 @@ class ModuleDependencyInfo {
/// Add a dependency on the given module, if it was not already in the set.
void addModuleImport(ImportPath::Module module,
llvm::StringSet<> *alreadyAddedModules = nullptr) {
addModuleImport(module.front().Item.str(), alreadyAddedModules);
std::string ImportedModuleName = module.front().Item.str().str();
auto submodulePath = module.getSubmodulePath();
if (submodulePath.size() > 0 && !submodulePath[0].Item.empty()) {
assert(submodulePath.size() == 1 && "Unsupported Clang submodule import");
auto submoduleComponent = submodulePath[0];
// Special case: a submodule named "Foo.Private" can be moved to a top-level
// module named "Foo_Private". ClangImporter has special support for this.
if (submoduleComponent.Item.str() == "Private")
ImportedModuleName = ImportedModuleName + "_Private";
}

addModuleImport(ImportedModuleName, alreadyAddedModules);
}

/// Add all of the module imports in the given source
Expand Down
1 change: 1 addition & 0 deletions test/ScanDependencies/Inputs/CHeaders/X_Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void funcXPrivate(void);
4 changes: 4 additions & 0 deletions test/ScanDependencies/Inputs/CHeaders/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ module X {
header "X.h"
export *
}
module X_Private {
header "X_Private.h"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %empty-directory(%t.module-cache)
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t.module-cache %s -o %t.deps.json -I %S/Inputs/CHeaders

// RUN: %FileCheck %s < %t.deps.json
// CHECK: "clang": "X_Private"
import X.Private