Skip to content

Commit 275a679

Browse files
authored
Merge pull request #80007 from hjyamauchi/androidoverlay
Propagate sysroot to module loader subinvocation
2 parents 673da6b + 1a3a6e1 commit 275a679

File tree

7 files changed

+29
-9
lines changed

7 files changed

+29
-9
lines changed

include/swift/AST/ModuleLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ struct InterfaceSubContextDelegate {
209209
virtual std::error_code runInSubContext(StringRef moduleName,
210210
StringRef interfacePath,
211211
StringRef sdkPath,
212+
std::optional<StringRef> sysroot,
212213
StringRef outputPath,
213214
SourceLoc diagLoc,
214215
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
@@ -217,6 +218,7 @@ struct InterfaceSubContextDelegate {
217218
virtual std::error_code runInSubCompilerInstance(StringRef moduleName,
218219
StringRef interfacePath,
219220
StringRef sdkPath,
221+
std::optional<StringRef> sysroot,
220222
StringRef outputPath,
221223
SourceLoc diagLoc,
222224
bool silenceErrors,

include/swift/Frontend/Frontend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ class CompilerInvocation {
222222
SearchPathOpts.VFSOverlayFiles = Overlays;
223223
}
224224

225+
void setSysRoot(StringRef SysRoot) {
226+
SearchPathOpts.setSysRoot(SysRoot);
227+
}
228+
225229
void setExtraClangArgs(const std::vector<std::string> &Args) {
226230
ClangImporterOpts.ExtraArgs = Args;
227231
}

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ struct InterfaceSubContextDelegateImpl : InterfaceSubContextDelegate {
712712
std::error_code runInSubContext(StringRef moduleName,
713713
StringRef interfacePath,
714714
StringRef sdkPath,
715+
std::optional<StringRef> sysroot,
715716
StringRef outputPath,
716717
SourceLoc diagLoc,
717718
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
@@ -720,6 +721,7 @@ struct InterfaceSubContextDelegateImpl : InterfaceSubContextDelegate {
720721
std::error_code runInSubCompilerInstance(StringRef moduleName,
721722
StringRef interfacePath,
722723
StringRef sdkPath,
724+
std::optional<StringRef> sysroot,
723725
StringRef outputPath,
724726
SourceLoc diagLoc,
725727
bool silenceErrors,

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ bool ImplicitModuleInterfaceBuilder::buildSwiftModuleInternal(
356356
}
357357

358358
SubError = (bool)subASTDelegate.runInSubCompilerInstance(
359-
moduleName, interfacePath, sdkPath, OutPath, diagnosticLoc,
359+
moduleName, interfacePath, sdkPath, sysroot, OutPath, diagnosticLoc,
360360
silenceInterfaceDiagnostics,
361361
[&](SubCompilerInstanceInfo &info) {
362362
auto EBuilder = ExplicitModuleInterfaceBuilder(

lib/Frontend/ModuleInterfaceBuilder.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ImplicitModuleInterfaceBuilder {
4242
InterfaceSubContextDelegate &subASTDelegate;
4343
const StringRef interfacePath;
4444
const StringRef sdkPath;
45+
const std::optional<StringRef> sysroot;
4546
const StringRef moduleName;
4647
const StringRef moduleCachePath;
4748
const StringRef prebuiltCachePath;
@@ -87,15 +88,17 @@ class ImplicitModuleInterfaceBuilder {
8788
SourceManager &sourceMgr, DiagnosticEngine *diags,
8889
InterfaceSubContextDelegate &subASTDelegate,
8990
StringRef interfacePath, StringRef sdkPath,
90-
StringRef moduleName, StringRef moduleCachePath,
91-
StringRef backupInterfaceDir, StringRef prebuiltCachePath,
92-
StringRef ABIDescriptorPath, bool disableInterfaceFileLock = false,
91+
std::optional<StringRef> sysroot, StringRef moduleName,
92+
StringRef moduleCachePath, StringRef backupInterfaceDir,
93+
StringRef prebuiltCachePath, StringRef ABIDescriptorPath,
94+
bool disableInterfaceFileLock = false,
9395
bool silenceInterfaceDiagnostics = false,
9496
SourceLoc diagnosticLoc = SourceLoc(),
9597
DependencyTracker *tracker = nullptr)
9698
: sourceMgr(sourceMgr), diags(diags), subASTDelegate(subASTDelegate),
97-
interfacePath(interfacePath), sdkPath(sdkPath), moduleName(moduleName),
98-
moduleCachePath(moduleCachePath), prebuiltCachePath(prebuiltCachePath),
99+
interfacePath(interfacePath), sdkPath(sdkPath), sysroot(sysroot),
100+
moduleName(moduleName), moduleCachePath(moduleCachePath),
101+
prebuiltCachePath(prebuiltCachePath),
99102
backupInterfaceDir(backupInterfaceDir),
100103
ABIDescriptorPath(ABIDescriptorPath),
101104
disableInterfaceFileLock(disableInterfaceFileLock),

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ class ModuleInterfaceLoaderImpl {
12151215
ctx.SourceMgr, diagsToUse,
12161216
astDelegate, interfacePath,
12171217
ctx.SearchPathOpts.getSDKPath(),
1218+
ctx.SearchPathOpts.getSysRoot(),
12181219
realName.str(), cacheDir,
12191220
prebuiltCacheDir, backupInterfaceDir, StringRef(),
12201221
Opts.disableInterfaceLock,
@@ -1250,6 +1251,7 @@ class ModuleInterfaceLoaderImpl {
12501251
ImplicitModuleInterfaceBuilder fallbackBuilder(
12511252
ctx.SourceMgr, &ctx.Diags, astDelegate, backupPath,
12521253
ctx.SearchPathOpts.getSDKPath(),
1254+
ctx.SearchPathOpts.getSysRoot(),
12531255
moduleName, cacheDir,
12541256
prebuiltCacheDir, backupInterfaceDir, StringRef(),
12551257
Opts.disableInterfaceLock,
@@ -1475,6 +1477,7 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
14751477
RequireOSSAModules);
14761478
ImplicitModuleInterfaceBuilder builder(SourceMgr, &Diags, astDelegate, InPath,
14771479
SearchPathOpts.getSDKPath(),
1480+
SearchPathOpts.getSysRoot(),
14781481
ModuleName, CacheDir, PrebuiltCacheDir,
14791482
BackupInterfaceDir, ABIOutputPath,
14801483
LoaderOpts.disableInterfaceLock,
@@ -1495,6 +1498,7 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
14951498
assert(!backInPath.empty());
14961499
ImplicitModuleInterfaceBuilder backupBuilder(SourceMgr, &Diags, astDelegate, backInPath,
14971500
SearchPathOpts.getSDKPath(),
1501+
SearchPathOpts.getSysRoot(),
14981502
ModuleName, CacheDir, PrebuiltCacheDir,
14991503
BackupInterfaceDir, ABIOutputPath,
15001504
LoaderOpts.disableInterfaceLock,
@@ -2058,12 +2062,13 @@ std::error_code
20582062
InterfaceSubContextDelegateImpl::runInSubContext(StringRef moduleName,
20592063
StringRef interfacePath,
20602064
StringRef sdkPath,
2065+
std::optional<StringRef> sysroot,
20612066
StringRef outputPath,
20622067
SourceLoc diagLoc,
20632068
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*, ArrayRef<StringRef>,
20642069
StringRef, StringRef)> action) {
2065-
return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, outputPath,
2066-
diagLoc, /*silenceErrors=*/false,
2070+
return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, sysroot,
2071+
outputPath, diagLoc, /*silenceErrors=*/false,
20672072
[&](SubCompilerInstanceInfo &info){
20682073
std::string UserModuleVer = info.Instance->getInvocation().getFrontendOptions()
20692074
.UserModuleVersion.getAsString();
@@ -2079,6 +2084,7 @@ std::error_code
20792084
InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
20802085
StringRef interfacePath,
20812086
StringRef sdkPath,
2087+
std::optional<StringRef> sysroot,
20822088
StringRef outputPath,
20832089
SourceLoc diagLoc,
20842090
bool silenceErrors,
@@ -2110,6 +2116,9 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
21102116
subInvocation.setModuleName(moduleName);
21112117
BuildArgs.push_back("-module-name");
21122118
BuildArgs.push_back(moduleName);
2119+
if (sysroot) {
2120+
subInvocation.setSysRoot(sysroot.value());
2121+
}
21132122

21142123
// FIXME: Hack for CoreGraphics.swiftmodule, which cannot be rebuilt because
21152124
// of a CF_OPTIONS bug (rdar://142762174).

lib/Serialization/ScanningLoaders.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
156156
std::optional<ModuleDependencyInfo> Result;
157157
std::error_code code = astDelegate.runInSubContext(
158158
realModuleName.str(), moduleInterfacePath.str(), sdkPath,
159-
StringRef(), SourceLoc(),
159+
Ctx.SearchPathOpts.getSysRoot(), StringRef(), SourceLoc(),
160160
[&](ASTContext &Ctx, ModuleDecl *mainMod, ArrayRef<StringRef> BaseArgs,
161161
StringRef Hash, StringRef UserModVer) {
162162
assert(mainMod);

0 commit comments

Comments
 (0)