28
28
#include " swift/Frontend/CompileJobCacheResult.h"
29
29
#include " swift/Frontend/DiagnosticHelper.h"
30
30
#include " swift/Frontend/Frontend.h"
31
+ #include " swift/Frontend/MakeStyleDependencies.h"
31
32
#include " swift/Frontend/PrintingDiagnosticConsumer.h"
32
33
#include " swift/Option/Options.h"
33
34
#include " clang/CAS/CASOptions.h"
34
35
#include " clang/Frontend/CompileJobCacheResult.h"
36
+ #include " clang/Frontend/FrontendOptions.h"
35
37
#include " llvm/ADT/ArrayRef.h"
36
38
#include " llvm/ADT/IntrusiveRefCntPtr.h"
37
39
#include " llvm/ADT/SmallVector.h"
@@ -932,17 +934,20 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
932
934
Outputs.try_emplace (ID, File);
933
935
});
934
936
Outputs.try_emplace (file_types::TY_CachedDiagnostics, " <cached-diagnostics>" );
937
+ Outputs.try_emplace (file_types::ID::TY_SymbolGraphFile, " <symbol-graph>" );
935
938
936
939
// Load all the output buffer.
937
940
bool Remarks = Instance.Invocation .getCASOptions ().EnableCachingRemarks ;
938
941
struct OutputEntry {
939
942
std::string Path;
940
943
llvm::cas::ObjectProxy Proxy;
944
+ file_types::ID Kind;
941
945
};
942
946
SmallVector<OutputEntry> OutputProxies;
943
947
std::optional<llvm::cas::ObjectProxy> DiagnosticsOutput;
944
948
bool UseCASBackend = Invocation.getIRGenOptions ().UseCASBackend ;
945
- std::string ObjFile;
949
+ const FrontendOptions &FrontendOpts =
950
+ Inst.getInvocation ().getFrontendOptions ();
946
951
947
952
swift::cas::CachedResultLoader Loader (CAS, Comp.Output );
948
953
if (auto Err = Loader.replay (
@@ -956,15 +961,38 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
956
961
if (!Proxy)
957
962
return Proxy.takeError ();
958
963
959
- if (Kind == file_types::ID::TY_Object && UseCASBackend)
960
- ObjFile = OutputPath->second ;
961
-
962
964
if (Kind == file_types::ID::TY_CachedDiagnostics) {
963
965
assert (!DiagnosticsOutput && " more than 1 diagnostics found" );
964
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;
965
993
} else
966
994
OutputProxies.emplace_back (
967
- OutputEntry{OutputPath->second , std::move (*Proxy)});
995
+ OutputEntry{OutputPath->second , std::move (*Proxy), Kind });
968
996
return Error::success ();
969
997
}))
970
998
return Err;
@@ -1006,11 +1034,17 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
1006
1034
auto File = Backend.createFile (Output.Path );
1007
1035
if (!File)
1008
1036
return File.takeError ();
1009
- if (UseCASBackend && Output.Path == ObjFile ) {
1037
+ if (UseCASBackend && Output.Kind == file_types::ID::TY_Object ) {
1010
1038
auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
1011
1039
if (auto E = Schema->serializeObjectFile (Output.Proxy , *File))
1012
1040
Inst.getDiags ().diagnose (SourceLoc (), diag::error_mccas,
1013
1041
toString (std::move (E)));
1042
+ } else if (Output.Kind == file_types::ID::TY_Dependencies) {
1043
+ if (emitMakeDependenciesFromSerializedBuffer (Output.Proxy .getData (),
1044
+ *File, FrontendOpts, Input,
1045
+ Inst.getDiags ()))
1046
+ Inst.getDiags ().diagnose (SourceLoc (), diag::cache_replay_failed,
1047
+ " failed to emit dependency file" );
1014
1048
} else
1015
1049
*File << Output.Proxy .getData ();
1016
1050
if (auto E = File->keep ())
0 commit comments