Add support for dependency file generation with -emit-dependencies.

This performs very conservative dependency generation for each compile task
within a full compilation. Any source file, swiftmodule, or Objective-C
header file that is /touched/ gets added to the dependencies list, which
is written out on a per-input basis at the end of compilation.

This does /not/ handle dependencies for the aggregated swiftmodule, swiftdoc,
generated header, or linked binary. This is just the minimum needed to get
Xcode to recognize what needs to be rebuilt when a header or Swift source
file changes. We can revisit this later.

This finishes <rdar://problem/14899639> for now.

Swift SVN r18045
This commit is contained in:
Jordan Rose
2014-05-14 00:34:11 +00:00
parent 67f319b747
commit 2877bd0854
21 changed files with 289 additions and 24 deletions

View File

@@ -22,6 +22,7 @@
#include "swift/AST/IRGenOptions.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Driver/Options.h"
#include "swift/Frontend/DependencyFileGenerator.h"
#include "swift/Frontend/DiagnosticVerifier.h"
#include "swift/Frontend/Frontend.h"
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
@@ -49,6 +50,26 @@ static std::string displayName(StringRef MainExecutablePath) {
return Name;
}
static bool emitDependencies(DiagnosticEngine &Diags,
DependencyFileGenerator &DFG,
const FrontendOptions &opts) {
opts.forAllOutputPaths([&DFG](StringRef target) { DFG.addTarget(target); });
std::string errorInfo;
llvm::raw_fd_ostream out(opts.DependenciesFilePath.c_str(), errorInfo,
llvm::sys::fs::F_None);
if (out.has_error() || !errorInfo.empty()) {
Diags.diagnose(SourceLoc(), diag::error_opening_output,
opts.DependenciesFilePath, errorInfo);
out.clear_error();
return true;
}
DFG.writeToStream(out);
return false;
}
/// Writes SIL out to the given file.
static bool writeSIL(SILModule &SM, Module *M, bool EmitVerboseSIL,
std::string &OutputFilename) {
@@ -133,6 +154,11 @@ static bool performCompile(CompilerInstance &Instance,
// If we were asked to print Clang stats, do so.
if (opts.PrintClangStats && Context.getClangModuleLoader())
Context.getClangModuleLoader()->printStatistics();
if (DependencyTracker *DT = Instance.getDependencyTracker()) {
auto &DFG = *static_cast<DependencyFileGenerator*>(DT);
(void)emitDependencies(Context.Diags, DFG, opts);
}
// We've just been told to perform a parse, so we can return now.
if (Action == FrontendOptions::Parse) {
@@ -343,6 +369,10 @@ int frontend_main(ArrayRef<const char *>Args,
enableDiagnosticVerifier(Instance.getSourceMgr());
}
DependencyFileGenerator DFG;
if (!Invocation.getFrontendOptions().DependenciesFilePath.empty())
Instance.setDependencyTracker(&DFG);
if (Instance.setup(Invocation)) {
return 1;
}