Skip to content

Commit 471aea8

Browse files
[ExplicitModuleBuild] Support -vfsoverlay swift option
Support `-vfsoverlay` swift option for explicit module build (including caching build). Previously, if the interface file is discovered from a location that is remapped by overlay, module cannot be built correctly. Make sure the overlay options are passed down to all interface compilaiton command. For caching build, need to make sure the overlay itself is part of the CAS file system so the downstream compilation can discover that. rdar://123655183
1 parent 91dc682 commit 471aea8

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

lib/AST/ModuleDependencies.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ void SwiftDependencyTracker::addCommonSearchPathDeps(
477477
FS->status(LayoutFile);
478478
}
479479
}
480+
481+
// Add VFSOverlay file.
482+
for (auto &Overlay: Opts.VFSOverlayFiles)
483+
FS->status(Overlay);
480484
}
481485

482486
void SwiftDependencyTracker::startTracking() {

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
199199
// Swift frontend option for input file path (Foo.modulemap).
200200
swiftArgs.push_back(remapPath(clangModuleDep.ClangModuleMapFile));
201201

202-
// Handle VFSOverlay.
203-
if (!ctx.SearchPathOpts.VFSOverlayFiles.empty()) {
202+
// Handle VFSOverlay. If include tree is used, there is no need for overlay.
203+
if (!ctx.ClangImporterOpts.UseClangIncludeTree) {
204204
for (auto &overlay : ctx.SearchPathOpts.VFSOverlayFiles) {
205205
swiftArgs.push_back("-vfsoverlay");
206206
swiftArgs.push_back(remapPath(overlay));

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,13 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
18791879
genericSubInvocation.getSearchPathOptions().ExplicitSwiftModuleMap =
18801880
explicitSwiftModuleMap.str();
18811881

1882+
// Pass down VFSOverlay flags (do not need to inherit the options because
1883+
// FileSystem is shared).
1884+
for (auto &Overlay : searchPathOpts.VFSOverlayFiles) {
1885+
GenericArgs.push_back("-vfsoverlay");
1886+
GenericArgs.push_back(Overlay);
1887+
}
1888+
18821889
// Load plugin libraries for macro expression as default arguments
18831890
genericSubInvocation.getSearchPathOptions().PluginSearchOpts =
18841891
searchPathOpts.PluginSearchOpts;

test/CAS/vfsoverlay.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
// RUN: sed -e "s@VFS_DIR@%{/t:regex_replacement}/vfs@g" -e "s@EXTERNAL_DIR@%{/t:regex_replacement}/hidden@g" %t/base.yaml > %t/overlay.yaml
4+
5+
// RUN: %target-swift-frontend -emit-module -module-name B -o %t/B.swiftmodule -swift-version 5 \
6+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
7+
// RUN: -emit-module-interface-path %t/hidden/B.swiftinterface -enable-library-evolution %t/hidden/B.swift
8+
9+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O \
10+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
11+
// RUN: %t/vfs/test.swift -o %t/deps.json -swift-version 5 -cache-compile-job -cas-path %t/cas \
12+
// RUN: -vfsoverlay %t/overlay.yaml -Xcc -ivfsoverlay -Xcc %t/overlay.yaml -I %t/vfs
13+
14+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:A > %t/A.cmd
15+
// RUN: %swift_frontend_plain @%t/A.cmd
16+
17+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json B > %t/B.cmd
18+
// RUN: %swift_frontend_plain @%t/B.cmd
19+
20+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
21+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
22+
23+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
24+
// RUN: %target-swift-frontend \
25+
// RUN: -typecheck -cache-compile-job -cas-path %t/cas -vfsoverlay %t/overlay.yaml \
26+
// RUN: -swift-version 5 -disable-implicit-swift-modules \
27+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
28+
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
29+
// RUN: %t/vfs/test.swift @%t/MyApp.cmd
30+
31+
//--- hidden/test.swift
32+
import A
33+
import B
34+
35+
//--- hidden/module.modulemap
36+
module A {
37+
header "A.h"
38+
export *
39+
}
40+
41+
//--- hidden/A.h
42+
void a(void);
43+
44+
//--- hidden/B.swift
45+
public func b() {}
46+
47+
//--- base.yaml
48+
{
49+
version: 0,
50+
roots: [
51+
{
52+
type: "directory-remap",
53+
name: "VFS_DIR",
54+
external-contents: "EXTERNAL_DIR"
55+
}
56+
]
57+
}

0 commit comments

Comments
 (0)