|
| 1 | +// Ensure all files references by a cached module can be found. |
| 2 | + |
| 3 | +// REQUIRES: ondisk_cas |
| 4 | + |
| 5 | +// RUN: rm -rf %t |
| 6 | +// RUN: split-file %s %t |
| 7 | +// RUN: sed "s|DIR|%/t|g" %t/cdb_pch.json.template > %t/cdb_pch.json |
| 8 | +// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json |
| 9 | + |
| 10 | +// == Scan PCH |
| 11 | +// RUN: clang-scan-deps -compilation-database %t/cdb_pch.json \ |
| 12 | +// RUN: -cas-path %t/cas -action-cache-path %t/cache -module-files-dir %t/outputs \ |
| 13 | +// RUN: -format experimental-full -mode preprocess-dependency-directives \ |
| 14 | +// RUN: > %t/deps_pch.json |
| 15 | + |
| 16 | +// == Build PCH |
| 17 | +// RUN: %deps-to-rsp %t/deps_pch.json --module-name A > %t/A.rsp |
| 18 | +// RUN: %deps-to-rsp %t/deps_pch.json --tu-index 0 > %t/pch.rsp |
| 19 | + |
| 20 | +// RUN: %clang @%t/A.rsp |
| 21 | +// RUN: %clang @%t/pch.rsp |
| 22 | + |
| 23 | +// == Scan TU, including PCH |
| 24 | +// RUN: clang-scan-deps -compilation-database %t/cdb.json \ |
| 25 | +// RUN: -cas-path %t/cas -action-cache-path %t/cache -module-files-dir %t/outputs \ |
| 26 | +// RUN: -format experimental-full -mode preprocess-dependency-directives \ |
| 27 | +// RUN: > %t/deps.json |
| 28 | + |
| 29 | +// == Build TU, including PCH |
| 30 | +// RUN: %deps-to-rsp %t/deps.json --module-name C > %t/C.rsp |
| 31 | +// RUN: %deps-to-rsp %t/deps.json --tu-index 0 > %t/tu.rsp |
| 32 | + |
| 33 | +// RUN: %clang @%t/C.rsp |
| 34 | +// RUN: %clang @%t/tu.rsp |
| 35 | + |
| 36 | +//--- cdb_pch.json.template |
| 37 | +[ |
| 38 | + { |
| 39 | + "directory" : "DIR", |
| 40 | + "command" : "clang_tool -I DIR -x c-header DIR/prefix.h -o DIR/prefix.h.pch -fmodules -fimplicit-modules -fimplicit-module-maps -fmodules-cache-path=DIR/module-cache -Rcompile-job-cache", |
| 41 | + "file" : "DIR/prefix.h" |
| 42 | + }, |
| 43 | +] |
| 44 | + |
| 45 | +//--- cdb.json.template |
| 46 | +[ |
| 47 | + { |
| 48 | + "directory" : "DIR", |
| 49 | + "command" : "clang_tool -I DIR -fsyntax-only DIR/tu.c -include DIR/prefix.h -fmodules -fimplicit-modules -fimplicit-module-maps -fmodules-cache-path=DIR/module-cache -Rcompile-job-cache", |
| 50 | + "file" : "DIR/tu.c" |
| 51 | + }, |
| 52 | +] |
| 53 | + |
| 54 | +// The test below is a specific instance that was failing in the past. The test |
| 55 | +// complexity is required to trigger looking up an input file of a module that |
| 56 | +// would not be automatically visited when importing that module during |
| 57 | +// dependency scanning, because it is only triggered incidentally. The anatomy |
| 58 | +// of the specific test case is: |
| 59 | +// * module A has a reference to B's modulemap but does not import B |
| 60 | +// because it was for an excluded header |
| 61 | +// * module C imports A and performs macro expansion of module_macro |
| 62 | +// * looking up the location for the macro definition does binary search and |
| 63 | +// incidentally deserializes the SLocEntry for B's modulemap. With small |
| 64 | +// modules such as in this test case, the binary search is *likely* to hit |
| 65 | +// that specific SLocEntry, and it did at the time this test was written. |
| 66 | +// * module A must be "prebuilt"; otherwise the scanner will visit all inputs |
| 67 | +// during implicit module validation; so we load it via PCH. |
| 68 | + |
| 69 | +//--- A/module.modulemap |
| 70 | +module A { header "A.h" } |
| 71 | + |
| 72 | +//--- A/A.h |
| 73 | +#include "B/B.h" |
| 74 | +#define module_macro int |
| 75 | + |
| 76 | +//--- B/module.modulemap |
| 77 | +module B { exclude header "B.h" } |
| 78 | + |
| 79 | +//--- B/B.h |
| 80 | + |
| 81 | +//--- module.modulemap |
| 82 | +module C { header "C.h" } |
| 83 | + |
| 84 | +//--- C.h |
| 85 | +#include "A/A.h" |
| 86 | +module_macro x; |
| 87 | + |
| 88 | +//--- prefix.h |
| 89 | +#include "A/A.h" |
| 90 | + |
| 91 | +//--- tu.c |
| 92 | +#include "C.h" |
0 commit comments