@@ -782,6 +782,7 @@ Expected<std::optional<int>> ObjectStoreCachingOutputs::replayCachedResult(
782
782
DiagnosticsEngine &Diags = Clang.getDiagnostics ();
783
783
bool HasMissingOutput = false ;
784
784
std::optional<llvm::cas::ObjectProxy> SerialDiags;
785
+ llvm::vfs::OnDiskOutputBackend Backend;
785
786
786
787
auto processOutput = [&](clang::cas::CompileJobCacheResult::Output O,
787
788
std::optional<llvm::cas::ObjectProxy> Obj) -> Error {
@@ -815,47 +816,48 @@ Expected<std::optional<int>> ObjectStoreCachingOutputs::replayCachedResult(
815
816
816
817
bool IsOutputFile = O.Kind == OutputKind::MainOutput;
817
818
818
- std::optional<StringRef> Contents;
819
- SmallString<50 > ContentsStorage;
820
819
if (IsOutputFile && ComputedJobNeedsReplay) {
821
- llvm::raw_svector_ostream OS (ContentsStorage);
820
+ auto Output = Backend.createFile (Path);
821
+ if (!Output)
822
+ return Output.takeError ();
822
823
if (WriteOutputAsCASID)
823
- llvm::cas::writeCASIDBuffer (CAS.getID (O.Object ), OS );
824
+ llvm::cas::writeCASIDBuffer (CAS.getID (O.Object ), *Output );
824
825
else if (UseCASBackend) {
825
826
// Replay by write out object file.
826
827
// When the environmental variable is set, save the backend CASID for
827
828
// analysis later.
828
829
if (llvm::sys::Process::GetEnv (" CLANG_CAS_BACKEND_SAVE_CASID_FILE" )) {
829
830
std::string CASIDPath = Path + " .casid" ;
830
831
std::error_code EC;
831
- llvm::raw_fd_ostream IDOS (CASIDPath, EC);
832
- if (EC)
833
- return llvm::errorCodeToError (EC);
834
- writeCASIDBuffer (CAS.getID (O.Object ), IDOS);
832
+ auto IDOut = Backend.createFile (CASIDPath);
833
+ if (!IDOut)
834
+ return IDOut.takeError ();
835
+ writeCASIDBuffer (CAS.getID (O.Object ), *IDOut);
836
+ if (auto E = IDOut->keep ())
837
+ return E;
835
838
}
836
839
auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
837
- if (auto E = Schema->serializeObjectFile (*Obj, OS ))
840
+ if (auto E = Schema->serializeObjectFile (*Obj, *Output ))
838
841
return E;
839
842
}
840
- Contents = ContentsStorage;
841
- } else if (JustComputedResult) {
843
+ return Output->keep ();
844
+ }
845
+
846
+ if (JustComputedResult)
842
847
return Error::success (); // continue
843
- } else if (O.Kind == OutputKind::Dependencies) {
844
- llvm::raw_svector_ostream OS (ContentsStorage);
848
+
849
+ auto Output = Backend.createFile (Path);
850
+ if (!Output)
851
+ return Output.takeError ();
852
+ if (O.Kind == OutputKind::Dependencies) {
845
853
if (auto E = CASDependencyCollector::replay (
846
- Clang.getDependencyOutputOpts (), CAS, *Obj, OS ))
854
+ Clang.getDependencyOutputOpts (), CAS, *Obj, *Output ))
847
855
return E;
848
- Contents = ContentsStorage;
849
856
} else {
850
- Contents = Obj->getData ();
857
+ *Output << Obj->getData ();
851
858
}
852
859
853
- std::unique_ptr<llvm::FileOutputBuffer> Output;
854
- if (Error E = llvm::FileOutputBuffer::create (Path, Contents->size ())
855
- .moveInto (Output))
856
- return E;
857
- llvm::copy (*Contents, Output->getBufferStart ());
858
- return Output->commit ();
860
+ return Output->keep ();
859
861
};
860
862
861
863
if (auto Err = Result.forEachLoadedOutput (processOutput))
0 commit comments