Skip to content

Commit 5311021

Browse files
author
Nathan Hawes
authored
Merge pull request #32024 from kastiglione/dl/index-apply--index-ignore-system-modules-to-clang-modules
[Index] Apply -index-ignore-system-modules to system clang modules
2 parents e11f167 + 258ceda commit 5311021

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

lib/Index/IndexRecord.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,16 @@ static void addModuleDependencies(ArrayRef<ModuleDecl::ImportedModule> imports,
416416
StringRef moduleName = mod->getNameStr();
417417
bool withoutUnitName = true;
418418
if (FU->getKind() == FileUnitKind::ClangModule) {
419-
withoutUnitName = false;
420419
auto clangModUnit = cast<ClangModuleUnit>(LFU);
421-
if (auto clangMod = clangModUnit->getUnderlyingClangModule()) {
422-
moduleName = clangMod->getTopLevelModuleName();
423-
// FIXME: clang's -Rremarks do not seem to go through Swift's
424-
// diagnostic emitter.
425-
clang::index::emitIndexDataForModuleFile(clangMod,
426-
clangCI, unitWriter);
420+
if (!clangModUnit->isSystemModule() || indexSystemModules) {
421+
withoutUnitName = false;
422+
if (auto clangMod = clangModUnit->getUnderlyingClangModule()) {
423+
moduleName = clangMod->getTopLevelModuleName();
424+
// FIXME: clang's -Rremarks do not seem to go through Swift's
425+
// diagnostic emitter.
426+
clang::index::emitIndexDataForModuleFile(clangMod,
427+
clangCI, unitWriter);
428+
}
427429
}
428430
} else {
429431
// Serialized AST file.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// Make a basic clang framework to import
4+
//
5+
// RUN: %empty-directory(%t/MySystemFramework.framework/Headers)
6+
// RUN: %empty-directory(%t/MySystemFramework.framework/Modules)
7+
// RUN: echo 'void someSystemFunc(int arg);' > %t/MySystemFramework.framework/Headers/MySystemFramework.h
8+
// RUN: echo 'framework module MySystemFramework { umbrella header "MySystemFramework.h" export * }' > %t/MySystemFramework.framework/Modules/module.modulemap
9+
10+
import MySystemFramework
11+
someSystemFunc(2)
12+
13+
// Index this file with and without ignoring system frameworks
14+
//
15+
// RUN: %target-swiftc_driver -index-store-path %t/idx1 -o %t/file.o -Fsystem %t -typecheck %s
16+
// RUN: %target-swiftc_driver -index-store-path %t/idx2 -o %t/file.o -index-ignore-system-modules -Fsystem %t -typecheck %s
17+
// RUN: c-index-test core -print-unit %t/idx1 | %FileCheck --check-prefixes=ALLOWSYSTEM,BOTH %s
18+
// RUN: c-index-test core -print-unit %t/idx2 | %FileCheck --check-prefixes=IGNORESYSTEM,BOTH %s
19+
20+
// We should always get a dependency on the system framework in the unit for this file's module.
21+
//
22+
// BOTH: DEPEND START
23+
// BOTH: Unit | system | MySystemFramework |
24+
// BOTH: DEPEND END
25+
26+
// We should get a unit for the system framework if not ignoring them.
27+
//
28+
// ALLOWSYSTEM: provider: clang
29+
// ALLOWSYSTEM-NEXT: is-system: 1
30+
// ALLOWSYSTEM-NEXT: is-module: 1
31+
// ALLOWSYSTEM-NEXT: module-name: MySystemFramework
32+
33+
// But shouldn't if we are.
34+
//
35+
// IGNORESYSTEM-NOT: module-name: MySystemFramework

0 commit comments

Comments
 (0)