llvm-project/clang/test/Driver/modulemap-allow-subdirectory-search.c
Volodymyr Sapsai cbd5ba20d1
[Modules] Don't search for modulemaps in the immediate sub-directories of search paths for recent Apple SDKs. (#100005)
Such searches can be costly and non-intuitive. We've seen complaints
from developers that they don't expect clang to find modules on their
own and not in search paths that developers provide. Keeping the search
of modulemaps in subdirectories for code completion as it provides
better user experience.

If you are defining module "UsefulCode" in
"include/UnrelatedName/module.modulemap", it is recommended to rename
the directory "UnrelatedName" to "UsefulCode". If you cannot do so, you
can add to "include/module.modulemap" a line like `extern module
UsefulCode "UnrelatedName/module.modulemap"`, so clang can find module
"UsefulCode" without checking each subdirectory in "include/".

rdar://106677321

---------

Co-authored-by: Jan Svoboda <jan@svoboda.ai>
2024-07-23 13:59:44 -07:00

28 lines
1.3 KiB
C

// RUN: rm -rf %t
// RUN: split-file %s %t
// Check that with a sufficiently new SDK not searching for module maps in subdirectories.
// New SDK.
// RUN: %clang -target x86_64-apple-macos10.13 -isysroot %t/MacOSX15.0.sdk -fmodules %t/test.c -### 2>&1 \
// RUN: | FileCheck --check-prefix=NO-SUBDIRECTORIES %t/test.c
// Old SDK.
// RUN: %clang -target x86_64-apple-macos10.13 -isysroot %t/MacOSX14.0.sdk -fmodules %t/test.c -### 2>&1 \
// RUN: | FileCheck --check-prefix=SEARCH-SUBDIRECTORIES %t/test.c
// Non-Darwin platform.
// RUN: %clang -target i386-unknown-linux -isysroot %t/MacOSX15.0.sdk -fmodules %t/test.c -### 2>&1 \
// RUN: | FileCheck --check-prefix=SEARCH-SUBDIRECTORIES %t/test.c
// New SDK overriding the default.
// RUN: %clang -target x86_64-apple-macos10.13 -isysroot %t/MacOSX15.0.sdk -fmodules %t/test.c -fmodulemap-allow-subdirectory-search -### 2>&1 \
// RUN: | FileCheck --check-prefix=SEARCH-SUBDIRECTORIES %t/test.c
//--- test.c
// NO-SUBDIRECTORIES: "-fno-modulemap-allow-subdirectory-search"
// SEARCH-SUBDIRECTORIES-NOT: "-fno-modulemap-allow-subdirectory-search"
//--- MacOSX15.0.sdk/SDKSettings.json
{"Version":"15.0", "MaximumDeploymentTarget": "15.0.99"}
//--- MacOSX14.0.sdk/SDKSettings.json
{"Version":"14.0", "MaximumDeploymentTarget": "14.0.99"}