Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / config / make-stl-wrappers.py
blob700cd86416509e89a2ee550fb4dd6ab2b62639af
1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
12 # License.
14 # The Original Code is mozilla.org code.
16 # The Initial Developer of the Original Code is
17 # The Mozilla Foundation
18 # Portions created by the Initial Developer are Copyright (C) 2010
19 # the Initial Developer. All Rights Reserved.
21 # Contributor(s):
22 # Chris Jones <jones.chris.g@gmail.com>
24 # Alternatively, the contents of this file may be used under the terms of
25 # either of the GNU General Public License Version 2 or later (the "GPL"),
26 # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 # in which case the provisions of the GPL or the LGPL are applicable instead
28 # of those above. If you wish to allow use of your version of this file only
29 # under the terms of either the GPL or the LGPL, and not to allow others to
30 # use your version of this file under the terms of the MPL, indicate your
31 # decision by deleting the provisions above and replace them with the notice
32 # and other provisions required by the GPL or the LGPL. If you do not delete
33 # the provisions above, a recipient may use your version of this file under
34 # the terms of any one of the MPL, the GPL or the LGPL.
36 # ***** END LICENSE BLOCK *****
38 import os, re, string, sys
40 def find_in_path(file, searchpath):
41 for dir in searchpath.split(os.pathsep):
42 f = os.path.join(dir, file)
43 if os.path.exists(f):
44 return f
45 return ''
47 def header_path(header, compiler):
48 if compiler == 'gcc':
49 # we use include_next on gcc
50 return header
51 elif compiler == 'msvc':
52 return find_in_path(header, os.environ.get('INCLUDE', ''))
53 else:
54 # hope someone notices this ...
55 raise NotImplementedError, compiler
57 def is_comment(line):
58 return re.match(r'\s*#.*', line)
60 def main(outdir, compiler, template_file, header_list_file):
61 if not os.path.isdir(outdir):
62 os.mkdir(outdir)
64 template = open(template_file, 'r').read()
65 path_to_new = header_path('new', compiler)
67 for header in open(header_list_file, 'r'):
68 header = header.rstrip()
69 if 0 == len(header) or is_comment(header):
70 continue
72 path = header_path(header, compiler)
73 try:
74 f = open(os.path.join(outdir, header), 'w')
75 f.write(string.Template(template).substitute(HEADER=header,
76 HEADER_PATH=path,
77 NEW_HEADER_PATH=path_to_new))
78 finally:
79 f.close()
82 if __name__ == '__main__':
83 if 5 != len(sys.argv):
84 print >>sys.stderr, """Usage:
85 python %s OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
86 """% (sys.argv[0])
87 sys.exit(1)
89 main(*sys.argv[1:])