| 1 |
// This test verifies that the modules visible to the translation unit are computed in dependency scanning. |
| 2 |
// "client" in the first scan represents the translation unit that imports an explicit submodule, |
| 3 |
// that only exports one other module. |
| 4 |
// In the second scan, the translation unit that imports an explicit submodule, |
| 5 |
// that exports an additional module. |
| 6 |
// Thus, the dependencies of the top level module for the submodule always differ from what is visible to the TU. |
| 7 |
|
| 8 |
// RUN: rm -rf %t |
| 9 |
// RUN: split-file %s %t |
| 10 |
// RUN: sed -e "s|DIR|%/t|g" %t/compile-commands.json.in > %t/compile-commands.json |
| 11 |
// RUN: clang-scan-deps -emit-visible-modules -compilation-database %t/compile-commands.json \ |
| 12 |
// RUN: -j 1 -format experimental-full 2>&1 > %t/result-first-scan.json |
| 13 |
// RUN: cat %t/result-first-scan.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix=SINGLE |
| 14 |
|
| 15 |
/// Re-run scan with different module map for direct dependency. |
| 16 |
// RUN: mv %t/A_with_visible_export.modulemap %t/Sysroot/usr/include/A/module.modulemap |
| 17 |
// RUN: clang-scan-deps -emit-visible-modules -compilation-database %t/compile-commands.json \ |
| 18 |
// RUN: -j 1 -format experimental-full 2>&1 > %t/result.json |
| 19 |
// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix=MULTIPLE |
| 20 |
|
| 21 |
// RUN: %deps-to-rsp %t/result.json --module-name=transitive > %t/transitive.rsp |
| 22 |
// RUN: %deps-to-rsp %t/result.json --module-name=visible > %t/visible.rsp |
| 23 |
// RUN: %deps-to-rsp %t/result.json --module-name=invisible > %t/invisible.rsp |
| 24 |
// RUN: %deps-to-rsp %t/result.json --module-name=A > %t/A.rsp |
| 25 |
// RUN: %deps-to-rsp %t/result.json --tu-index=0 > %t/tu.rsp |
| 26 |
|
| 27 |
// RUN: %clang @%t/transitive.rsp |
| 28 |
// RUN: %clang @%t/visible.rsp |
| 29 |
// RUN: %clang @%t/invisible.rsp |
| 30 |
// RUN: %clang @%t/A.rsp |
| 31 |
|
| 32 |
/// Verify compilation & scan agree with each other. |
| 33 |
// RUN: not %clang @%t/tu.rsp -o %t/blah.o 2>&1 | FileCheck %s --check-prefix=COMPILE |
| 34 |
|
| 35 |
// SINGLE: "visible-clang-modules": [ |
| 36 |
// SINGLE-NEXT: "A" |
| 37 |
// SINGLE-NEXT: ] |
| 38 |
|
| 39 |
// MULTIPLE: "visible-clang-modules": [ |
| 40 |
// MULTIPLE-NEXT: "A", |
| 41 |
// MULTIPLE-NEXT: "visible" |
| 42 |
// MULTIPLE-NEXT: ] |
| 43 |
|
| 44 |
// COMPILE-NOT: 'visible_t' must be declared before it is used |
| 45 |
// COMPILE: 'transitive_t' must be declared before it is used |
| 46 |
// COMPILE: 'invisible_t' must be declared before it is used |
| 47 |
|
| 48 |
//--- compile-commands.json.in |
| 49 |
[ |
| 50 |
{ |
| 51 |
"directory": "DIR", |
| 52 |
"command": "clang -c DIR/client.c -isysroot DIR/Sysroot -IDIR/Sysroot/usr/include -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps", |
| 53 |
"file": "DIR/client.c" |
| 54 |
} |
| 55 |
] |
| 56 |
|
| 57 |
//--- Sysroot/usr/include/A/module.modulemap |
| 58 |
module A { |
| 59 |
explicit module visibleToTU { |
| 60 |
header "visibleToTU.h" |
| 61 |
} |
| 62 |
explicit module invisibleToTU { |
| 63 |
header "invisibleToTU.h" |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
//--- A_with_visible_export.modulemap |
| 68 |
module A { |
| 69 |
explicit module visibleToTU { |
| 70 |
header "visibleToTU.h" |
| 71 |
export visible |
| 72 |
} |
| 73 |
explicit module invisibleToTU { |
| 74 |
header "invisibleToTU.h" |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
//--- Sysroot/usr/include/A/visibleToTU.h |
| 79 |
#include <visible/visible.h> |
| 80 |
typedef int A_visibleToTU; |
| 81 |
|
| 82 |
//--- Sysroot/usr/include/A/invisibleToTU.h |
| 83 |
#include <invisible/invisible.h> |
| 84 |
typedef int A_invisibleToTU; |
| 85 |
|
| 86 |
//--- Sysroot/usr/include/invisible/module.modulemap |
| 87 |
module invisible { |
| 88 |
umbrella "." |
| 89 |
} |
| 90 |
|
| 91 |
//--- Sysroot/usr/include/invisible/invisible.h |
| 92 |
typedef int invisible_t; |
| 93 |
|
| 94 |
//--- Sysroot/usr/include/visible/module.modulemap |
| 95 |
module visible { |
| 96 |
umbrella "." |
| 97 |
} |
| 98 |
|
| 99 |
//--- Sysroot/usr/include/visible/visible.h |
| 100 |
#include <transitive/transitive.h> |
| 101 |
typedef int visible_t; |
| 102 |
|
| 103 |
//--- Sysroot/usr/include/transitive/module.modulemap |
| 104 |
module transitive { |
| 105 |
umbrella "." |
| 106 |
} |
| 107 |
|
| 108 |
//--- Sysroot/usr/include/transitive/transitive.h |
| 109 |
typedef int transitive_t; |
| 110 |
|
| 111 |
//--- client.c |
| 112 |
#include <A/visibleToTU.h> |
| 113 |
visible_t foo_v(void); |
| 114 |
// Both decls are not visible, thus should fail to actually compile. |
| 115 |
transitive_t foo_t(void); |
| 116 |
invisible_t foo_i(void); |