1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 from __future__
import print_function
5 import os
, re
, string
, sys
6 from mozbuild
.util
import FileAvoidWrite
8 def find_in_path(file, searchpath
):
9 for dir in searchpath
.split(os
.pathsep
):
10 f
= os
.path
.join(dir, file)
15 def header_path(header
, compiler
):
17 # we use include_next on gcc
19 elif compiler
== 'msvc':
20 return find_in_path(header
, os
.environ
.get('INCLUDE', ''))
22 # hope someone notices this ...
23 raise NotImplementedError(compiler
)
26 return re
.match(r
'\s*#.*', line
)
28 def main(outdir
, compiler
, template_file
, header_list_file
):
29 if not os
.path
.isdir(outdir
):
32 template
= open(template_file
, 'r').read()
34 for header
in open(header_list_file
, 'r'):
35 header
= header
.rstrip()
36 if 0 == len(header
) or is_comment(header
):
39 path
= header_path(header
, compiler
)
40 with
FileAvoidWrite(os
.path
.join(outdir
, header
)) as f
:
41 f
.write(string
.Template(template
).substitute(HEADER
=header
,
45 if __name__
== '__main__':
46 if 5 != len(sys
.argv
):
48 python {0} OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
49 """.format(sys
.argv
[0]), file=sys
.stderr
)