@@ -169,20 +169,31 @@ static bool emitMakeDependenciesIfNeeded(DiagnosticEngine &diags,
169169
170170 llvm::SmallString<256 > buffer;
171171
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+
172192 // FIXME: Xcode can't currently handle multiple targets in a single
173193 // dependency line.
174194 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 ' ;
186197 });
187198
188199 return false ;
0 commit comments