Skip to content

Commit b460ea4

Browse files
[BridgingHeader] Implicit import bridging header from CAS module
The binary module built from a CAS build will have the embeded bridging header info with 0 modTime. Allow a regular build to import such a module with the same behavior as if the module is built from a regular build. rdar://126221616 (cherry picked from commit e654e37)
1 parent 77a090b commit b460ea4

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,8 +1703,13 @@ bool ClangImporter::importHeader(StringRef header, ModuleDecl *adapter,
17031703
StringRef cachedContents, SourceLoc diagLoc) {
17041704
clang::FileManager &fileManager = Impl.Instance->getFileManager();
17051705
auto headerFile = fileManager.getFile(header, /*OpenFile=*/true);
1706+
// Prefer importing the header directly if the header content matches by
1707+
// checking size and mod time. This allows correct import if some no-modular
1708+
// headers are already imported into clang importer. If mod time is zero, then
1709+
// the module should be built from CAS and there is no mod time to verify.
17061710
if (headerFile && (*headerFile)->getSize() == expectedSize &&
1707-
(*headerFile)->getModificationTime() == expectedModTime) {
1711+
(expectedModTime == 0 ||
1712+
(*headerFile)->getModificationTime() == expectedModTime)) {
17081713
return importBridgingHeader(header, adapter, diagLoc, false, true);
17091714
}
17101715

test/CAS/bridging-header.swift

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// REQUIRES: objc_interop
12
// RUN: %empty-directory(%t)
23
// RUN: split-file %s %t
34

@@ -64,13 +65,28 @@
6465
// RUN: %target-swift-frontend -cache-compile-job -module-name Test -O -cas-path %t/cas @%t/MyApp.cmd %t/test.swift \
6566
// RUN: -emit-module -o %t/Test.swiftmodule
6667

68+
/// Importing binary module with bridging header built from CAS from a regluar build.
69+
/// This should succeed even it is also importing a bridging header that shares same header dependencies (with proper header guard).
6770
// RUN: %target-swift-frontend -typecheck -module-name User -swift-version 5 \
6871
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
6972
// RUN: -Xcc -fmodule-map-file=%t/a.modulemap -Xcc -fmodule-map-file=%t/b.modulemap \
70-
// RUN: -I %t %t/user.swift
73+
// RUN: -I %t %t/user.swift -import-objc-header %t/Bridging2.h
74+
75+
/// Importing binary module with bridging header built from CAS from a cached build. This should work without additional bridging header deps.
76+
// RUN: %target-swift-frontend -scan-dependencies -module-name User -module-cache-path %t/clang-module-cache -O \
77+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
78+
// RUN: %t/user.swift -o %t/deps2.json -swift-version 5 -cache-compile-job -cas-path %t/cas \
79+
// RUN: -Xcc -fmodule-map-file=%t/a.modulemap -Xcc -fmodule-map-file=%t/b.modulemap -I %t
80+
81+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps2.json > %t/map2.json
82+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map2.json > %t/map2.casid
83+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps2.json User > %t/User.cmd
84+
// RUN: %target-swift-frontend -cache-compile-job -module-name User -O -cas-path %t/cas \
85+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -disable-implicit-swift-modules \
86+
// RUN: -explicit-swift-module-map-file @%t/map2.casid @%t/User.cmd %t/user.swift \
87+
// RUN: -emit-module -o %t/User.swiftmodule
7188

7289
//--- test.swift
73-
import B
7490
public func test() {
7591
b()
7692
}
@@ -84,14 +100,31 @@ func user() {
84100
test()
85101
}
86102

103+
extension A {
104+
public func testA() {}
105+
}
106+
107+
87108
//--- Bridging.h
88109
#include "Foo.h"
110+
#include "Foo2.h"
111+
112+
//--- Bridging2.h
113+
#include "Foo.h"
114+
#include "Foo2.h"
89115

90116
//--- Foo.h
91117
#import "a.h"
92118

119+
//--- Foo2.h
120+
#pragma once
121+
int Foo = 0;
122+
93123
//--- a.h
94124
#include "b.h"
125+
struct A {
126+
int a;
127+
};
95128

96129
//--- b.h
97130
void b(void);

0 commit comments

Comments
 (0)