diff options
author | 2020-11-30 11:56:37 -0500 | |
---|---|---|
committer | 2020-12-01 15:04:15 -0500 | |
commit | 79ba7967f4813445c3ce5624170c19584bbfda72 (patch) | |
tree | 52d6127713b42532e27c334e87c02efbedc0249d | |
parent | [CMake][NewPM] Move ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER into llvm/ (diff) | |
download | llvm-project-79ba7967f4813445c3ce5624170c19584bbfda72.tar.gz llvm-project-79ba7967f4813445c3ce5624170c19584bbfda72.tar.bz2 llvm-project-79ba7967f4813445c3ce5624170c19584bbfda72.zip |
[clang-scan-deps] Improve argument parsing to find target object file path.
Support the joined version of -o (-ofilepath), and ensure we use the last provided -o option.
Differential Revision: https://reviews.llvm.org/D92330
-rw-r--r-- | clang/test/ClangScanDeps/Inputs/target-filename-cdb.json | 22 | ||||
-rw-r--r-- | clang/test/ClangScanDeps/target-filename.cpp | 20 | ||||
-rw-r--r-- | clang/tools/clang-scan-deps/ClangScanDeps.cpp | 23 |
3 files changed, 55 insertions, 10 deletions
diff --git a/clang/test/ClangScanDeps/Inputs/target-filename-cdb.json b/clang/test/ClangScanDeps/Inputs/target-filename-cdb.json new file mode 100644 index 000000000000..af2e43e4e171 --- /dev/null +++ b/clang/test/ClangScanDeps/Inputs/target-filename-cdb.json @@ -0,0 +1,22 @@ +[ +{ + "directory": "DIR", + "command": "clang -E DIR/target-filename_input.cpp", + "file": "DIR/target-filename_input.cpp" +}, +{ + "directory": "DIR", + "command": "clang -E DIR/target-filename_input.cpp -o a.o", + "file": "DIR/target-filename_input.cpp" +}, +{ + "directory": "DIR", + "command": "clang -E DIR/target-filename_input.cpp -ob.o", + "file": "DIR/target-filename_input.cpp" +}, +{ + "directory": "DIR", + "command": "clang -E DIR/target-filename_input.cpp -o first.o -o last.o", + "file": "DIR/target-filename_input.cpp" +} +] diff --git a/clang/test/ClangScanDeps/target-filename.cpp b/clang/test/ClangScanDeps/target-filename.cpp new file mode 100644 index 000000000000..c47166b21e4e --- /dev/null +++ b/clang/test/ClangScanDeps/target-filename.cpp @@ -0,0 +1,20 @@ +// RUN: rm -rf %t.dir +// RUN: rm -rf %t.cdb +// RUN: mkdir -p %t.dir +// RUN: cp %s %t.dir/target-filename_input.cpp +// RUN: mkdir %t.dir/Inputs +// RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h +// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/target-filename-cdb.json > %t.cdb +// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 | FileCheck %s + +// CHECK: target-filename_input.o: +// CHECK-NEXT: target-filename_input.cpp + +// CHECK-NEXT: a.o: +// CHECK-NEXT: target-filename_input.cpp + +// CHECK-NEXT: b.o: +// CHECK-NEXT: target-filename_input.cpp + +// CHECK-NEXT: last.o: +// CHECK-NEXT: target-filename_input.cpp diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp index 91d2dc23d861..1bb65ef12d6b 100644 --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -425,18 +425,21 @@ int main(int argc, const char **argv) { 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") + StringRef Arg = Args[Idx]; + if (LastO.empty()) { + if (Arg == "-o" && It != Args.rbegin()) LastO = Args[Idx + 1]; - if (Args[Idx] == "-MT") - HasMT = true; - if (Args[Idx] == "-MQ") - HasMQ = true; - if (Args[Idx] == "-MD") - HasMD = true; - if (Args[Idx] == "-resource-dir") - HasResourceDir = true; + else if (Arg.startswith("-o")) + LastO = Arg.drop_front(2).str(); } + if (Arg == "-MT") + HasMT = true; + if (Arg == "-MQ") + HasMQ = true; + if (Arg == "-MD") + HasMD = true; + if (Arg == "-resource-dir") + HasResourceDir = true; --Idx; } } |