John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 1 | .. index:: modularize |
| 2 | |
| 3 | ================================== |
| 4 | Modularize User's Manual |
| 5 | ================================== |
| 6 | |
| 7 | .. toctree:: |
| 8 | :hidden: |
| 9 | |
| 10 | ModularizeUsage |
| 11 | |
| 12 | :program:`modularize` is a standalone tool that checks whether a set of headers |
| 13 | provides the consistent definitions required to use modules. For example, it |
| 14 | detects whether the same entity (say, a NULL macro or size_t typedef) is |
| 15 | defined in multiple headers or whether a header produces different definitions |
| 16 | under different circumstances. These conditions cause modules built from the |
| 17 | headers to behave poorly, and should be fixed before introducing a module |
| 18 | map. |
| 19 | |
John Thompson | 26ecaf9 | 2013-10-16 13:44:21 +0000 | [diff] [blame] | 20 | :program:`modularize` also has an assistant mode option for generating |
| 21 | a module map file based on the provided header list. The generated file |
| 22 | is a functional module map that can be used as a starting point for a |
| 23 | module.map file. |
| 24 | |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 25 | Getting Started |
| 26 | =============== |
| 27 | |
| 28 | To build from source: |
| 29 | |
| 30 | 1. Read `Getting Started with the LLVM System`_ and `Clang Tools |
| 31 | Documentation`_ for information on getting sources for LLVM, Clang, and |
| 32 | Clang Extra Tools. |
| 33 | |
| 34 | 2. `Getting Started with the LLVM System`_ and `Building LLVM with CMake`_ give |
| 35 | directions for how to build. With sources all checked out into the |
| 36 | right place the LLVM build will build Clang Extra Tools and their |
| 37 | dependencies automatically. |
| 38 | |
| 39 | * If using CMake, you can also use the ``modularize`` target to build |
| 40 | just the modularize tool and its dependencies. |
| 41 | |
| 42 | Before continuing, take a look at :doc:`ModularizeUsage` to see how to invoke |
| 43 | modularize. |
| 44 | |
| 45 | .. _Getting Started with the LLVM System: http://llvm.org/docs/GettingStarted.html |
| 46 | .. _Building LLVM with CMake: http://llvm.org/docs/CMake.html |
| 47 | .. _Clang Tools Documentation: http://clang.llvm.org/docs/ClangTools.html |
| 48 | |
| 49 | What Modularize Checks |
| 50 | ====================== |
| 51 | |
John Thompson | 587f6db | 2013-09-20 16:47:33 +0000 | [diff] [blame] | 52 | Modularize will check for the following: |
| 53 | |
| 54 | * Duplicate global type and variable definitions |
| 55 | * Duplicate macro definitions |
| 56 | * Macro instances, 'defined(macro)', or #if, #elif, #ifdef, #ifndef conditions |
| 57 | that evaluate differently in a header |
| 58 | * #include directives inside 'extern "C/C++" {}' or 'namespace (name) {}' blocks |
| 59 | |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 60 | Modularize will do normal C/C++ parsing, reporting normal errors and warnings, |
John Thompson | 8925d46 | 2013-09-23 14:17:27 +0000 | [diff] [blame] | 61 | but will also report special error messages like the following:: |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 62 | |
John Thompson | 8925d46 | 2013-09-23 14:17:27 +0000 | [diff] [blame] | 63 | error: '(symbol)' defined at multiple locations: |
| 64 | (file):(row):(column) |
| 65 | (file):(row):(column) |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 66 | |
John Thompson | 8925d46 | 2013-09-23 14:17:27 +0000 | [diff] [blame] | 67 | error: header '(file)' has different contents depending on how it was included |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 68 | |
John Thompson | 8925d46 | 2013-09-23 14:17:27 +0000 | [diff] [blame] | 69 | The latter might be followed by messages like the following:: |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 70 | |
John Thompson | 8925d46 | 2013-09-23 14:17:27 +0000 | [diff] [blame] | 71 | note: '(symbol)' in (file) at (row):(column) not always provided |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 72 | |
| 73 | Checks will also be performed for macro expansions, defined(macro) |
| 74 | expressions, and preprocessor conditional directives that evaluate |
John Thompson | 8925d46 | 2013-09-23 14:17:27 +0000 | [diff] [blame] | 75 | inconsistently, and can produce error messages like the following:: |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 76 | |
John Thompson | 8925d46 | 2013-09-23 14:17:27 +0000 | [diff] [blame] | 77 | (...)/SubHeader.h:11:5: |
| 78 | #if SYMBOL == 1 |
| 79 | ^ |
| 80 | error: Macro instance 'SYMBOL' has different values in this header, |
| 81 | depending on how it was included. |
| 82 | 'SYMBOL' expanded to: '1' with respect to these inclusion paths: |
| 83 | (...)/Header1.h |
| 84 | (...)/SubHeader.h |
| 85 | (...)/SubHeader.h:3:9: |
| 86 | #define SYMBOL 1 |
| 87 | ^ |
| 88 | Macro defined here. |
| 89 | 'SYMBOL' expanded to: '2' with respect to these inclusion paths: |
| 90 | (...)/Header2.h |
| 91 | (...)/SubHeader.h |
| 92 | (...)/SubHeader.h:7:9: |
| 93 | #define SYMBOL 2 |
| 94 | ^ |
| 95 | Macro defined here. |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 96 | |
| 97 | Checks will also be performed for '#include' directives that are |
| 98 | nested inside 'extern "C/C++" {}' or 'namespace (name) {}' blocks, |
John Thompson | 8925d46 | 2013-09-23 14:17:27 +0000 | [diff] [blame] | 99 | and can produce error message like the following:: |
John Thompson | 2d2d45e | 2013-09-20 14:40:52 +0000 | [diff] [blame] | 100 | |
John Thompson | 8925d46 | 2013-09-23 14:17:27 +0000 | [diff] [blame] | 101 | IncludeInExtern.h:2:3: |
| 102 | #include "Empty.h" |
| 103 | ^ |
| 104 | error: Include directive within extern "C" {}. |
| 105 | IncludeInExtern.h:1:1: |
| 106 | extern "C" { |
| 107 | ^ |
| 108 | The "extern "C" {}" block is here. |
John Thompson | 26ecaf9 | 2013-10-16 13:44:21 +0000 | [diff] [blame] | 109 | |
| 110 | .. _module-map-generation: |
| 111 | |
| 112 | Module Map Generation |
| 113 | ===================== |
| 114 | |
| 115 | If you specify the ``-module-map-path=<module map file>``, |
| 116 | :program:`modularize` will output a module map based on the input header list. |
| 117 | A module will be created for each header. Also, if the header in the header |
| 118 | list is a partial path, a nested module hierarchy will be created in which a |
| 119 | module will be created for each subdirectory component in the header path, |
| 120 | with the header itself represented by the innermost module. If other headers |
| 121 | use the same subdirectories, they will be enclosed in these same modules also. |
| 122 | |
| 123 | For example, for the header list:: |
| 124 | |
| 125 | SomeTypes.h |
| 126 | SomeDecls.h |
| 127 | SubModule1/Header1.h |
| 128 | SubModule1/Header2.h |
| 129 | SubModule2/Header3.h |
| 130 | SubModule2/Header4.h |
| 131 | SubModule2.h |
| 132 | |
| 133 | The following module map will be generated:: |
| 134 | |
| 135 | // Output/NoProblemsAssistant.txt
|
| 136 | // Generated by: modularize -module-map-path=Output/NoProblemsAssistant.txt \ |
| 137 | -root-module=Root NoProblemsAssistant.modularize
|
| 138 |
|
| 139 | module SomeTypes {
|
| 140 | header "SomeTypes.h"
|
| 141 | export *
|
| 142 | }
|
| 143 | module SomeDecls {
|
| 144 | header "SomeDecls.h"
|
| 145 | export *
|
| 146 | }
|
| 147 | module SubModule1 {
|
| 148 | module Header1 {
|
| 149 | header "SubModule1/Header1.h"
|
| 150 | export *
|
| 151 | }
|
| 152 | module Header2 {
|
| 153 | header "SubModule1/Header2.h"
|
| 154 | export *
|
| 155 | }
|
| 156 | }
|
| 157 | module SubModule2 {
|
| 158 | module Header3 {
|
| 159 | header "SubModule2/Header3.h"
|
| 160 | export *
|
| 161 | }
|
| 162 | module Header4 {
|
| 163 | header "SubModule2/Header4.h"
|
| 164 | export *
|
| 165 | }
|
| 166 | header "SubModule2.h"
|
| 167 | export *
|
| 168 | }
|
| 169 | |
| 170 | An optional ``-root-module=<root-name>`` option can be used to cause a root module |
| 171 | to be created which encloses all the modules. |
| 172 | |
| 173 | For example, with the same header list from above:: |
| 174 | |
| 175 | // Output/NoProblemsAssistant.txt
|
| 176 | // Generated by: modularize -module-map-path=Output/NoProblemsAssistant.txt \ |
| 177 | -root-module=Root NoProblemsAssistant.modularize
|
| 178 |
|
| 179 | module Root {
|
| 180 | module SomeTypes {
|
| 181 | header "SomeTypes.h"
|
| 182 | export *
|
| 183 | }
|
| 184 | module SomeDecls {
|
| 185 | header "SomeDecls.h"
|
| 186 | export *
|
| 187 | }
|
| 188 | module SubModule1 {
|
| 189 | module Header1 {
|
| 190 | header "SubModule1/Header1.h"
|
| 191 | export *
|
| 192 | }
|
| 193 | module Header2 {
|
| 194 | header "SubModule1/Header2.h"
|
| 195 | export *
|
| 196 | }
|
| 197 | }
|
| 198 | module SubModule2 {
|
| 199 | module Header3 {
|
| 200 | header "SubModule2/Header3.h"
|
| 201 | export *
|
| 202 | }
|
| 203 | module Header4 {
|
| 204 | header "SubModule2/Header4.h"
|
| 205 | export *
|
| 206 | }
|
| 207 | header "SubModule2.h"
|
| 208 | export *
|
| 209 | }
|
| 210 | }
|
| 211 |
|
| 212 | Note that headers with dependents will be ignored with a warning, as the
|
| 213 | Clang module mechanism doesn't support headers the rely on other headers
|
| 214 | to be included first.
|
| 215 |
|
| 216 | The module map format defines some keywords which can't be used in module
|
| 217 | names. If a header has one of these names, an underscore ('_') will be
|
| 218 | prepended to the name. For example, if the header name is ``header.h``, |
| 219 | because ``header`` is a keyword, the module name will be ``_header``. |
| 220 | For a list of the module map keywords, please see: |
| 221 | `Lexical structure <http://clang.llvm.org/docs/Modules.html#lexical-structure>`_
|