summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJan Korous <jkorous@apple.com>2019-09-12 00:48:45 +0000
committerJan Korous <jkorous@apple.com>2019-09-12 00:48:45 +0000
commit23a6eed24ca3cbe75d9173ca0272cac2d88578de (patch)
tree5883347441017d2c575d20386f591135d6cb976b /tools
parentf38445a332418eb3fa4a707d3a6d40e11a6c3601 (diff)
downloadclang-23a6eed24ca3cbe75d9173ca0272cac2d88578de.tar.gz
[clang-scan-deps] Add dependency targets
Differential Revision: https://reviews.llvm.org/D67475 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@371697 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/clang-scan-deps/ClangScanDeps.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/tools/clang-scan-deps/ClangScanDeps.cpp b/tools/clang-scan-deps/ClangScanDeps.cpp
index 2181e0e0d3..4020a4ce64 100644
--- a/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -178,6 +178,13 @@ llvm::cl::opt<bool> SkipExcludedPPRanges(
} // end anonymous namespace
+/// \returns object-file path derived from source-file path.
+static std::string getObjFilePath(StringRef SrcFile) {
+ SmallString<128> ObjFileName(SrcFile);
+ llvm::sys::path::replace_extension(ObjFileName, "o");
+ return ObjFileName.str();
+}
+
int main(int argc, const char **argv) {
llvm::InitLLVM X(argc, argv);
llvm::cl::HideUnrelatedOptions(DependencyScannerCategory);
@@ -206,10 +213,45 @@ int main(int argc, const char **argv) {
std::make_unique<tooling::ArgumentsAdjustingCompilations>(
std::move(Compilations));
AdjustingCompilations->appendArgumentsAdjuster(
- [](const tooling::CommandLineArguments &Args, StringRef /*unused*/) {
+ [](const tooling::CommandLineArguments &Args, StringRef FileName) {
+ std::string LastO = "";
+ bool HasMT = false;
+ bool HasMQ = false;
+ bool HasMD = false;
+ // We need to find the last -o value.
+ if (!Args.empty()) {
+ std::size_t Idx = Args.size() - 1;
+ for (auto It = Args.rbegin(); It != Args.rend(); ++It) {
+ if (It != Args.rbegin()) {
+ if (Args[Idx] == "-o")
+ LastO = Args[Idx + 1];
+ if (Args[Idx] == "-MT")
+ HasMT = true;
+ if (Args[Idx] == "-MQ")
+ HasMQ = true;
+ if (Args[Idx] == "-MD")
+ HasMD = true;
+ }
+ --Idx;
+ }
+ }
+ // If there's no -MT/-MQ Driver would add -MT with the value of the last
+ // -o option.
tooling::CommandLineArguments AdjustedArgs = Args;
AdjustedArgs.push_back("-o");
AdjustedArgs.push_back("/dev/null");
+ if (!HasMT && !HasMQ) {
+ AdjustedArgs.push_back("-MT");
+ // We're interested in source dependencies of an object file.
+ if (!HasMD) {
+ // FIXME: We are missing the directory unless the -o value is an
+ // absolute path.
+ AdjustedArgs.push_back(!LastO.empty() ? LastO
+ : getObjFilePath(FileName));
+ } else {
+ AdjustedArgs.push_back(FileName);
+ }
+ }
AdjustedArgs.push_back("-Xclang");
AdjustedArgs.push_back("-Eonly");
AdjustedArgs.push_back("-Xclang");