Skip to content

Commit 30cb49b

Browse files
committed
[clang][deps] NFC: De-duplicate clang-cl tests
In D92191, a bunch of test cases were added to check `clang-scan-deps` works in `clang-cl` mode as well. We don't need to duplicate all test cases, though. Testing the few special cases we have in `clang-scan-deps` for `clang-cl` should be good enough: 1. Deducing output path (and therefore target name in our make output). 2. Ignoring `-Xclang` arguments in step 1. 3. Deducing resource directory by invoking the compiler executuable. This test de-duplicates the extra clang-cl test cases. Reviewed By: dexonsmith, saudi Differential Revision: https://reviews.llvm.org/D121812
1 parent 26053ce commit 30cb49b

29 files changed

+147
-239
lines changed

clang/test/ClangScanDeps/Inputs/has_include_if_elif.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
"directory": "DIR",
44
"command": "clang -E DIR/has_include_if_elif2.cpp -IInputs",
55
"file": "DIR/has_include_if_elif2.cpp"
6-
},
7-
{
8-
"directory": "DIR",
9-
"command": "clang-cl /E /IInputs -- DIR/has_include_if_elif2_clangcl.cpp",
10-
"file": "DIR/has_include_if_elif2_clangcl.cpp"
116
}
127
]

clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
"directory": "DIR",
44
"command": "clang -E DIR/header_stat_before_open_input.m -iframework Inputs/frameworks",
55
"file": "DIR/header_stat_before_open_input.m"
6-
},
7-
{
8-
"directory": "DIR",
9-
"command": "clang-cl /E -Xclang -iframework -Xclang Inputs/frameworks -- DIR/header_stat_before_open_input_clangcl.m",
10-
"file": "DIR/header_stat_before_open_input_clangcl.m"
116
}
127
]

clang/test/ClangScanDeps/Inputs/headerwithdirname.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
"directory": "DIR",
44
"command": "clang -c -IDIR -IDIR/foodir -IInputs DIR/headerwithdirname_input.cpp",
55
"file": "DIR/headerwithdirname_input.cpp"
6-
},
7-
{
8-
"directory": "DIR",
9-
"command": "clang-cl /c /IDIR /IDIR/foodir -IInputs -- DIR/headerwithdirname_input_clangcl.cpp",
10-
"file": "DIR/headerwithdirname_input_clangcl.cpp"
116
}
127
]

clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
"directory": "DIR",
44
"command": "clang -c -IDIR -IInputs DIR/headerwithdirname_input.cpp",
55
"file": "DIR/headerwithdirname_input.cpp"
6-
},
7-
{
8-
"directory": "DIR",
9-
"command": "clang-cl /c /IDIR /IInputs -- DIR/headerwithdirname_input_clangcl.cpp",
10-
"file": "DIR/headerwithdirname_input_clangcl.cpp"
116
}
127
]

clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl_by_mod_name.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

clang/test/ClangScanDeps/Inputs/no-werror.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
"directory": "DIR",
44
"command": "clang -E DIR/no-werror_input.cpp -IInputs -std=c++17 -Weverything -Werror",
55
"file": "DIR/no-werror.cpp"
6-
},
7-
{
8-
"directory": "DIR",
9-
"command": "clang-cl /E /IInputs /std:c++17 -Weverything -Werror -- DIR/no-werror_input_clangcl.cpp",
10-
"file": "DIR/no-werror_clangcl.cpp"
116
}
127
]

clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
"directory": "DIR",
44
"command": "clang --analyze DIR/static-analyzer_clang.c",
55
"file": "DIR/static-analyzer_clang.c"
6-
},
7-
{
8-
"directory": "DIR",
9-
"command": "clang-cl --analyze -- DIR/static-analyzer_clangcl.c",
10-
"file": "DIR/static-analyzer_clangcl.c"
116
}
127
]

