[DependencyScanning] Handle testable dependencies correctly

Teach scanner to pick and choose binary modules correctly based on if it
is testable import or not. Some situations that scanner need to be
careful when testable is involved:

* When it is a regular import, it should not import binary modules that
  are built with -enable-testing, it should prefer interfaces if that is
  available.
* When testable import, it should only load binary module and it should
  make sure the internal imports from binary modules are actually
  required for testable import to work.

If a testable import only find a regular binary module, dependency
scanner currently will just preceed with such module and leave the
diagnostics to swift-frontend, because the alternative (failed to find
module) can be confusing to users.

rdar://125914165
This commit is contained in:
Steven Wu
2024-04-04 14:16:21 -07:00
parent 0e12f2042e
commit d4c90d6eeb
6 changed files with 154 additions and 64 deletions

View File

@@ -24,6 +24,7 @@
namespace swift {
class ModuleFile;
class PathObfuscator;
class ModuleFileSharedCore;
enum class ModuleLoadingBehavior;
namespace file_types {
enum ID : uint8_t;
@@ -162,22 +163,18 @@ protected:
}
/// Scan the given serialized module file to determine dependencies.
llvm::ErrorOr<ModuleDependencyInfo> scanModuleFile(Twine modulePath, bool isFramework);
llvm::ErrorOr<ModuleDependencyInfo>
scanModuleFile(Twine modulePath, bool isFramework, bool isTestableImport);
struct BinaryModuleImports {
llvm::StringSet<> moduleImports;
std::string headerImport;
};
static llvm::ErrorOr<BinaryModuleImports>
getImportsOfModule(Twine modulePath,
static BinaryModuleImports
getImportsOfModule(const ModuleFileSharedCore &loadedModule,
ModuleLoadingBehavior transitiveBehavior,
bool isFramework,
bool isRequiredOSSAModules,
StringRef SDKName,
StringRef packageName,
llvm::vfs::FileSystem *fileSystem,
PathObfuscator &recoverer);
StringRef packageName);
/// Load the module file into a buffer and also collect its module name.
static std::unique_ptr<llvm::MemoryBuffer>