Skip to content

Commit 7b6f573

Browse files
committed
Address review comments
Also fix stack-allocated `CommandLine` entries when using a InplaceCompilationDatabase
1 parent 3eaba52 commit 7b6f573

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

clang/test/ClangScanDeps/response-file-clang-cl.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,53 @@
22

33
// RUN: rm -rf %t
44
// RUN: split-file %s %t
5+
6+
// First run the tests with a .cdb
57
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
6-
// RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
8+
// RUN: sed -e "s|DIR|%/t|g" %t/args_nested.template > %t/args_nested.rsp
79

8-
// RUN: echo /c >> %t/args_nested.rsp
9-
// RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
10+
// RUN: cp %t/args_compilation.rsp %t/args.rsp
11+
// RUN: clang-scan-deps --compilation-database %t/cdb.json > %t/deps.json
1012
// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s
1113

12-
// RUN: echo /E >> %t/args_nested.rsp
13-
// RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
14+
// RUN: cp %t/args_preprocess.rsp %t/args.rsp
15+
// RUN: clang-scan-deps --compilation-database %t/cdb.json > %t/deps.json
1416
// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s
1517

18+
19+
// Now run the tests again with a in-place compilation database
20+
// RUN: cd %t
21+
22+
// RUN: cp args_compilation.rsp args.rsp
23+
// RUN: clang-scan-deps -o deps.json -- %clang_cl @args.rsp
24+
// RUN: cat deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s
25+
26+
// RUN: cp args_preprocess.rsp args.rsp
27+
// RUN: clang-scan-deps -o deps.json -- %clang_cl @args.rsp
28+
// RUN: cat deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s
29+
1630
// Here we ensure that we got a qualified .obj with its full path, since that's what we're passing with /Fo
1731
// CHECK: [[PREFIX]]/tu.obj:
1832

1933
//--- cdb.json.template
2034
[{
21-
"file": "DIR/t.cpp",
35+
"file": "DIR/tu.cpp",
2236
"directory": "DIR",
2337
"command": "clang-cl @DIR/args.rsp"
2438
}]
2539

26-
//--- args.rsp
40+
//--- args_compilation.rsp
2741
@args_nested.rsp
28-
tu.cpp
42+
/c
43+
44+
//--- args_preprocess.rsp
45+
@args_nested.rsp
46+
/E
2947

30-
//--- args_nested.rsp
48+
//--- args_nested.template
3149
/I include
50+
tu.cpp
51+
/FoDIR/tu.obj
3252

3353
//--- include/header.h
3454

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ static bool DeprecatedDriverCommand;
8686
static ResourceDirRecipeKind ResourceDirRecipe;
8787
static bool Verbose;
8888
static bool PrintTiming;
89+
static llvm::BumpPtrAllocator Alloc;
90+
static llvm::StringSaver Saver{Alloc};
8991
static std::vector<const char *> CommandLine;
9092

9193
#ifndef NDEBUG
@@ -99,8 +101,6 @@ static bool RoundTripArgs = DoRoundTripDefault;
99101
static void ParseArgs(int argc, char **argv) {
100102
ScanDepsOptTable Tbl;
101103
llvm::StringRef ToolName = argv[0];
102-
llvm::BumpPtrAllocator Alloc;
103-
llvm::StringSaver Saver{Alloc};
104104
llvm::opt::InputArgList Args =
105105
Tbl.parseArgs(argc, argv, OPT_UNKNOWN, Saver, [&](StringRef Msg) {
106106
llvm::errs() << Msg << '\n';
@@ -794,13 +794,13 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
794794

795795
// Expand response files in advance, so that we can "see" all the arguments
796796
// when adjusting below.
797-
auto ResponseExpander = expandResponseFiles(std::move(Compilations),
798-
llvm::vfs::getRealFileSystem());
797+
Compilations = expandResponseFiles(std::move(Compilations),
798+
llvm::vfs::getRealFileSystem());
799799

800800
// The command options are rewritten to run Clang in preprocessor only mode.
801801
auto AdjustingCompilations =
802802
std::make_unique<tooling::ArgumentsAdjustingCompilations>(
803-
std::move(ResponseExpander));
803+
std::move(Compilations));
804804
ResourceDirectoryCache ResourceDirCache;
805805

806806
AdjustingCompilations->appendArgumentsAdjuster(

0 commit comments

Comments
 (0)