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.

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

mercurial