| // RUN: rm -rf %t |
| // RUN: split-file %s %t |
| // RUN: %clang_cc1 -fimplicit-module-maps -fmodules-cache-path=%t -fmodules-strict-decluse -fmodule-name=lib_Private -I %t %t/lib.cpp -verify |
| |
| //--- module.modulemap |
| // This simulates a modulemap that might reasonably be generated by a build system for something resembling the following. |
| // This can be used to perform strict dependency checking to ensure that your build graph is correctly declared. |
| // cc_library( |
| // name = "lib", |
| // # .cpp file in sources -> generate a compilation action with -fmodule-name=lib_Private |
| // # .h file in sources -> "textual header" in private modulemap |
| // sources = ["lib.cpp"], |
| // # headers -> "textual header" in public modulemap |
| // headers = ["lib.h"], |
| // # implementation_dep -> "use" in private modulemap |
| // implementation_deps = [":impl_dep"] |
| // # dep -> "use" in private and public modulemap |
| // deps = [":direct"], |
| // ) |
| // cc_library(name = "direct", headers = ["direct.h"], deps = [":indirect"], ...) |
| // cc_library(name = "indirect", headers = ["indirect.h"], ..) |
| // cc_library(name = "impl_dep", headers = ["impl_dep.h"], ...) |
| module lib_Private { |
| use impl_dep |
| use lib |
| use direct |
| } |
| |
| module lib { |
| textual header "lib.h" |
| use direct |
| } |
| |
| |
| module impl_dep { |
| textual header "impl_dep.h" |
| } |
| |
| module direct { |
| textual header "direct.h" |
| use indirect |
| } |
| |
| module indirect { |
| textual header "indirect.h" |
| } |
| |
| //--- impl_dep.h |
| void impl_dep(); |
| //--- direct.h |
| #include "impl_dep.h" // OK (it should only verify the main module). |
| void direct(); |
| //--- indirect.h |
| void indirect(); |
| //--- not_module.h |
| void not_module(); |
| |
| //--- lib.cpp |
| #include "lib.h" |
| #include "direct.h" // OK |
| #include "indirect.h" // expected-error {{module lib_Private does not directly depend on a module exporting 'indirect.h', which is part of indirectly-used module indirect}} |
| #include "impl_dep.h" // OK |
| #include "not_module.h" // expected-error {{module lib_Private does not depend on a module exporting 'not_module.h'}} |
| |
| //--- lib.h |
| #include "direct.h" // OK |
| #include "indirect.h" // expected-error {{module lib does not directly depend on a module exporting 'indirect.h', which is part of indirectly-used module indirect}} |
| #include "impl_dep.h" // expected-error {{module lib does not depend on a module exporting 'impl_dep.h', which is part of module impl_dep, although its private module does}} |
| #include "not_module.h" // expected-error {{module lib does not depend on a module exporting 'not_module.h'}} |