Bug 1288373 - Add missing task.h for NewRunnableFunction r=tzimmermann
[gecko.git] / configure.py
blobdcaa61a7d62a98ed658d3a002c1ef946658a74d9
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/.
5 from __future__ import print_function, unicode_literals
7 import codecs
8 import json
9 import os
10 import subprocess
11 import sys
14 base_dir = os.path.abspath(os.path.dirname(__file__))
15 sys.path.insert(0, os.path.join(base_dir, 'python', 'mozbuild'))
16 from mozbuild.configure import ConfigureSandbox
19 def main(argv):
20 config = {}
21 sandbox = ConfigureSandbox(config, os.environ, argv)
22 sandbox.run(os.path.join(os.path.dirname(__file__), 'moz.configure'))
24 if sandbox._help:
25 return 0
27 return config_status(config)
30 def config_status(config):
31 # Sanitize config data to feed config.status
32 # Ideally, all the backend and frontend code would handle the booleans, but
33 # there are so many things involved, that it's easier to keep config.status
34 # untouched for now.
35 def sanitized_bools(v):
36 if v is True:
37 return '1'
38 if v is False:
39 return ''
40 return v
42 sanitized_config = {}
43 sanitized_config['substs'] = {
44 k: sanitized_bools(v) for k, v in config.iteritems()
45 if k not in ('DEFINES', 'non_global_defines', 'TOPSRCDIR', 'TOPOBJDIR')
47 sanitized_config['defines'] = {
48 k: sanitized_bools(v) for k, v in config['DEFINES'].iteritems()
50 sanitized_config['non_global_defines'] = config['non_global_defines']
51 sanitized_config['topsrcdir'] = config['TOPSRCDIR']
52 sanitized_config['topobjdir'] = config['TOPOBJDIR']
53 sanitized_config['mozconfig'] = config.get('MOZCONFIG')
55 # Create config.status. Eventually, we'll want to just do the work it does
56 # here, when we're able to skip configure tests/use cached results/not rely
57 # on autoconf.
58 print("Creating config.status", file=sys.stderr)
59 encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
60 with codecs.open('config.status', 'w', encoding) as fh:
61 fh.write('#!%s\n' % config['PYTHON'])
62 fh.write('# coding=%s\n' % encoding)
63 # Because we're serializing as JSON but reading as python, the values
64 # for True, False and None are true, false and null, which don't exist.
65 # Define them.
66 fh.write('true, false, null = True, False, None\n')
67 for k, v in sanitized_config.iteritems():
68 fh.write('%s = ' % k)
69 json.dump(v, fh, sort_keys=True, indent=4, ensure_ascii=False)
70 fh.write('\n')
71 fh.write("__all__ = ['topobjdir', 'topsrcdir', 'defines', "
72 "'non_global_defines', 'substs', 'mozconfig']")
74 if config.get('MOZ_BUILD_APP') != 'js' or config.get('JS_STANDALONE'):
75 fh.write('''
76 if __name__ == '__main__':
77 args = dict([(name, globals()[name]) for name in __all__])
78 from mozbuild.config_status import config_status
79 config_status(**args)
80 ''')
82 # Other things than us are going to run this file, so we need to give it
83 # executable permissions.
84 os.chmod('config.status', 0755)
85 if config.get('MOZ_BUILD_APP') != 'js' or config.get('JS_STANDALONE'):
86 os.environ['WRITE_MOZINFO'] = '1'
87 # Until we have access to the virtualenv from this script, execute
88 # config.status externally, with the virtualenv python.
89 return subprocess.call([config['PYTHON'], 'config.status'])
90 return 0
93 if __name__ == '__main__':
94 sys.exit(main(sys.argv))