clang/test/ClangScanDeps/Inputs/target-filename-cdb.json

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,5 @@
2323
"directory": "DIR",
2424
"command": "clang-cl /E -- DIR/target-filename_input.cpp",
2525
"file": "DIR/target-filename_input.cpp"
26-
},
27-
{
28-
"directory": "DIR",
29-
"command": "clang-cl /E -o clangcl-a.o -- DIR/target-filename_input.cpp",
30-
"file": "DIR/target-filename_input.cpp"
31-
},
32-
{
33-
"directory": "DIR",
34-
"command": "clang-cl /E -oclangcl-b.o -- DIR/target-filename_input.cpp",
35-
"file": "DIR/target-filename_input.cpp"
36-
},
37-
{
38-
"directory": "DIR",
39-
"command": "clang-cl /E /o clangcl-c.o -- DIR/target-filename_input.cpp",
40-
"file": "DIR/target-filename_input.cpp"
41-
},
42-
{
43-
"directory": "DIR",
44-
"command": "clang-cl /E /oclangcl-d.o -- DIR/target-filename_input.cpp",
45-
"file": "DIR/target-filename_input.cpp"
46-
},
47-
{
48-
"directory": "DIR",
49-
"command": "clang-cl /E /Foclangcl-e.o -- DIR/target-filename_input.cpp",
50-
"file": "DIR/target-filename_input.cpp"
51-
},
52-
{
53-
"directory": "DIR",
54-
"command": "clang-cl /E -o clangcl-firstf.o -o clangcl-lastf.o -- DIR/target-filename_input.cpp",
55-
"file": "DIR/target-filename_input.cpp"
56-
},
57-
{
58-
"directory": "DIR",
59-
"command": "clang-cl /E /oclangcl-firstg.o /Foclangcl-lastg.o -- DIR/target-filename_input.cpp",
60-
"file": "DIR/target-filename_input.cpp"
61-
},
62-
{
63-
"directory": "DIR",
64-
"command": "clang-cl /E /Foclangcl-firsth.o -o clangcl-midh.o /oclangcl-lasth.o -- DIR/target-filename_input.cpp",
65-
"file": "DIR/target-filename_input.cpp"
6626
}
6727
]

clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,4 @@
44
"command": "clang -E DIR/vfsoverlay_input.cpp -IInputs -ivfsoverlay DIR/vfsoverlay.yaml",
55
"file": "DIR/vfsoverlay_input.cpp"
66
},
7-
{
8-
"directory": "DIR",
9-
"command": "clang-cl /E /IInputs -Xclang -ivfsoverlay -Xclang DIR/vfsoverlay.yaml -- DIR/vfsoverlay_input_clangcl.cpp",
10-
"file": "DIR/vfsoverlay_input_clangcl.cpp"
11-
}
127
]

