build/docs/preprocessor.rst

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 .. _preprocessor:
michael@0 2
michael@0 3 =================
michael@0 4 Text Preprocessor
michael@0 5 =================
michael@0 6
michael@0 7 The build system contains a text preprocessor similar to the C preprocessor,
michael@0 8 meant for processing files which have no built-in preprocessor such as XUL
michael@0 9 and JavaScript documents. It is implemented at ``python/mozbuild/mozbuild/preprocessor.py`` and
michael@0 10 is typically invoked via :ref:`jar_manifests`.
michael@0 11
michael@0 12 While used to preprocess CSS files, the directives are changed to begin with
michael@0 13 ``%`` instead of ``#`` to avoid conflict of the id selectors.
michael@0 14
michael@0 15 Directives
michael@0 16 ==========
michael@0 17
michael@0 18 Variable Definition
michael@0 19 -------------------
michael@0 20
michael@0 21 define
michael@0 22 ^^^^^^
michael@0 23
michael@0 24 ::
michael@0 25
michael@0 26 #define variable
michael@0 27 #define variable value
michael@0 28
michael@0 29 Defines a preprocessor variable.
michael@0 30
michael@0 31 Note that, unlike the C preprocessor, instances of this variable later in the
michael@0 32 source are not automatically replaced (see #filter). If value is not supplied,
michael@0 33 it defaults to ``1``.
michael@0 34
michael@0 35 Note that whitespace is significant, so ``"#define foo one"`` and
michael@0 36 ``"#define foo one "`` is different (in the second case, ``foo`` is defined to
michael@0 37 be a four-character string).
michael@0 38
michael@0 39 undef
michael@0 40 ^^^^^
michael@0 41
michael@0 42 ::
michael@0 43
michael@0 44 #undef variable
michael@0 45
michael@0 46 Undefines a preprocessor variable.
michael@0 47
michael@0 48 Conditionals
michael@0 49 ------------
michael@0 50
michael@0 51 if
michael@0 52 ^^
michael@0 53
michael@0 54 ::
michael@0 55
michael@0 56 #if variable
michael@0 57 #if !variable
michael@0 58 #if variable==string
michael@0 59 #if variable!=string
michael@0 60
michael@0 61 Disables output if the conditional is false. This can be nested to arbitrary
michael@0 62 depths. Note that in the equality checks, the variable must come first, and
michael@0 63 the comparison operator must not be surrounded by any whitespace.
michael@0 64
michael@0 65 else
michael@0 66 ^^^^
michael@0 67
michael@0 68 ::
michael@0 69
michael@0 70 #else
michael@0 71
michael@0 72 Reverses the state of the previous conditional block; for example, if the
michael@0 73 last ``#if`` was true (output was enabled), an ``#else`` makes it off
michael@0 74 (output gets disabled).
michael@0 75
michael@0 76 .. warning:: An ``#else`` is relative to the last conditional block only,
michael@0 77 unlike the C preprocessor.
michael@0 78
michael@0 79 It does not matter whether any blocks before it were true. This behavior
michael@0 80 changed on trunk (Gecko 1.9) on 2006-12-07; see Bug 277122 for details.
michael@0 81
michael@0 82 ::
michael@0 83
michael@0 84 #if 1
michael@0 85 always included
michael@0 86 #elif 1
michael@0 87 never included
michael@0 88 #else
michael@0 89 always included
michael@0 90 #endif
michael@0 91
michael@0 92 endif
michael@0 93 ^^^^^
michael@0 94
michael@0 95 ::
michael@0 96
michael@0 97 #endif
michael@0 98
michael@0 99 Ends the conditional block.
michael@0 100
michael@0 101 ifdef / ifndef
michael@0 102 ^^^^^^^^^^^^^^
michael@0 103
michael@0 104 ::
michael@0 105
michael@0 106 #ifdef variable
michael@0 107 #ifndef variable
michael@0 108
michael@0 109 An ``#if`` conditional that is true only if the preprocessor variable
michael@0 110 variable is defined (in the case of ``ifdef``) or not defined (``ifndef``).
michael@0 111
michael@0 112 elif / elifdef / elifndef
michael@0 113 ^^^^^^^^^^^^^^^^^^^^^^^^^
michael@0 114
michael@0 115 ::
michael@0 116
michael@0 117 #elif variable
michael@0 118 #elif !variable
michael@0 119 #elif variable == string
michael@0 120 #elif variable != string
michael@0 121 #elifdef variable
michael@0 122 #elifndef variable
michael@0 123
michael@0 124 A shorthand to mean an ``#else`` combined with the relevant conditional.
michael@0 125 The following two blocks are equivalent::
michael@0 126
michael@0 127 #ifdef foo
michael@0 128 block 1
michael@0 129 #elifdef bar
michael@0 130 block 2
michael@0 131 #endif
michael@0 132
michael@0 133 ::
michael@0 134
michael@0 135 #ifdef foo
michael@0 136 block 1
michael@0 137 #else
michael@0 138 #ifdef bar
michael@0 139 block 2
michael@0 140 #endif
michael@0 141 #endif
michael@0 142
michael@0 143 .. warning:: An ``#elif``, ``#elifdef``, or ``#elifndef`` is relative to
michael@0 144 the last conditional block only (as well as the condition it implies),
michael@0 145 unlike the C preprocessor. It does not matter whether any blocks before
michael@0 146 it were true. This behavior changed on trunk (Gecko 1.9) on 2006-12-07.
michael@0 147 See Bug 277122 for details.
michael@0 148
michael@0 149 File Inclusion
michael@0 150 --------------
michael@0 151
michael@0 152 include
michael@0 153 ^^^^^^^
michael@0 154
michael@0 155 ::
michael@0 156
michael@0 157 #include filename
michael@0 158
michael@0 159 The file specified by filename is processed as if the contents was placed
michael@0 160 at this position. This also means that preprocessor conditionals can even
michael@0 161 be started in one file and ended in another (but is highly discouraged).
michael@0 162 There is no limit on depth of inclusion, or repeated inclusion of the same
michael@0 163 file, or self inclusion; thus, care should be taken to avoid infinite loops.
michael@0 164
michael@0 165 includesubst
michael@0 166 ^^^^^^^^^^^^
michael@0 167
michael@0 168 ::
michael@0 169
michael@0 170 #includesubst @variable@filename
michael@0 171
michael@0 172 Same as a ``#include`` except that all instances of variable in the included
michael@0 173 file is also expanded as in ``#filter`` substitution
michael@0 174
michael@0 175 expand
michael@0 176 ^^^^^^
michael@0 177
michael@0 178 ::
michael@0 179
michael@0 180 #expand string
michael@0 181
michael@0 182 All variables wrapped in ``__`` are replaced with their value, for this line
michael@0 183 only. If the variable is not defined, it expands to an empty string. For
michael@0 184 example, if ``foo`` has the value ``bar``, and ``baz`` is not defined, then::
michael@0 185
michael@0 186 #expand This <__foo__> <__baz__> gets expanded
michael@0 187
michael@0 188 Is expanded to::
michael@0 189
michael@0 190 This <bar> <> gets expanded
michael@0 191
michael@0 192 filter / unfilter
michael@0 193 ^^^^^^^^^^^^^^^^^
michael@0 194
michael@0 195 ::
michael@0 196
michael@0 197 #filter filter1 filter2 ... filterN
michael@0 198 #unfilter filter1 filter2 ... filterN
michael@0 199
michael@0 200 ``#filter`` turns on the given filter.
michael@0 201
michael@0 202 Filters are run in alphabetical order on a per-line basis.
michael@0 203
michael@0 204 ``#unfilter`` turns off the given filter. Available filters are:
michael@0 205
michael@0 206 emptyLines
michael@0 207 strips blank lines from the output
michael@0 208 slashslash
michael@0 209 strips everything from the first two consecutive slash (``/``)
michael@0 210 characters until the end of the line
michael@0 211 spaces
michael@0 212 collapses consecutive sequences of spaces into a single space,
michael@0 213 and strips leading and trailing spaces
michael@0 214 substitution
michael@0 215 all variables wrapped in @ are replaced with their value. If the
michael@0 216 variable is not defined, it is a fatal error. Similar to ``#expand``
michael@0 217 and ``#filter``
michael@0 218 attemptSubstitution
michael@0 219 all variables wrapped in ``@`` are replaced with their value, or an
michael@0 220 empty string if the variable is not defined. Similar to ``#expand``.
michael@0 221
michael@0 222 literal
michael@0 223 ^^^^^^^
michael@0 224
michael@0 225 ::
michael@0 226
michael@0 227 #literal string
michael@0 228
michael@0 229 Output the string (i.e. the rest of the line) literally, with no other fixups.
michael@0 230 This is useful to output lines starting with ``#``, or to temporarily
michael@0 231 disable filters.
michael@0 232
michael@0 233 Other
michael@0 234 -----
michael@0 235
michael@0 236 #error
michael@0 237 ^^^^^^
michael@0 238
michael@0 239 ::
michael@0 240
michael@0 241 #error string
michael@0 242
michael@0 243 Cause a fatal error at this point, with the error message being the
michael@0 244 given string.

mercurial