mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Dependency Scanning] Emit a note if a dependency cycle is between the source target and another Swift module with the same name
The note will point the user to where the "other" module with the same name is located and mention whether it is an SDK module. This is nice to have in various circumstances where developers attempt to define a module with the same name as a Swift module that already exists on their search paths, for example in the SDK.
This commit is contained in:
@@ -88,6 +88,30 @@ ModuleDependencyInfo::getAsClangModule() const {
|
||||
return dyn_cast<ClangModuleDependencyStorage>(storage.get());
|
||||
}
|
||||
|
||||
std::string ModuleDependencyInfo::getModuleDefiningPath() const {
|
||||
std::string path = "";
|
||||
switch (getKind()) {
|
||||
case swift::ModuleDependencyKind::SwiftInterface:
|
||||
path = getAsSwiftInterfaceModule()->swiftInterfaceFile;
|
||||
break;
|
||||
case swift::ModuleDependencyKind::SwiftBinary:
|
||||
path = getAsSwiftBinaryModule()->compiledModulePath;
|
||||
break;
|
||||
case swift::ModuleDependencyKind::Clang:
|
||||
path = getAsClangModule()->moduleMapFile;
|
||||
break;
|
||||
case swift::ModuleDependencyKind::SwiftSource:
|
||||
path = getAsSwiftSourceModule()->sourceFiles.front();
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Unexpected dependency kind");
|
||||
}
|
||||
|
||||
// Relative to the `module.modulemap` or `.swiftinterface` or `.swiftmodule`,
|
||||
// the defininig path is the parent directory of the file.
|
||||
return llvm::sys::path::parent_path(path).str();
|
||||
}
|
||||
|
||||
void ModuleDependencyInfo::addTestableImport(ImportPath::Module module) {
|
||||
assert(getAsSwiftSourceModule() && "Expected source module for addTestableImport.");
|
||||
dyn_cast<SwiftSourceModuleDependenciesStorage>(storage.get())->addTestableImport(module);
|
||||
|
||||
Reference in New Issue
Block a user