config/make-stl-wrappers.py
author Tanushree Podder <tpodder@mozilla.com>
Wed, 25 Jul 2018 23:08:20 -0400
changeset 432412 a236c987f26c926f9bf4f82e351aaad39c7ae639
parent 419630 da3c81f986fa63b42a2874b1791eddcdbfbe8424
child 447614 b6c97b4db60a1d8169a3e798a248144ab2973506
permissions -rw-r--r--
Bug 1357785 - Expose the Visual Viewport API to web content. r=botond,Nika Summary: Implemented the non-event handler attributes of the Visual Viewport API according to the spec: https://wicg.github.io/visual-viewport The 'onresize' and 'onscroll' attributes will be implemented in the bug 1478776. MozReview-Commit-ID: G4bkIZ9VtZ2

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