[PATCH] D92330: [clang-scan-deps] Improve argument parsing to find target object file path.
Sylvain Audi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 1 12:04:41 PST 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG79ba7967f481: [clang-scan-deps] Improve argument parsing to find target object file path. (authored by saudi).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92330/new/
https://reviews.llvm.org/D92330
Files:
clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
clang/test/ClangScanDeps/target-filename.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp
Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===================================================================
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -425,18 +425,21 @@
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;
}
}
Index: clang/test/ClangScanDeps/target-filename.cpp
===================================================================
--- /dev/null
+++ 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
Index: clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
===================================================================
--- /dev/null
+++ 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"
+}
+]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92330.308731.patch
Type: text/x-patch
Size: 2958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201201/7152df28/attachment.bin>
More information about the cfe-commits
mailing list