mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
57
lib/Frontend/DependencyFileGenerator.cpp
Normal file
57
lib/Frontend/DependencyFileGenerator.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
//===- DependencyFileGenerator.cpp - .d file generation -------------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See http://swift.org/LICENSE.txt for license information
|
||||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/Frontend/DependencyFileGenerator.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
using namespace swift;
|
||||
|
||||
void DependencyFileGenerator::addDependency(StringRef file) {
|
||||
paths.insert(file);
|
||||
}
|
||||
|
||||
void DependencyFileGenerator::addTarget(StringRef targetName) {
|
||||
if (!targetName.empty())
|
||||
targets.push_back(targetName);
|
||||
}
|
||||
|
||||
void DependencyFileGenerator::writeToStream(llvm::raw_ostream &os) const {
|
||||
// Declare a helper for escaping file names for use in Makefiles.
|
||||
llvm::SmallString<256> pathBuf;
|
||||
auto escape = [&](StringRef raw) -> StringRef {
|
||||
pathBuf.clear();
|
||||
|
||||
static const char badChars[] = " $#:\n";
|
||||
size_t prev = 0;
|
||||
for (auto index = raw.find_first_of(badChars); index != StringRef::npos;
|
||||
index = raw.find_first_of(badChars, index+1)) {
|
||||
pathBuf.append(raw.slice(prev, index));
|
||||
if (pathBuf[index] == '$')
|
||||
pathBuf.push_back('$');
|
||||
else
|
||||
pathBuf.push_back('\\');
|
||||
prev = index;
|
||||
}
|
||||
pathBuf.append(raw.substr(prev));
|
||||
return pathBuf;
|
||||
};
|
||||
|
||||
// FIXME: Xcode can't currently handle multiple targets in a single
|
||||
// dependency line.
|
||||
for (StringRef targetName : targets) {
|
||||
os << targetName << " :";
|
||||
for (StringRef path : paths)
|
||||
os << ' ' << escape(path);
|
||||
os << '\n';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user