config/make-stl-wrappers.py

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 # This Source Code Form is subject to the terms of the Mozilla Public
     2 # License, v. 2.0. If a copy of the MPL was not distributed with this
     3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4 from __future__ import print_function
     5 import os, re, string, sys
     6 from mozbuild.util import FileAvoidWrite
     8 def find_in_path(file, searchpath):
     9     for dir in searchpath.split(os.pathsep):
    10         f = os.path.join(dir, file)
    11         if os.path.exists(f):
    12             return f
    13     return ''
    15 def header_path(header, compiler):
    16     if compiler == 'gcc':
    17         # we use include_next on gcc
    18         return header
    19     elif compiler == 'msvc':
    20         return find_in_path(header, os.environ.get('INCLUDE', ''))
    21     else:
    22         # hope someone notices this ...
    23         raise NotImplementedError(compiler)
    25 def is_comment(line):
    26     return re.match(r'\s*#.*', line)
    28 def main(outdir, compiler, template_file, header_list_file):
    29     if not os.path.isdir(outdir):
    30         os.mkdir(outdir)
    32     template = open(template_file, 'r').read()
    33     path_to_new = header_path('new', compiler)
    35     for header in open(header_list_file, 'r'):
    36         header = header.rstrip()
    37         if 0 == len(header) or is_comment(header):
    38             continue
    40         path = header_path(header, compiler)
    41         with FileAvoidWrite(os.path.join(outdir, header)) as f:
    42             f.write(string.Template(template).substitute(HEADER=header,
    43                                                          HEADER_PATH=path,
    44                                                          NEW_HEADER_PATH=path_to_new))
    47 if __name__ == '__main__':
    48     if 5 != len(sys.argv):
    49         print("""Usage:
    50   python {0} OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
    51 """.format(sys.argv[0]), file=sys.stderr)
    52         sys.exit(1)
    54     main(*sys.argv[1:])

mercurial