Bug 1283439 - Include OpusDecoder.h only for Rust MP4 parsing r=kinetik
[gecko.git] / config / make-stl-wrappers.py
blobc0ab21c7e50f6858ac6dfbc6d570a18b9c7055d9
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)
11 if os.path.exists(f):
12 return f
13 return ''
15 def header_path(header, compiler):
16 if compiler == 'gcc':
17 # we use include_next on gcc
18 return header
19 elif compiler == 'msvc':
20 return find_in_path(header, os.environ.get('INCLUDE', ''))
21 else:
22 # hope someone notices this ...
23 raise NotImplementedError(compiler)
25 def is_comment(line):
26 return re.match(r'\s*#.*', line)
28 def main(outdir, compiler, template_file, header_list_file):
29 if not os.path.isdir(outdir):
30 os.mkdir(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):
37 continue
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,
42 HEADER_PATH=path))
45 if __name__ == '__main__':
46 if 5 != len(sys.argv):
47 print("""Usage:
48 python {0} OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
49 """.format(sys.argv[0]), file=sys.stderr)
50 sys.exit(1)
52 main(*sys.argv[1:])