@@ -57,16 +57,39 @@ class SwiftCASOutputBackend::Implementation {
5757public:
5858 Implementation (ObjectStore &CAS, ActionCache &Cache, ObjectRef BaseKey,
5959 const FrontendInputsAndOutputs &InputsAndOutputs,
60+ const FrontendOptions &Opts,
6061 FrontendOptions::ActionType Action)
6162 : CAS(CAS), Cache(Cache), BaseKey(BaseKey),
62- InputsAndOutputs (InputsAndOutputs), Action(Action) {
63+ InputsAndOutputs (InputsAndOutputs), Opts(Opts), Action(Action) {
6364 initBackend (InputsAndOutputs);
6465 }
6566
6667 llvm::Expected<std::unique_ptr<llvm::vfs::OutputFileImpl>>
6768 createFileImpl (llvm::StringRef ResolvedPath,
6869 std::optional<llvm::vfs::OutputConfig> Config) {
6970 auto ProducingInput = OutputToInputMap.find (ResolvedPath);
71+ if (ProducingInput == OutputToInputMap.end () &&
72+ ResolvedPath.starts_with (Opts.SymbolGraphOutputDir )) {
73+ return std::make_unique<SwiftCASOutputFile>(
74+ ResolvedPath, [this ](StringRef Path, StringRef Bytes) -> Error {
75+ bool Shortened = Path.consume_front (Opts.SymbolGraphOutputDir );
76+ assert (Shortened && " symbol graph path outside output dir" );
77+ (void )Shortened;
78+ std::optional<ObjectRef> PathRef;
79+ if (Error E =
80+ CAS.storeFromString (std::nullopt , Path).moveInto (PathRef))
81+ return E;
82+ std::optional<ObjectRef> BytesRef;
83+ if (Error E =
84+ CAS.storeFromString (std::nullopt , Bytes).moveInto (BytesRef))
85+ return E;
86+ auto Ref = CAS.store ({*PathRef, *BytesRef}, {});
87+ if (!Ref)
88+ return Ref.takeError ();
89+ SymbolGraphOutputRefs.push_back (*Ref);
90+ return Error::success ();
91+ });
92+ }
7093 assert (ProducingInput != OutputToInputMap.end () && " Unknown output file" );
7194
7295 unsigned InputIndex = ProducingInput->second .first ;
@@ -97,21 +120,24 @@ class SwiftCASOutputBackend::Implementation {
97120 ActionCache &Cache;
98121 ObjectRef BaseKey;
99122 const FrontendInputsAndOutputs &InputsAndOutputs;
123+ const FrontendOptions &Opts;
100124 FrontendOptions::ActionType Action;
101125
102126 // Map from output path to the input index and output kind.
103127 StringMap<std::pair<unsigned , file_types::ID>> OutputToInputMap;
104128
105129 // A vector of output refs where the index is the input index.
106130 SmallVector<DenseMap<file_types::ID, ObjectRef>> OutputRefs;
131+
132+ SmallVector<ObjectRef> SymbolGraphOutputRefs;
107133};
108134
109135SwiftCASOutputBackend::SwiftCASOutputBackend (
110136 ObjectStore &CAS, ActionCache &Cache, ObjectRef BaseKey,
111137 const FrontendInputsAndOutputs &InputsAndOutputs,
112- FrontendOptions::ActionType Action)
138+ const FrontendOptions &Opts, FrontendOptions::ActionType Action)
113139 : Impl(*new SwiftCASOutputBackend::Implementation(
114- CAS, Cache, BaseKey, InputsAndOutputs, Action)) {}
140+ CAS, Cache, BaseKey, InputsAndOutputs, Opts, Action)) {}
115141
116142SwiftCASOutputBackend::~SwiftCASOutputBackend () { delete &Impl; }
117143
@@ -122,7 +148,8 @@ bool SwiftCASOutputBackend::isStoredDirectly(file_types::ID Kind) {
122148
123149IntrusiveRefCntPtr<OutputBackend> SwiftCASOutputBackend::cloneImpl () const {
124150 return makeIntrusiveRefCnt<SwiftCASOutputBackend>(
125- Impl.CAS , Impl.Cache , Impl.BaseKey , Impl.InputsAndOutputs , Impl.Action );
151+ Impl.CAS , Impl.Cache , Impl.BaseKey , Impl.InputsAndOutputs , Impl.Opts ,
152+ Impl.Action );
126153}
127154
128155Expected<std::unique_ptr<OutputFileImpl>>
@@ -243,6 +270,13 @@ Error SwiftCASOutputBackend::Implementation::finalizeCacheKeysFor(
243270 llvm::for_each (ProducedOutputs, [&OutputsForInput](auto E) {
244271 OutputsForInput.emplace_back (E.first , E.second );
245272 });
273+ if (InputIndex == InputsAndOutputs.getIndexOfFirstOutputProducingInput () &&
274+ !SymbolGraphOutputRefs.empty ()) {
275+ auto SGRef = CAS.store (SymbolGraphOutputRefs, {});
276+ if (!SGRef)
277+ return SGRef.takeError ();
278+ OutputsForInput.emplace_back (file_types::ID::TY_SymbolGraphFile, *SGRef);
279+ }
246280 // Sort to a stable ordering for deterministic output cache object.
247281 llvm::sort (OutputsForInput,
248282 [](auto &LHS, auto &RHS) { return LHS.first < RHS.first ; });
0 commit comments