From 4e227f8a76deb1d189a0e62694124a11dbbe1792 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Sat, 23 May 2020 09:50:25 -0700 Subject: [PATCH 1/3] [Index] Apply -index-ignore-system-modules to clang modules --- lib/Index/IndexRecord.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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. From 8eb5cbe6a3f3445c1c0cb28b931c3bbd0189b572 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Wed, 3 Jun 2020 11:04:28 -0700 Subject: [PATCH 2/3] add test by @nathawes --- .../Store/driver-ignore-system-modules.swift | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/Index/Store/driver-ignore-system-modules.swift diff --git a/test/Index/Store/driver-ignore-system-modules.swift b/test/Index/Store/driver-ignore-system-modules.swift new file mode 100644 index 0000000000000..7147488165fdf --- /dev/null +++ b/test/Index/Store/driver-ignore-system-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 From 258ceda02fade5ba21cfad26b552803698f44cb5 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Wed, 3 Jun 2020 11:13:45 -0700 Subject: [PATCH 3/3] rename test --- ...ore-system-modules.swift => ignore-system-clang-modules.swift} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/Index/Store/{driver-ignore-system-modules.swift => ignore-system-clang-modules.swift} (100%) diff --git a/test/Index/Store/driver-ignore-system-modules.swift b/test/Index/Store/ignore-system-clang-modules.swift similarity index 100% rename from test/Index/Store/driver-ignore-system-modules.swift rename to test/Index/Store/ignore-system-clang-modules.swift