Skip to content
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
3 changes: 3 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ class FrontendOptions {
/// for testing purposes only.
bool DisableBuildingInterface = false;

/// Is this frontend configuration of an interface dependency scan sub-invocation
bool DependencyScanningSubInvocation = false;

/// When performing a dependency scanning action, only identify and output all imports
/// of the main Swift module's source files.
bool ImportPrescan = false;
Expand Down
7 changes: 6 additions & 1 deletion lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,9 +1169,14 @@ bool CompilerInstance::canImportCxxShim() const {
ImportPath::Module::Builder builder(
getASTContext().getIdentifier(CXX_SHIM_NAME));
auto modulePath = builder.get();
// Currently, Swift interfaces are not to expose their
// C++ dependencies. Which means that when scanning them we should not
// bring in such dependencies, including CxxShims.
return getASTContext().testImportModule(modulePath) &&
!Invocation.getFrontendOptions()
.InputsAndOutputs.hasModuleInterfaceOutputPath();
.InputsAndOutputs.hasModuleInterfaceOutputPath() &&
!Invocation.getFrontendOptions()
.DependencyScanningSubInvocation;
}

bool CompilerInstance::supportCaching() const {
Expand Down
2 changes: 2 additions & 0 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,8 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
// in the Swift compile commands, when different.
inheritedParentContextClangArgs =
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
genericSubInvocation.getFrontendOptions()
.DependencyScanningSubInvocation = true;
} else if (LoaderOpts.strictImplicitModuleContext) {
// If the compiler has been asked to be strict with ensuring downstream
// dependencies get the parent invocation's context, inherit the extra Clang
Expand Down
18 changes: 18 additions & 0 deletions test/ScanDependencies/test_no_indirect_cxx.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// REQUIRES: OS=macosx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this limited to macOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/deps)
// RUN: split-file %s %t
// RUN: mv %t/Foo.swiftinterface %t/deps/

// RUN: %target-swift-frontend -scan-dependencies -o %t/deps.json %t/a.swift -I %t/deps -verify

//--- Foo.swiftinterface
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name Foo -cxx-interoperability-mode=default
public struct S1 {}

//--- a.swift
import Foo

// RUN: cat %t/deps.json | %FileCheck %s
// CHECK-NOT: "CxxShim"