[Dependency Scanning] On failure to locate a module, attempt to diagnose if binary dependencies contain search paths with this module.

Unlike with implicitly-built modules (prior to Swift 6 mode), explicitly-built modules require that all search paths be specified explicitly and no longer inherit search paths serialized into discovered Swift binary modules. This behavior was never intentional and is considered a bug. This change adds a diagnostic note to a scan failure: for each binary Swift module dependency, the scanner will attempt to execute a dependency scanning query for each serialized search path inside that module. If such diagnostic query returns a result, a diagnostic will be emitted to inform the user that the dependency may be found in the search path configuration of another Swift binary module dependency, specifying which search path contains the "missing" module, and stating that such search paths are not automatically inherited by the current compilation.
This commit is contained in:
Artem Chikin
2025-06-02 17:27:03 -07:00
parent 47e5edeb3e
commit 90f2fba2ae
8 changed files with 262 additions and 85 deletions

View File

@@ -22,6 +22,7 @@
#include "swift/AST/LinkLibrary.h"
#include "swift/Basic/CXXStdlibKind.h"
#include "swift/Basic/LLVM.h"
#include "swift/Serialization/Validation.h"
#include "clang/CAS/CASOptions.h"
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
@@ -406,15 +407,18 @@ public:
StringRef sourceInfoPath,
ArrayRef<ScannerImportStatementInfo> moduleImports,
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
ArrayRef<LinkLibrary> linkLibraries, StringRef headerImport,
StringRef definingModuleInterface, bool isFramework, bool isStatic,
StringRef moduleCacheKey, StringRef userModuleVersion)
ArrayRef<LinkLibrary> linkLibraries,
ArrayRef<serialization::SearchPath> serializedSearchPaths,
StringRef headerImport, StringRef definingModuleInterface,
bool isFramework, bool isStatic, StringRef moduleCacheKey,
StringRef userModuleVersion)
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftBinary,
moduleImports, optionalModuleImports,
linkLibraries, moduleCacheKey),
compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath),
sourceInfoPath(sourceInfoPath), headerImport(headerImport),
definingModuleInterfacePath(definingModuleInterface),
serializedSearchPaths(serializedSearchPaths),
isFramework(isFramework), isStatic(isStatic),
userModuleVersion(userModuleVersion) {}
@@ -441,6 +445,9 @@ public:
/// Source files on which the header inputs depend.
std::vector<std::string> headerSourceFiles;
/// Search paths this module was built with which got serialized
std::vector<serialization::SearchPath> serializedSearchPaths;
/// (Clang) modules on which the header inputs depend.
std::vector<ModuleDependencyID> headerModuleDependencies;
@@ -613,15 +620,17 @@ public:
StringRef sourceInfoPath,
ArrayRef<ScannerImportStatementInfo> moduleImports,
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
ArrayRef<LinkLibrary> linkLibraries, StringRef headerImport,
StringRef definingModuleInterface, bool isFramework,
bool isStatic, StringRef moduleCacheKey, StringRef userModuleVer) {
ArrayRef<LinkLibrary> linkLibraries,
ArrayRef<serialization::SearchPath> serializedSearchPaths,
StringRef headerImport, StringRef definingModuleInterface,
bool isFramework, bool isStatic, StringRef moduleCacheKey,
StringRef userModuleVer) {
return ModuleDependencyInfo(
std::make_unique<SwiftBinaryModuleDependencyStorage>(
compiledModulePath, moduleDocPath, sourceInfoPath, moduleImports,
optionalModuleImports, linkLibraries, headerImport,
definingModuleInterface,isFramework, isStatic, moduleCacheKey,
userModuleVer));
optionalModuleImports, linkLibraries, serializedSearchPaths,
headerImport, definingModuleInterface,isFramework, isStatic,
moduleCacheKey, userModuleVer));
}
/// Describe the main Swift module.