Skip to content

Commit f683373

Browse files
author
Nathan Hawes
committed
[ParseableInterface] Respect -track-system-dependencies with -build-module-from-parseable-interface
Updates the subinvocation that builds the parseable interface to respect the -track-system-dependencies flag of the top-level invocation if present, by including system dependencies in the produced .swiftmodule.
1 parent 7f33444 commit f683373

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

include/swift/Frontend/ParseableInterfaceModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class ParseableInterfaceModuleLoader : public SerializedModuleLoaderBase {
156156
static bool buildSwiftModuleFromSwiftInterface(
157157
ASTContext &Ctx, StringRef CacheDir, StringRef PrebuiltCacheDir,
158158
StringRef ModuleName, StringRef InPath, StringRef OutPath,
159-
bool SerializeDependencyHashes);
159+
bool SerializeDependencyHashes, bool TrackSystemDependencies);
160160
};
161161

162162
/// Extract the specified-or-defaulted -module-cache-path that winds up in

lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class swift::ParseableInterfaceBuilder {
261261
const StringRef moduleCachePath;
262262
const StringRef prebuiltCachePath;
263263
const bool serializeDependencyHashes;
264+
const bool trackSystemDependencies;
264265
const SourceLoc diagnosticLoc;
265266
DependencyTracker *const dependencyTracker;
266267
CompilerInvocation subInvocation;
@@ -295,6 +296,7 @@ class swift::ParseableInterfaceBuilder {
295296
subInvocation.setClangModuleCachePath(moduleCachePath);
296297
subInvocation.getFrontendOptions().PrebuiltModuleCachePath =
297298
prebuiltCachePath;
299+
subInvocation.getFrontendOptions().TrackSystemDeps = trackSystemDependencies;
298300

299301
// Respect the detailed-record preprocessor setting of the parent context.
300302
// This, and the "raw" clang module format it implicitly enables, are
@@ -449,12 +451,14 @@ class swift::ParseableInterfaceBuilder {
449451
StringRef moduleCachePath,
450452
StringRef prebuiltCachePath,
451453
bool serializeDependencyHashes = false,
454+
bool trackSystemDependencies = false,
452455
SourceLoc diagnosticLoc = SourceLoc(),
453456
DependencyTracker *tracker = nullptr)
454457
: ctx(ctx), fs(*ctx.SourceMgr.getFileSystem()), diags(ctx.Diags),
455458
interfacePath(interfacePath), moduleName(moduleName),
456459
moduleCachePath(moduleCachePath), prebuiltCachePath(prebuiltCachePath),
457460
serializeDependencyHashes(serializeDependencyHashes),
461+
trackSystemDependencies(trackSystemDependencies),
458462
diagnosticLoc(diagnosticLoc), dependencyTracker(tracker) {
459463
configureSubInvocation();
460464
}
@@ -532,7 +536,8 @@ class swift::ParseableInterfaceBuilder {
532536
ForwardingDiagnosticConsumer FDC(diags);
533537
SubInstance.addDiagnosticConsumer(&FDC);
534538

535-
SubInstance.createDependencyTracker(/*TrackSystemDeps=*/true);
539+
SubInstance.createDependencyTracker(FEOpts.TrackSystemDeps);
540+
536541
if (SubInstance.setup(subInvocation)) {
537542
SubError = true;
538543
return;
@@ -656,6 +661,10 @@ class ParseableInterfaceModuleLoaderImpl {
656661
// it.
657662
H = hash_combine(H, SubInvocation.getSDKPath());
658663

664+
// Whether or not we're tracking system dependencies affects the
665+
// invalidation behavior of this cache item.
666+
H = hash_combine(H, SubInvocation.getFrontendOptions().TrackSystemDeps);
667+
659668
return llvm::APInt(64, H).toString(36, /*Signed=*/false);
660669
}
661670

@@ -928,12 +937,21 @@ class ParseableInterfaceModuleLoaderImpl {
928937
/// loading strategy.
929938
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
930939
findOrBuildLoadableModule() {
940+
// Track system dependencies if the parent tracker is set to do so.
941+
// FIXME: This means -track-system-dependencies isn't honored when the
942+
// top-level invocation isn't tracking dependencies
943+
bool trackSystemDependencies = false;
944+
if (dependencyTracker) {
945+
auto ClangDependencyTracker = dependencyTracker->getClangCollector();
946+
trackSystemDependencies = ClangDependencyTracker->needSystemDependencies();
947+
}
931948

932949
// Set up a builder if we need to build the module. It'll also set up
933950
// the subinvocation we'll need to use to compute the cache paths.
934951
ParseableInterfaceBuilder builder(
935952
ctx, interfacePath, moduleName, cacheDir, prebuiltCacheDir,
936-
/*serializeDependencyHashes*/false, diagnosticLoc, dependencyTracker);
953+
/*serializeDependencyHashes*/false, trackSystemDependencies,
954+
diagnosticLoc, dependencyTracker);
937955
auto &subInvocation = builder.getSubInvocation();
938956

939957
// Compute the output path if we're loading or emitting a cached module.
@@ -1036,7 +1054,7 @@ std::error_code ParseableInterfaceModuleLoader::findModuleFilesInDirectory(
10361054
bool ParseableInterfaceModuleLoader::buildSwiftModuleFromSwiftInterface(
10371055
ASTContext &Ctx, StringRef CacheDir, StringRef PrebuiltCacheDir,
10381056
StringRef ModuleName, StringRef InPath, StringRef OutPath,
1039-
bool SerializeDependencyHashes) {
1057+
bool SerializeDependencyHashes, bool TrackSystemDependencies) {
10401058
ParseableInterfaceBuilder builder(Ctx, InPath, ModuleName,
10411059
CacheDir, PrebuiltCacheDir,
10421060
SerializeDependencyHashes);

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ static bool buildModuleFromParseableInterface(CompilerInvocation &Invocation,
587587
Instance.getASTContext(), Invocation.getClangModuleCachePath(),
588588
PrebuiltCachePath, Invocation.getModuleName(), InputPath,
589589
Invocation.getOutputFilename(),
590-
FEOpts.SerializeParseableModuleInterfaceDependencyHashes);
590+
FEOpts.SerializeParseableModuleInterfaceDependencyHashes,
591+
FEOpts.TrackSystemDeps);
591592
}
592593

593594
static bool compileLLVMIR(CompilerInvocation &Invocation,

0 commit comments

Comments
 (0)