clang/test/ClangScanDeps/cl-output.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// This test checks that the output path is correctly deduced/recognized in clang-cl mode.
2+
3+
// RUN: rm -rf %t
4+
// RUN: split-file %s %t
5+
6+
//--- deduce-cdb.json.template
7+
[{
8+
"file": "DIR/test.c",
9+
"directory": "DIR",
10+
"command": "clang --driver-mode=cl /c -- DIR/test.c"
11+
},{
12+
"file": "DIR/test.c",
13+
"directory": "DIR",
14+
"command": "clang-cl /c -- DIR/test.c"
15+
}]
16+
17+
//--- recognize-cdb.json.template
18+
[{
19+
"file": "DIR/test.c",
20+
"directory": "DIR",
21+
"command": "clang-cl /c -o DIR/test.o -- DIR/test.c"
22+
},{
23+
"file": "DIR/test.c",
24+
"directory": "DIR",
25+
"command": "clang-cl /c /o DIR/test.o -- DIR/test.c"
26+
},{
27+
"file": "DIR/test.c",
28+
"directory": "DIR",
29+
"command": "clang-cl /c -oDIR/test.o -- DIR/test.c"
30+
},{
31+
"file": "DIR/test.c",
32+
"directory": "DIR",
33+
"command": "clang-cl /c /oDIR/test.o -- DIR/test.c"
34+
},{
35+
"file": "DIR/test.c",
36+
"directory": "DIR",
37+
"command": "clang-cl /c -FoDIR/test.o -- DIR/test.c"
38+
},{
39+
"file": "DIR/test.c",
40+
"directory": "DIR",
41+
"command": "clang-cl /c /FoDIR/test.o -- DIR/test.c"
42+
}]
43+
44+
//--- last-arg-cdb.json.template
45+
[{
46+
"file": "DIR/test.c",
47+
"directory": "DIR",
48+
"command": "clang-cl /c -o DIR/test.o -o DIR/last.o -- DIR/test.c"
49+
}]
50+
51+
//--- test.c
52+
53+
// Check that missing output path is deduced (with both clang-cl executable and driver mode flag):
54+
//
55+
// RUN: sed -e "s|DIR|%/t|g" %t/deduce-cdb.json.template > %t/deduce-cdb.json
56+
// RUN: clang-scan-deps -compilation-database %t/deduce-cdb.json -j 1 > %t/deduce-result.d
57+
// RUN: cat %t/deduce-result.d | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix=CHECK-DEDUCE
58+
// CHECK-DEDUCE: test.obj:
59+
// CHECK-DEDUCE-NEXT: [[PREFIX]]/test.c
60+
// CHECK-DEDUCE-NEXT: test.obj:
61+
// CHECK-DEDUCE-NEXT: [[PREFIX]]/test.c
62+
63+
// Check that all the different ways to specify output file are recognized:
64+
//
65+
// RUN: sed -e "s|DIR|%/t|g" %t/recognize-cdb.json.template > %t/recognize-cdb.json
66+
// RUN: clang-scan-deps -compilation-database %t/recognize-cdb.json -j 1 > %t/recognize-result.d
67+
// RUN: cat %t/recognize-result.d | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix=CHECK-RECOGNIZE
68+
// CHECK-RECOGNIZE: [[PREFIX]]/test.o:
69+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.c
70+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.o:
71+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.c
72+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.o:
73+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.c
74+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.o:
75+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.c
76+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.o:
77+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.c
78+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.o:
79+
// CHECK-RECOGNIZE-NEXT: [[PREFIX]]/test.c
80+
81+
// Check that the last argument specifying the output path wins.
82+
//
83+
// RUN: sed -e "s|DIR|%/t|g" %t/last-arg-cdb.json.template > %t/last-arg-cdb.json
84+
// RUN: clang-scan-deps -compilation-database %t/last-arg-cdb.json > %t/last-arg-result.d
85+
// RUN: cat %t/last-arg-result.d | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix=CHECK-LAST
86+
// CHECK-LAST: [[PREFIX]]/last.o:
87+
// CHECK-LAST-NEXT: [[PREFIX]]/test.c
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This test checks that the clang-cl compiler is correctly invoked to deduce resource directory.
2+
3+
// REQUIRES: shell
4+
5+
// RUN: rm -rf %t
6+
// RUN: split-file %s %t
7+
8+
//--- cdb.json.template
9+
[{
10+
"file": "DIR/test.c",
11+
"directory": "DIR",
12+
"command": "DIR/clang-cl /c /o DIR/test.o -- DIR/test.c"
13+
}]
14+
15+
//--- clang-cl
16+
#!/bin/sh
17+
18+
# This is a fake compiler that should be invoked the clang-cl way to print the resource directory.
19+
20+
if [ "$1" = "/clang:-print-resource-dir" ]; then
21+
echo "/pass"
22+
else
23+
echo "/fail"
24+
fi;
25+
26+
//--- test.c
27+
28+
// RUN: chmod +x %t/clang-cl
29+
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
30+
// RUN: clang-scan-deps -compilation-database %t/cdb.json --resource-dir-recipe invoke-compiler \
31+
// RUN: --format experimental-full > %t/result.json
32+
// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s
33+
// CHECK: "-resource-dir"
34+
// CHECK-NEXT: "/pass"

clang/test/ClangScanDeps/cl-xclang.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This test checks that '-Xclang' arguments are ignored during the clang-cl command line adjustment.
2+
// This prevents interpreting '-Xclang -I -Xclang /opt/include' as '/o pt/include' (output path).
3+
4+
// RUN: rm -rf %t
5+
// RUN: split-file %s %t
6+
7+
//--- cdb.json.template
8+
[{
9+
"file": "DIR/test.c",
10+
"directory": "DIR",
11+
"command": "clang-cl /c /o DIR/test.o -Xclang -I -Xclang /opt/include -- DIR/test.c"
12+
}]
13+
14+
//--- test.c
15+
16+
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
17+
// RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/result.d
18+
// RUN: cat %t/result.d | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
19+
// CHECK: [[PREFIX]]/test.o:
20+
// CHECK-NEXT: [[PREFIX]]/test.c

