make-stl-wrappers.py 1.3 KB
Newer Older
1 2 3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# 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
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

def find_in_path(file, searchpath):
    for dir in searchpath.split(os.pathsep):
        f = os.path.join(dir, file)
        if os.path.exists(f):
            return f
    return ''

def header_path(header, compiler):
    if compiler == 'gcc':
        # we use include_next on gcc
        return header
    elif compiler == 'msvc':
        return find_in_path(header, os.environ.get('INCLUDE', ''))
    else:
        # hope someone notices this ...
23
        raise NotImplementedError(compiler)
24

25 26 27
# The 'unused' arg is the output file from the file_generate action. We actually
# generate all the files in header_list
def gen_wrappers(unused, outdir, compiler, template_file, *header_list):
28
    template = open(template_file, 'r').read()
29

30
    for header in header_list:
31
        path = header_path(header, compiler)
32
        with FileAvoidWrite(os.path.join(outdir, header)) as f:
33
            f.write(string.Template(template).substitute(HEADER=header,
34
                                                         HEADER_PATH=path))