diff --git a/lib/Index/IndexRecord.cpp b/lib/Index/IndexRecord.cpp index 8cc4d3997b8a0..d441ade35075f 100644 --- a/lib/Index/IndexRecord.cpp +++ b/lib/Index/IndexRecord.cpp @@ -416,14 +416,16 @@ static void addModuleDependencies(ArrayRef imports, StringRef moduleName = mod->getNameStr(); bool withoutUnitName = true; if (FU->getKind() == FileUnitKind::ClangModule) { - withoutUnitName = false; auto clangModUnit = cast(LFU); - if (auto clangMod = clangModUnit->getUnderlyingClangModule()) { - moduleName = clangMod->getTopLevelModuleName(); - // FIXME: clang's -Rremarks do not seem to go through Swift's - // diagnostic emitter. - clang::index::emitIndexDataForModuleFile(clangMod, - clangCI, unitWriter); + if (!clangModUnit->isSystemModule() || indexSystemModules) { + withoutUnitName = false; + if (auto clangMod = clangModUnit->getUnderlyingClangModule()) { + moduleName = clangMod->getTopLevelModuleName(); + // FIXME: clang's -Rremarks do not seem to go through Swift's + // diagnostic emitter. + clang::index::emitIndexDataForModuleFile(clangMod, + clangCI, unitWriter); + } } } else { // Serialized AST file. diff --git a/test/Index/Store/ignore-system-clang-modules.swift b/test/Index/Store/ignore-system-clang-modules.swift new file mode 100644 index 0000000000000..7147488165fdf --- /dev/null +++ b/test/Index/Store/ignore-system-clang-modules.swift @@ -0,0 +1,35 @@ +// RUN: %empty-directory(%t) + +// Make a basic clang framework to import +// +// RUN: %empty-directory(%t/MySystemFramework.framework/Headers) +// RUN: %empty-directory(%t/MySystemFramework.framework/Modules) +// RUN: echo 'void someSystemFunc(int arg);' > %t/MySystemFramework.framework/Headers/MySystemFramework.h +// RUN: echo 'framework module MySystemFramework { umbrella header "MySystemFramework.h" export * }' > %t/MySystemFramework.framework/Modules/module.modulemap + +import MySystemFramework +someSystemFunc(2) + +// Index this file with and without ignoring system frameworks +// +// RUN: %target-swiftc_driver -index-store-path %t/idx1 -o %t/file.o -Fsystem %t -typecheck %s +// RUN: %target-swiftc_driver -index-store-path %t/idx2 -o %t/file.o -index-ignore-system-modules -Fsystem %t -typecheck %s +// RUN: c-index-test core -print-unit %t/idx1 | %FileCheck --check-prefixes=ALLOWSYSTEM,BOTH %s +// RUN: c-index-test core -print-unit %t/idx2 | %FileCheck --check-prefixes=IGNORESYSTEM,BOTH %s + +// We should always get a dependency on the system framework in the unit for this file's module. +// +// BOTH: DEPEND START +// BOTH: Unit | system | MySystemFramework | +// BOTH: DEPEND END + +// We should get a unit for the system framework if not ignoring them. +// +// ALLOWSYSTEM: provider: clang +// ALLOWSYSTEM-NEXT: is-system: 1 +// ALLOWSYSTEM-NEXT: is-module: 1 +// ALLOWSYSTEM-NEXT: module-name: MySystemFramework + +// But shouldn't if we are. +// +// IGNORESYSTEM-NOT: module-name: MySystemFramework