clang/test/ClangScanDeps/error.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
// RUN: mkdir -p %t.dir
44
// RUN: cp %s %t.dir/regular_cdb_input.cpp
55
// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/regular_cdb.json > %t.cdb
6-
// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/regular_cdb_clangcl.json > %t_clangcl.cdb
76
//
87
// RUN: not clang-scan-deps -compilation-database %t.cdb -j 1 2>%t.dir/errs
98
// RUN: echo EOF >> %t.dir/errs
109
// RUN: FileCheck %s --input-file %t.dir/errs
1110

12-
// RUN: not clang-scan-deps -compilation-database %t_clangcl.cdb -j 1 2>%t.dir/errs_clangcl
13-
// RUN: echo EOF >> %t.dir/errs_clangcl
14-
// RUN: FileCheck %s --input-file %t.dir/errs_clangcl
15-
1611
#include "missing.h"
1712

1813
// CHECK: Error while scanning dependencies

clang/test/ClangScanDeps/has_include_if_elif.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: rm -rf %t.cdb
33
// RUN: mkdir -p %t.dir
44
// RUN: cp %s %t.dir/has_include_if_elif2.cpp
5-
// RUN: cp %s %t.dir/has_include_if_elif2_clangcl.cpp
65
// RUN: mkdir %t.dir/Inputs
76
// RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
87
// RUN: cp %S/Inputs/header.h %t.dir/Inputs/header2.h
@@ -37,9 +36,3 @@
3736
// CHECK-NEXT: Inputs{{/|\\}}header2.h
3837
// CHECK-NEXT: Inputs{{/|\\}}header3.h
3938
// CHECK-NEXT: Inputs{{/|\\}}header4.h
40-
41-
// CHECK: has_include_if_elif2_clangcl.cpp
42-
// CHECK-NEXT: Inputs{{/|\\}}header.h
43-
// CHECK-NEXT: Inputs{{/|\\}}header2.h
44-
// CHECK-NEXT: Inputs{{/|\\}}header3.h
45-
// CHECK-NEXT: Inputs{{/|\\}}header4.h

clang/test/ClangScanDeps/header_stat_before_open.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: rm -rf %t.cdb
33
// RUN: mkdir -p %t.dir
44
// RUN: cp %s %t.dir/header_stat_before_open_input.m
5-
// RUN: cp %s %t.dir/header_stat_before_open_input_clangcl.m
65
// RUN: mkdir %t.dir/Inputs
76
// RUN: cp -R %S/Inputs/frameworks %t.dir/Inputs/frameworks
87
// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/header_stat_before_open_cdb.json > %t.cdb
@@ -17,8 +16,3 @@
1716
// CHECK-NEXT: header_stat_before_open_input.m
1817
// CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}Headers{{/|\\}}Framework.h
1918
// CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}PrivateHeaders{{/|\\}}PrivateHeader.h
20-
21-
// CHECK: header_stat_before_open_input_clangcl.o
22-
// CHECK-NEXT: header_stat_before_open_input_clangcl.m
23-
// CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}Headers{{/|\\}}Framework.h
24-
// CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}PrivateHeaders{{/|\\}}PrivateHeader.h

clang/test/ClangScanDeps/headerwithdirname.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// RUN: mkdir -p %t.dir
55
// RUN: mkdir -p %t.dir/foodir
66
// RUN: cp %s %t.dir/headerwithdirname_input.cpp
7-
// RUN: cp %s %t.dir/headerwithdirname_input_clangcl.cpp
87
// RUN: mkdir %t.dir/Inputs
98
// RUN: cp %S/Inputs/foodir %t.dir/Inputs/foodir
109
// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/headerwithdirname.json > %t.cdb
@@ -16,7 +15,3 @@
1615
// CHECK: headerwithdirname_input{{\.o|.*\.s}}
1716
// CHECK-NEXT: headerwithdirname_input.cpp
1817
// CHECK-NEXT: Inputs{{/|\\}}foodir
19-
20-
// CHECK: headerwithdirname_input_clangcl.o
21-
// CHECK-NEXT: headerwithdirname_input_clangcl.cpp
22-
// CHECK-NEXT: Inputs{{/|\\}}foodir

0 commit comments

Comments
 (0)