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.

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

mercurial