@@ -169,20 +169,31 @@ static bool emitMakeDependenciesIfNeeded(DiagnosticEngine &diags,
169
169
170
170
llvm::SmallString<256 > buffer;
171
171
172
+ // collect everything in memory to avoid redundant work
173
+ // when there are multiple targets
174
+ std::string dependencyString;
175
+
176
+ // First include all other files in the module. Make-style dependencies
177
+ // need to be conservative!
178
+ auto inputPaths =
179
+ reversePathSortedFilenames (opts.InputsAndOutputs .getInputFilenames ());
180
+ for (auto const &path : inputPaths) {
181
+ dependencyString.push_back (' ' );
182
+ dependencyString.append (frontend::utils::escapeForMake (path, buffer));
183
+ }
184
+ // Then print dependencies we've picked up during compilation.
185
+ auto dependencyPaths =
186
+ reversePathSortedFilenames (depTracker->getDependencies ());
187
+ for (auto const &path : dependencyPaths) {
188
+ dependencyString.push_back (' ' );
189
+ dependencyString.append (frontend::utils::escapeForMake (path, buffer));
190
+ }
191
+
172
192
// FIXME: Xcode can't currently handle multiple targets in a single
173
193
// dependency line.
174
194
opts.forAllOutputPaths (input, [&](const StringRef targetName) {
175
- out << swift::frontend::utils::escapeForMake (targetName, buffer) << " :" ;
176
- // First include all other files in the module. Make-style dependencies
177
- // need to be conservative!
178
- for (auto const &path :
179
- reversePathSortedFilenames (opts.InputsAndOutputs .getInputFilenames ()))
180
- out << ' ' << swift::frontend::utils::escapeForMake (path, buffer);
181
- // Then print dependencies we've picked up during compilation.
182
- for (auto const &path :
183
- reversePathSortedFilenames (depTracker->getDependencies ()))
184
- out << ' ' << swift::frontend::utils::escapeForMake (path, buffer);
185
- out << ' \n ' ;
195
+ auto targetNameEscaped = frontend::utils::escapeForMake (targetName, buffer);
196
+ out << targetNameEscaped << " :" << dependencyString << ' \n ' ;
186
197
});
187
198
188
199
return false ;
0 commit comments