33
33
#include " swift/Option/Options.h"
34
34
#include " clang/CAS/CASOptions.h"
35
35
#include " clang/Frontend/CompileJobCacheResult.h"
36
+ #include " clang/Frontend/FrontendOptions.h"
36
37
#include " llvm/ADT/ArrayRef.h"
37
38
#include " llvm/ADT/IntrusiveRefCntPtr.h"
38
39
#include " llvm/ADT/SmallVector.h"
@@ -933,6 +934,7 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
933
934
Outputs.try_emplace (ID, File);
934
935
});
935
936
Outputs.try_emplace (file_types::TY_CachedDiagnostics, " <cached-diagnostics>" );
937
+ Outputs.try_emplace (file_types::ID::TY_SymbolGraphFile, " <symbol-graph>" );
936
938
937
939
// Load all the output buffer.
938
940
bool Remarks = Instance.Invocation .getCASOptions ().EnableCachingRemarks ;
@@ -944,6 +946,8 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
944
946
SmallVector<OutputEntry> OutputProxies;
945
947
std::optional<llvm::cas::ObjectProxy> DiagnosticsOutput;
946
948
bool UseCASBackend = Invocation.getIRGenOptions ().UseCASBackend ;
949
+ const FrontendOptions &FrontendOpts =
950
+ Inst.getInvocation ().getFrontendOptions ();
947
951
948
952
swift::cas::CachedResultLoader Loader (CAS, Comp.Output );
949
953
if (auto Err = Loader.replay (
@@ -960,6 +964,32 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
960
964
if (Kind == file_types::ID::TY_CachedDiagnostics) {
961
965
assert (!DiagnosticsOutput && " more than 1 diagnostics found" );
962
966
DiagnosticsOutput = std::move (*Proxy);
967
+ } else if (Kind == file_types::ID::TY_SymbolGraphFile &&
968
+ !FrontendOpts.SymbolGraphOutputDir .empty ()) {
969
+ auto Err = Proxy->forEachReference ([&](llvm::cas::ObjectRef Ref)
970
+ -> llvm::Error {
971
+ auto Proxy = CAS.getProxy (Ref);
972
+ if (!Proxy)
973
+ return Proxy.takeError ();
974
+ auto PathRef = Proxy->getReference (0 );
975
+ auto ContentRef = Proxy->getReference (1 );
976
+ auto Path = CAS.getProxy (PathRef);
977
+ auto Content = CAS.getProxy (ContentRef);
978
+ if (!Path)
979
+ return Path.takeError ();
980
+ if (!Content)
981
+ return Content.takeError ();
982
+
983
+ SmallString<128 > OutputPath (FrontendOpts.SymbolGraphOutputDir );
984
+ llvm::sys::path::append (OutputPath, Path->getData ());
985
+
986
+ OutputProxies.emplace_back (OutputEntry{
987
+ std::string (OutputPath), std::move (*Content), Kind});
988
+
989
+ return Error::success ();
990
+ });
991
+ if (Err)
992
+ return Err;
963
993
} else
964
994
OutputProxies.emplace_back (
965
995
OutputEntry{OutputPath->second , std::move (*Proxy), Kind});
@@ -1010,10 +1040,9 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
1010
1040
Inst.getDiags ().diagnose (SourceLoc (), diag::error_mccas,
1011
1041
toString (std::move (E)));
1012
1042
} else if (Output.Kind == file_types::ID::TY_Dependencies) {
1013
- if (emitMakeDependenciesFromSerializedBuffer (
1014
- Output.Proxy .getData (), *File,
1015
- Inst.getInvocation ().getFrontendOptions (), Input,
1016
- Inst.getDiags ()))
1043
+ if (emitMakeDependenciesFromSerializedBuffer (Output.Proxy .getData (),
1044
+ *File, FrontendOpts, Input,
1045
+ Inst.getDiags ()))
1017
1046
Inst.getDiags ().diagnose (SourceLoc (), diag::cache_replay_failed,
1018
1047
" failed to emit dependency file" );
1019
1048
} else
0 commit comments