[clang-scan-deps] Add dependency targets

Differential Revision: https://reviews.llvm.org/D67475

llvm-svn: 371697
This commit is contained in:
Jan Korous 2019-09-12 00:48:45 +00:00
parent aaef97a55e
commit b51a285c4c
8 changed files with 53 additions and 10 deletions

View File

@ -2,11 +2,11 @@
{
"directory": "DIR",
"command": "clang -E DIR/subframework_header_dir_symlink_input.m -D EMPTY -iframework Inputs/frameworks",
"file": "DIR/subframework_header_dir_symlink.m"
"file": "DIR/subframework_header_dir_symlink_input.m"
},
{
"directory": "DIR",
"command": "clang -E DIR/subframework_header_dir_symlink_input2.m -FInputs/frameworks -iframework Inputs/frameworks_symlink",
"file": "DIR/subframework_header_dir_symlink2.m"
"file": "DIR/subframework_header_dir_symlink_input2.m"
}
]

View File

@ -2,11 +2,11 @@
{
"directory": "DIR",
"command": "clang -E DIR/symlink_input.cpp -IInputs",
"file": "DIR/symlink.cpp"
"file": "DIR/symlink_input.cpp"
},
{
"directory": "DIR",
"command": "clang -E DIR/symlink_input2.cpp -IInputs",
"file": "DIR/symlink2.cpp"
"file": "DIR/symlink_input2.cpp"
}
]

View File

@ -2,6 +2,6 @@
{
"directory": "DIR",
"command": "clang -E DIR/vfsoverlay_input.cpp -IInputs -ivfsoverlay DIR/vfsoverlay.yaml",
"file": "DIR/vfsoverlay.cpp"
"file": "DIR/vfsoverlay_input.cpp"
}
]

View File

@ -12,7 +12,7 @@
#include "Framework/Framework.h"
#include "Framework/PrivateHeader.h"
// CHECK: clang-scan-deps dependency
// CHECK: header_stat_before_open_input.o
// CHECK-NEXT: header_stat_before_open_input.m
// CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}Headers{{/|\\}}Framework.h
// CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}PrivateHeaders{{/|\\}}PrivateHeader.h

View File

@ -36,6 +36,7 @@
#include "header.h"
// CHECK1: regular_cdb_input2.cpp
// CHECK1-NEXT: regular_cdb_input2.cpp
// CHECK1-NEXT: Inputs{{/|\\}}header.h
// CHECK1-NEXT: Inputs{{/|\\}}header2.h

View File

@ -17,8 +17,8 @@
#include "Framework/Framework.h"
#endif
// CHECK: clang-scan-deps dependency
// CHECK: subframework_header_dir_symlink_input.o
// CHECK-NEXT: subframework_header_dir_symlink_input.m
// CHECK: clang-scan-deps dependency
// CHECK: subframework_header_dir_symlink_input2.o
// CHECK-NEXT: subframework_header_dir_symlink_input2.m
// CHECK-NEXT: Inputs{{/|\\}}frameworks_symlink{{/|\\}}Framework.framework{{/|\\}}Headers{{/|\\}}Framework.h

View File

@ -12,6 +12,6 @@
#include "not_real.h"
// CHECK: clang-scan-deps dependency
// CHECK: vfsoverlay_input.o
// CHECK-NEXT: vfsoverlay_input.cpp
// CHECK-NEXT: Inputs{{/|\\}}header.h

View File

@ -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");