Skip to content

Commit 58d7137

Browse files
[Caching] Fix cache replay logics for makefile dependency file
Make sure the driver replay logics from C API can replay makefile dependency file correctly. rdar://141567785
1 parent 4f7ffcc commit 58d7137

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

lib/Frontend/CachingUtils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,11 @@ bool replayCachedCompilerOutputs(
325325
}
326326
} else if (Output.Kind == file_types::ID::TY_Dependencies) {
327327
if (emitMakeDependenciesFromSerializedBuffer(
328-
Output.Proxy.getData(), *File, Opts, Output.Input, Diag))
328+
Output.Proxy.getData(), *File, Opts, Output.Input, Diag)) {
329+
Diag.diagnose(SourceLoc(), diag::cache_replay_failed,
330+
"failed to emit dependency file");
329331
return false;
332+
}
330333
} else
331334
*File << Output.Proxy.getData();
332335

lib/Tooling/libSwiftScan/SwiftCaching.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "swift/Frontend/CompileJobCacheResult.h"
2929
#include "swift/Frontend/DiagnosticHelper.h"
3030
#include "swift/Frontend/Frontend.h"
31+
#include "swift/Frontend/MakeStyleDependencies.h"
3132
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
3233
#include "swift/Option/Options.h"
3334
#include "clang/CAS/CASOptions.h"
@@ -938,6 +939,7 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
938939
struct OutputEntry {
939940
std::string Path;
940941
llvm::cas::ObjectProxy Proxy;
942+
file_types::ID Kind;
941943
};
942944
SmallVector<OutputEntry> OutputProxies;
943945
std::optional<llvm::cas::ObjectProxy> DiagnosticsOutput;
@@ -964,7 +966,7 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
964966
DiagnosticsOutput = std::move(*Proxy);
965967
} else
966968
OutputProxies.emplace_back(
967-
OutputEntry{OutputPath->second, std::move(*Proxy)});
969+
OutputEntry{OutputPath->second, std::move(*Proxy), Kind});
968970
return Error::success();
969971
}))
970972
return Err;
@@ -1011,6 +1013,13 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
10111013
if (auto E = Schema->serializeObjectFile(Output.Proxy, *File))
10121014
Inst.getDiags().diagnose(SourceLoc(), diag::error_mccas,
10131015
toString(std::move(E)));
1016+
} else if (Output.Kind == file_types::ID::TY_Dependencies) {
1017+
if (emitMakeDependenciesFromSerializedBuffer(
1018+
Output.Proxy.getData(), *File,
1019+
Inst.getInvocation().getFrontendOptions(), Input,
1020+
Inst.getDiags()))
1021+
Inst.getDiags().diagnose(SourceLoc(), diag::cache_replay_failed,
1022+
"failed to emit dependency file");
10141023
} else
10151024
*File << Output.Proxy.getData();
10161025
if (auto E = File->keep())

test/CAS/dependency_file.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@
5656
// RUN: %FileCheck %s --check-prefix=DEPS3 --input-file=%t/main-3.d -DTMP=%t
5757
// DEPS3: [[TMP]]{{/|\\}}main-3.o : [[TMP]]{{/|\\}}main.swift
5858

59+
/// Test replay from driver interface
60+
// RUN: %swift-scan-test -action compute_cache_key_from_index -cas-path %t/cas -input 0 -- \
61+
// RUN: %target-swift-frontend \
62+
// RUN: -c -o %t/main-4.o -cache-compile-job -cas-path %t/cas -Rcache-compile-job \
63+
// RUN: -swift-version 5 -disable-implicit-swift-modules \
64+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
65+
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
66+
// RUN: -cache-replay-prefix-map /^src=%swift_src_root -cache-replay-prefix-map /^tmp=%t -cache-replay-prefix-map /^sdk=%t/sdk \
67+
// RUN: /^tmp/main.swift @%t/MyApp-1.cmd -emit-dependencies -emit-dependencies-path %t/main-4.d > %t/key.casid
68+
69+
// RUN: %swift-scan-test -action replay_result -cas-path %t/cas -id @%t/key.casid -- \
70+
// RUN: %target-swift-frontend \
71+
// RUN: -c -o %t/main-4.o -cache-compile-job -cas-path %t/cas -Rcache-compile-job \
72+
// RUN: -swift-version 5 -disable-implicit-swift-modules \
73+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
74+
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
75+
// RUN: -cache-replay-prefix-map /^src=%swift_src_root -cache-replay-prefix-map /^tmp=%t -cache-replay-prefix-map /^sdk=%t/sdk \
76+
// RUN: /^tmp/main.swift @%t/MyApp-1.cmd -emit-dependencies -emit-dependencies-path %t/main-4.d 2>&1 | %FileCheck %s --check-prefix=CACHE-HIT4
77+
// CACHE-HIT4: remark: replay output file '{{.*}}{{/|\\}}main-4.d': key 'llvmcas://{{.*}}'
78+
// RUN: %FileCheck %s --check-prefix=DEPS4 --input-file=%t/main-4.d -DTMP=%t
79+
// DEPS4: [[TMP]]{{/|\\}}main-4.o : [[TMP]]{{/|\\}}main.swift
80+
81+
5982
//--- main.swift
6083
import A
6184

0 commit comments

Comments
 (0)