author Emilio Cobos Álvarez <>
Thu, 31 Aug 2017 09:42:26 +0200
changeset 430034 8daf204f77fbf183e3660fd89e170f076967d245
parent 339413 68da139d0866977c0ada86319fa94388f2255446
child 444355 828d43ec1b16edaac69c42f15561f26e209051f1
permissions -rw-r--r--
Bug 1394935: Add a special case for marking something as dirty from invalidation code. r=bholley Not sure about the name, or whether making it a static or not (a static seemed slightly clearer, but nbd, feel free to bikeshed about it). MozReview-Commit-ID: FHGmcoprN2Q

# 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
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', ''))
        # hope someone notices this ...
        raise NotImplementedError(compiler)

def is_comment(line):
    return re.match(r'\s*#.*', line)

def main(outdir, compiler, template_file, header_list_file):
    if not os.path.isdir(outdir):

    template = open(template_file, 'r').read()

    for header in open(header_list_file, 'r'):
        header = header.rstrip()
        if 0 == len(header) or is_comment(header):

        path = header_path(header, compiler)
        with FileAvoidWrite(os.path.join(outdir, header)) as f:

if __name__ == '__main__':
    if 5 != len(sys.argv):
  python {0} OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
""".format(sys.argv[0]), file=sys.stderr)