[AST] Treat platform modules as non-user

Modules defined within the SDK are considered
non-user modules, extend this to any module found
within the parent platform directory if there is
one. This ensures we include modules such as
XCTest and Testing.

rdar://131854240
This commit is contained in:
Hamish Knight
2024-08-23 14:23:37 +01:00
parent 7075c05d62
commit 940f5f7c2a
6 changed files with 70 additions and 4 deletions

View File

@@ -80,6 +80,34 @@ void ModuleSearchPathLookup::rebuildLookupTable(const SearchPathOptions *Opts,
State.IsPopulated = true;
}
static std::string computeSDKPlatformPath(StringRef SDKPath,
llvm::vfs::FileSystem *FS) {
if (SDKPath.empty())
return "";
SmallString<128> platformPath;
if (auto err = FS->getRealPath(SDKPath, platformPath))
llvm::sys::path::append(platformPath, SDKPath);
llvm::sys::path::remove_filename(platformPath); // specific SDK
llvm::sys::path::remove_filename(platformPath); // SDKs
llvm::sys::path::remove_filename(platformPath); // Developer
if (!llvm::sys::path::filename(platformPath).endswith(".platform"))
return "";
return platformPath.str().str();
}
std::optional<StringRef>
SearchPathOptions::getSDKPlatformPath(llvm::vfs::FileSystem *FS) const {
if (!SDKPlatformPath)
SDKPlatformPath = computeSDKPlatformPath(getSDKPath(), FS);
if (SDKPlatformPath->empty())
return std::nullopt;
return *SDKPlatformPath;
}
void SearchPathOptions::dump(bool isDarwin) const {
llvm::errs() << "Module import search paths (non system):\n";
for (auto Entry : llvm::enumerate(getImportSearchPaths())) {