config/make-stl-wrappers.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/config/make-stl-wrappers.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +from __future__ import print_function
     1.8 +import os, re, string, sys
     1.9 +from mozbuild.util import FileAvoidWrite
    1.10 +
    1.11 +def find_in_path(file, searchpath):
    1.12 +    for dir in searchpath.split(os.pathsep):
    1.13 +        f = os.path.join(dir, file)
    1.14 +        if os.path.exists(f):
    1.15 +            return f
    1.16 +    return ''
    1.17 +
    1.18 +def header_path(header, compiler):
    1.19 +    if compiler == 'gcc':
    1.20 +        # we use include_next on gcc
    1.21 +        return header
    1.22 +    elif compiler == 'msvc':
    1.23 +        return find_in_path(header, os.environ.get('INCLUDE', ''))
    1.24 +    else:
    1.25 +        # hope someone notices this ...
    1.26 +        raise NotImplementedError(compiler)
    1.27 +
    1.28 +def is_comment(line):
    1.29 +    return re.match(r'\s*#.*', line)
    1.30 +
    1.31 +def main(outdir, compiler, template_file, header_list_file):
    1.32 +    if not os.path.isdir(outdir):
    1.33 +        os.mkdir(outdir)
    1.34 +
    1.35 +    template = open(template_file, 'r').read()
    1.36 +    path_to_new = header_path('new', compiler)
    1.37 +
    1.38 +    for header in open(header_list_file, 'r'):
    1.39 +        header = header.rstrip()
    1.40 +        if 0 == len(header) or is_comment(header):
    1.41 +            continue
    1.42 +
    1.43 +        path = header_path(header, compiler)
    1.44 +        with FileAvoidWrite(os.path.join(outdir, header)) as f:
    1.45 +            f.write(string.Template(template).substitute(HEADER=header,
    1.46 +                                                         HEADER_PATH=path,
    1.47 +                                                         NEW_HEADER_PATH=path_to_new))
    1.48 +
    1.49 +
    1.50 +if __name__ == '__main__':
    1.51 +    if 5 != len(sys.argv):
    1.52 +        print("""Usage:
    1.53 +  python {0} OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
    1.54 +""".format(sys.argv[0]), file=sys.stderr)
    1.55 +        sys.exit(1)
    1.56 +
    1.57 +    main(*sys.argv[1:])

mercurial