config/make-stl-wrappers.py
author Emilio Cobos Álvarez <emilio@crisal.io>
Wed, 13 Dec 2017 01:50:36 +0100
changeset 396209 ada854f90036f6696691c14d8987822f3f300959
parent 391239 ccc34ca6ecfde0b52f0725caeefc03ecf5ec20a5
child 419598 fba6f974041a3d3c22ef95c44f6e4262e8e5c52f
permissions -rw-r--r--
Bug 1424950: Add missing repository.callsign to .arcconfig. r=dkl Summary: MozReview-Commit-ID: 74DSn04pBig Reviewers: dkl Bug #: 1424950 Differential Revision: https://phabricator.services.mozilla.com/D335 MozReview-Commit-ID: 3hdaZ2s1MjL

# 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))