1 // RUN: rm -rf %t && mkdir %t
2 // RUN: cp -r %S/Inputs/modules-context-hash/* %t
4 // Check that the scanner reports the same module as distinct dependencies when
5 // a single translation unit gets compiled with multiple command-lines that
6 // produce different **strict** context hashes.
8 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_a.json.template > %t/cdb_a.json
9 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_b.json.template > %t/cdb_b.json
10 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_b2.json.template > %t/cdb_b2.json
12 // We run separate scans. The context hash for "a" and "b" can differ between
13 // systems. If we'd scan both Clang invocations in a single run, the order of JSON
14 // entities would be non-deterministic. To prevent this, run the scans separately
15 // and verify that the context hashes differ with a single FileCheck invocation.
17 // RUN: clang-scan-deps -compilation-database %t/cdb_a.json -format experimental-full -j 1 > %t/result_a.json
18 // RUN: clang-scan-deps -compilation-database %t/cdb_b.json -format experimental-full -j 1 > %t/result_b.json
19 // RUN: clang-scan-deps -compilation-database %t/cdb_b2.json -format experimental-full -j 1 > %t/result_b2.json
20 // RUN: cat %t/result_a.json %t/result_b.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK
21 // RUN: cat %t/result_b.json %t/result_b2.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=FLAG_ONLY
24 // CHECK-NEXT: "modules": [
26 // CHECK-NEXT: "clang-module-deps": [],
27 // CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
28 // CHECK-NEXT: "command-line": [
30 // CHECK: "-emit-module"
32 // CHECK: "[[PREFIX]]/a"
33 // CHECK: "-fmodule-name=mod"
35 // CHECK-NEXT: "context-hash": "[[HASH_MOD_A:.*]]",
36 // CHECK-NEXT: "file-deps": [
37 // CHECK-NEXT: "[[PREFIX]]/a/dep.h",
38 // CHECK-NEXT: "[[PREFIX]]/mod.h",
39 // CHECK-NEXT: "[[PREFIX]]/module.modulemap"
41 // CHECK-NEXT: "name": "mod"
44 // CHECK-NEXT: "translation-units": [
46 // CHECK: "clang-context-hash": "{{.*}}",
47 // CHECK-NEXT: "clang-module-deps": [
49 // CHECK-NEXT: "context-hash": "[[HASH_MOD_A]]",
50 // CHECK-NEXT: "module-name": "mod"
53 // CHECK-NEXT: "command-line": [
55 // CHECK: "file-deps": [
56 // CHECK-NEXT: "[[PREFIX]]/tu.c"
58 // CHECK-NEXT: "input-file": "[[PREFIX]]/tu.c"
61 // CHECK: "modules": [
63 // CHECK-NEXT: "clang-module-deps": [],
64 // CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
65 // CHECK-NEXT: "command-line": [
67 // CHECK: "-emit-module"
69 // CHECK: "[[PREFIX]]/b"
70 // CHECK: "-fmodule-name=mod"
72 // CHECK-NOT: "context-hash": "[[HASH_MOD_A]]",
73 // CHECK: "file-deps": [
74 // CHECK-NEXT: "[[PREFIX]]/b/dep.h",
75 // CHECK-NEXT: "[[PREFIX]]/mod.h",
76 // CHECK-NEXT: "[[PREFIX]]/module.modulemap"
78 // CHECK-NEXT: "name": "mod"
81 // CHECK-NEXT: "translation-units": [
83 // CHECK: "clang-context-hash": "{{.*}}",
84 // CHECK-NEXT: "clang-module-deps": [
86 // CHECK-NOT: "context-hash": "[[HASH_MOD_A]]",
87 // CHECK: "module-name": "mod"
90 // CHECK-NEXT: "command-line": [
92 // CHECK: "file-deps": [
93 // CHECK-NEXT: "[[PREFIX]]/tu.c"
95 // CHECK-NEXT: "input-file": "[[PREFIX]]/tu.c"
98 // B and B2 only differ by -fapplication-extension
100 // FLAG_ONLY: "modules": [
102 // FLAG_ONLY: "context-hash": "[[HASH_MOD_B1:.*]]"
103 // FLAG_ONLY-NOT: "-fapplication-extension"
105 // FLAG_ONLY: "modules": [
107 // FLAG_ONLY-NOT: "context-hash": "[[HASH_MOD_B1]]"
108 // FLAG_ONLY: "-fapplication-extension"
109 // FLAG_ONLY: "translation-units": [
110 // FLAG_ONLY-NOT: "context-hash": "[[HASH_MOD_B1]]"