config/make-stl-wrappers.py
author Jeff Gilbert <jgilbert@mozilla.com>
Tue, 28 Nov 2017 17:11:12 -0800
changeset 398433 9c970413952af20f7a6e2309047cc245a7f8fd2a
parent 391319 ccc34ca6ecfde0b52f0725caeefc03ecf5ec20a5
child 419629 fba6f974041a3d3c22ef95c44f6e4262e8e5c52f
permissions -rw-r--r--
Bug 1428898 - Add TlsScope to reduce fIsCurrent calls. - r=daoshengmu MozReview-Commit-ID: Kyi8dcO7nAu

# 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/.
from __future__ import print_function
import os, re, string, sys
from mozbuild.util import FileAvoidWrite

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 ...
        raise NotImplementedError(compiler)

# 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):
    template = open(template_file, 'r').read()

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