Skip to content

[Index] Apply -index-ignore-system-modules to system clang modules #32024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/Index/IndexRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,16 @@ static void addModuleDependencies(ArrayRef<ModuleDecl::ImportedModule> imports,
StringRef moduleName = mod->getNameStr();
bool withoutUnitName = true;
if (FU->getKind() == FileUnitKind::ClangModule) {
withoutUnitName = false;
auto clangModUnit = cast<ClangModuleUnit>(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.
Expand Down
35 changes: 35 additions & 0 deletions test/Index/Store/ignore-system-clang-modules.swift
Original file line number Diff line number Diff line change
@@ -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