Skip to content

Commit 1a60dae

Browse files
authored
Merge pull request #70335 from artemcm/DepScanSkipSwiftDependencyClangSearchPaths
[Explicit Moduele Builds] Look through forwarding modules for `canImport` version check.
2 parents e052833 + 22d39e9 commit 1a60dae

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,21 @@ bool ExplicitSwiftModuleLoader::canImportModule(
22442244
it->second.modulePath);
22452245
return false;
22462246
}
2247+
2248+
// If it's a forwarding module, load the YAML file from disk and get the path
2249+
// to the actual module for the version check.
2250+
if (!serialization::isSerializedAST((*moduleBuf)->getBuffer())) {
2251+
if (auto forwardingModule = ForwardingModule::load(**moduleBuf)) {
2252+
moduleBuf = fs.getBufferForFile(forwardingModule->underlyingModulePath);
2253+
if (!moduleBuf) {
2254+
Ctx.Diags.diagnose(SourceLoc(),
2255+
diag::error_opening_explicit_module_file,
2256+
forwardingModule->underlyingModulePath);
2257+
return false;
2258+
}
2259+
}
2260+
}
2261+
22472262
auto metaData = serialization::validateSerializedAST(
22482263
(*moduleBuf)->getBuffer(), Ctx.SILOpts.EnableOSSAModules,
22492264
Ctx.LangOpts.SDKName);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: mkdir -p %t/clang-module-cache
3+
// RUN: mkdir -p %t/inputs
4+
// RUN: mkdir -p %t/barinputs
5+
// RUN: echo "public func foo() {}" >> %t/foo.swift
6+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/inputs/Foo.swiftmodule -emit-module-doc-path %t/inputs/Foo.swiftdoc -emit-module-source-info -emit-module-source-info-path %t/inputs/Foo.swiftsourceinfo -module-cache-path %t.module-cache %t/foo.swift -module-name Foo -user-module-version 9001
7+
// RUN: echo "public func bar() {}" >> %t/bar.swift
8+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/barinputs/Bar.swiftmodule -emit-module-doc-path %t/barinputs/Bar.swiftdoc -emit-module-source-info -emit-module-source-info-path %t/barinputs/Bar.swiftsourceinfo -module-cache-path %t.module-cache %t/bar.swift -module-name Bar
9+
10+
// RUN: echo "---" >> %t/inputs/ForwardingFoo.swiftmodule
11+
// RUN: echo "path: '%/t/inputs/Foo.swiftmodule'" >> %t/inputs/ForwardingFoo.swiftmodule
12+
// RUN: echo "dependencies: []" >> %t/inputs/ForwardingFoo.swiftmodule
13+
// RUN: echo "version: 1 " >> %t/inputs/ForwardingFoo.swiftmodule
14+
// RUN: echo "..." >> %t/inputs/ForwardingFoo.swiftmodule
15+
16+
// RUN: echo "[{" > %/t/inputs/map.json
17+
// RUN: echo "\"moduleName\": \"Foo\"," >> %/t/inputs/map.json
18+
// RUN: echo "\"modulePath\": \"%/t/inputs/ForwardingFoo.swiftmodule\"," >> %/t/inputs/map.json
19+
// RUN: echo "\"docPath\": \"%/t/inputs/Foo.swiftdoc\"," >> %/t/inputs/map.json
20+
// RUN: echo "\"sourceInfoPath\": \"%/t/inputs/Foo.swiftsourceinfo\"," >> %/t/inputs/map.json
21+
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
22+
// RUN: echo "}]" >> %/t/inputs/map.json
23+
24+
// RUN: not %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -disable-implicit-swift-modules
25+
// RUN: %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -I %t/barinputs -Rmodule-loading 2>&1 | %FileCheck -check-prefix=POSITIVE-CHECK %s
26+
27+
#if canImport(Foo, _version: 9000)
28+
import Bar
29+
#endif
30+
31+
// 'Bar' can only be imported if the explicitly-loaded 'Foo' is known to be over 9000
32+
// POSITIVE-CHECK: remark: loaded module 'Bar'
33+
34+
// Re-build Foo with a lower version and ensure we do not import `Bar`
35+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/inputs/Foo.swiftmodule -emit-module-doc-path %t/inputs/Foo.swiftdoc -emit-module-source-info -emit-module-source-info-path %t/inputs/Foo.swiftsourceinfo -module-cache-path %t.module-cache %t/foo.swift -module-name Foo -user-module-version 7000
36+
// RUN: %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -I %t/barinputs -Rmodule-loading 2>&1 | %FileCheck -check-prefix=NEGATIVE-CHECK %s
37+
38+
// 'Bar' can only be imported if the explicitly-loaded 'Foo' is known to be over 9000
39+
// NEGATIVE-CHECK-NOT: remark: loaded module 'Bar'

0 commit comments

Comments
 (0)