https://github.com/cyndyishida created https://github.com/llvm/llvm-project/pull/238860
Respect resolving modulemaps with `-fmodulemap-allow-subdirectory-search` in `getModuleMapsForModules` to match the normal scan's lookup. Note this option is default disabled. >From e62aff43fdddc1dd102f072bba9e532bbae42ef2 Mon Sep 17 00:00:00 2001 From: Cyndy Ishida <[email protected]> Date: Wed, 4 Nov 2026 08:37:39 -0800 Subject: [PATCH] [clang][DepScan] Support subdirectory seach in getModuleMapsForModules Respect resolving modulemaps with `-fmodulemap-allow-subdirectory-search` in getModuleMapsForModules. Note this is default disabled. --- .../DependencyScanningWorker.cpp | 3 +- .../Tooling/DependencyScannerTest.cpp | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/clang/lib/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/DependencyScanning/DependencyScanningWorker.cpp index 410f38c333a81e..ed620617d6fd61 100644 --- a/clang/lib/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/DependencyScanning/DependencyScanningWorker.cpp @@ -737,7 +737,8 @@ class ModuleMapLookup { // Skip over prebuilt modules. if (HasPrebuiltModules && !HS.getPrebuiltModuleFileName(Name).empty()) continue; - OptionalFileEntryRef File = HS.lookupModuleMapFileForModule(Name); + OptionalFileEntryRef File = HS.lookupModuleMapFileForModule( + Name, /*AllowExtraModuleMapSearch=*/true); // Skip over modules that didn't find a modulemap. if (!File) continue; diff --git a/clang/unittests/Tooling/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScannerTest.cpp index f9a60b9c1f6e98..8e2f0455288fd8 100644 --- a/clang/unittests/Tooling/DependencyScannerTest.cpp +++ b/clang/unittests/Tooling/DependencyScannerTest.cpp @@ -534,6 +534,37 @@ TEST_F(GetModuleMapsForModulesTest, NotFound) { EXPECT_TRUE(ModuleMaps->empty()); } +// Verify a modulemap that can only be resolved with subdirectory search, fails +// when disabled but passes otherwise. +TEST_F(GetModuleMapsForModulesTest, SubdirectorySearch) { + addFile("/root/test.m", "\n"); + addFile("/root/a/Sub/module.modulemap", "module A { header \"a.h\" }\n"); + addFile("/root/a/Sub/a.h", "\n"); + + std::pair<StringRef, StringRef> Cases[] = { + {"-fmodulemap-allow-subdirectory-search", "/root/a/Sub/module.modulemap"}, + {"-fno-modulemap-allow-subdirectory-search", ""}}; + for (auto [Flag, Expected] : Cases) { + SCOPED_TRACE(Flag); + std::vector<std::string> CommandLine = { + "clang", "-target", "x86_64-apple-macosx10.7", + "-c", "test.m", "-fmodules", + "-I/root/a", Flag.str()}; + + TextDiagnosticBuffer ScanDiags; + EXPECT_EQ(llvm::sys::path::convert_to_slash( + scanModuleMapFile(CommandLine, "A", ScanDiags)), + Expected); + + TextDiagnosticBuffer LookupDiags; + std::optional<llvm::StringMap<std::string>> ModuleMaps = + getModuleMaps(CommandLine, {"A"}, LookupDiags); + ASSERT_TRUE(ModuleMaps); + EXPECT_EQ(llvm::sys::path::convert_to_slash(ModuleMaps->lookup("A")), + Expected); + } +} + // Verify a command line that cannot be set up reports // an error. TEST_F(GetModuleMapsForModulesTest, IllFormedCommandLine) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
