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
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
21 sandbox
= ConfigureSandbox(config
, os
.environ
, argv
)
22 sandbox
.run(os
.path
.join(os
.path
.dirname(__file__
), 'moz.configure'))
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
35 def sanitized_bools(v
):
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
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.
66 fh
.write('true, false, null = True, False, None\n')
67 for k
, v
in sanitized_config
.iteritems():
69 json
.dump(v
, fh
, sort_keys
=True, indent
=4, ensure_ascii
=False)
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'):
76 if __name__ == '__main__':
77 args = dict([(name, globals()[name]) for name in __all__])
78 from mozbuild.config_status import config_status
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'])
93 if __name__
== '__main__':
94 sys
.exit(main(sys
.argv
))