@@ -57,16 +57,39 @@ class SwiftCASOutputBackend::Implementation {
57
57
public:
58
58
Implementation (ObjectStore &CAS, ActionCache &Cache, ObjectRef BaseKey,
59
59
const FrontendInputsAndOutputs &InputsAndOutputs,
60
+ const FrontendOptions &Opts,
60
61
FrontendOptions::ActionType Action)
61
62
: CAS(CAS), Cache(Cache), BaseKey(BaseKey),
62
- InputsAndOutputs (InputsAndOutputs), Action(Action) {
63
+ InputsAndOutputs (InputsAndOutputs), Opts(Opts), Action(Action) {
63
64
initBackend (InputsAndOutputs);
64
65
}
65
66
66
67
llvm::Expected<std::unique_ptr<llvm::vfs::OutputFileImpl>>
67
68
createFileImpl (llvm::StringRef ResolvedPath,
68
69
std::optional<llvm::vfs::OutputConfig> Config) {
69
70
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
+ }
70
93
assert (ProducingInput != OutputToInputMap.end () && " Unknown output file" );
71
94
72
95
unsigned InputIndex = ProducingInput->second .first ;
@@ -97,21 +120,24 @@ class SwiftCASOutputBackend::Implementation {
97
120
ActionCache &Cache;
98
121
ObjectRef BaseKey;
99
122
const FrontendInputsAndOutputs &InputsAndOutputs;
123
+ const FrontendOptions &Opts;
100
124
FrontendOptions::ActionType Action;
101
125
102
126
// Map from output path to the input index and output kind.
103
127
StringMap<std::pair<unsigned , file_types::ID>> OutputToInputMap;
104
128
105
129
// A vector of output refs where the index is the input index.
106
130
SmallVector<DenseMap<file_types::ID, ObjectRef>> OutputRefs;
131
+
132
+ SmallVector<ObjectRef> SymbolGraphOutputRefs;
107
133
};
108
134
109
135
SwiftCASOutputBackend::SwiftCASOutputBackend (
110
136
ObjectStore &CAS, ActionCache &Cache, ObjectRef BaseKey,
111
137
const FrontendInputsAndOutputs &InputsAndOutputs,
112
- FrontendOptions::ActionType Action)
138
+ const FrontendOptions &Opts, FrontendOptions::ActionType Action)
113
139
: Impl(*new SwiftCASOutputBackend::Implementation(
114
- CAS, Cache, BaseKey, InputsAndOutputs, Action)) {}
140
+ CAS, Cache, BaseKey, InputsAndOutputs, Opts, Action)) {}
115
141
116
142
SwiftCASOutputBackend::~SwiftCASOutputBackend () { delete &Impl; }
117
143
@@ -122,7 +148,8 @@ bool SwiftCASOutputBackend::isStoredDirectly(file_types::ID Kind) {
122
148
123
149
IntrusiveRefCntPtr<OutputBackend> SwiftCASOutputBackend::cloneImpl () const {
124
150
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 );
126
153
}
127
154
128
155
Expected<std::unique_ptr<OutputFileImpl>>
@@ -243,6 +270,13 @@ Error SwiftCASOutputBackend::Implementation::finalizeCacheKeysFor(
243
270
llvm::for_each (ProducedOutputs, [&OutputsForInput](auto E) {
244
271
OutputsForInput.emplace_back (E.first , E.second );
245
272
});
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
+ }
246
280
// Sort to a stable ordering for deterministic output cache object.
247
281
llvm::sort (OutputsForInput,
248
282
[](auto &LHS, auto &RHS) { return LHS.first < RHS.first ; });
0 commit comments