2012-05-21 15:12:37 +04:00
|
|
|
# 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/.
|
2013-02-27 21:00:56 +04:00
|
|
|
from __future__ import print_function
|
2010-04-02 21:58:11 +04:00
|
|
|
import os, re, string, sys
|
2013-09-06 04:22:39 +04:00
|
|
|
from mozbuild.util import FileAvoidWrite
|
2010-04-02 21:58:11 +04:00
|
|
|
|
|
|
|
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 ...
|
2013-02-27 21:00:56 +04:00
|
|
|
raise NotImplementedError(compiler)
|
2010-04-02 21:58:11 +04:00
|
|
|
|
2017-11-09 01:42:27 +03:00
|
|
|
# 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):
|
2010-04-02 21:58:11 +04:00
|
|
|
template = open(template_file, 'r').read()
|
2010-04-21 00:12:02 +04:00
|
|
|
|
2017-11-09 01:42:27 +03:00
|
|
|
for header in header_list:
|
2010-04-02 21:58:11 +04:00
|
|
|
path = header_path(header, compiler)
|
2013-09-06 04:22:39 +04:00
|
|
|
with FileAvoidWrite(os.path.join(outdir, header)) as f:
|
2010-04-02 21:58:11 +04:00
|
|
|
f.write(string.Template(template).substitute(HEADER=header,
|
2016-05-18 10:37:19 +03:00
|
|
|
HEADER_PATH=path))
|