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
15 base_dir
= os
.path
.abspath(os
.path
.dirname(__file__
))
16 sys
.path
.insert(0, os
.path
.join(base_dir
, 'python', 'mozbuild'))
17 from mozbuild
.configure
import ConfigureSandbox
18 from mozbuild
.pythonutil
import iter_modules_in_path
19 from mozbuild
.backend
.configenvironment
import PartialConfigEnvironment
20 from mozbuild
.util
import (
24 import mozpack
.path
as mozpath
29 sandbox
= ConfigureSandbox(config
, os
.environ
, argv
)
30 sandbox
.run(os
.path
.join(os
.path
.dirname(__file__
), 'moz.configure'))
35 return config_status(config
)
38 def config_status(config
):
39 # Sanitize config data to feed config.status
40 # Ideally, all the backend and frontend code would handle the booleans, but
41 # there are so many things involved, that it's easier to keep config.status
43 def sanitized_bools(v
):
51 sanitized_config
['substs'] = {
52 k
: sanitized_bools(v
) for k
, v
in config
.iteritems()
53 if k
not in ('DEFINES', 'non_global_defines', 'TOPSRCDIR', 'TOPOBJDIR',
56 sanitized_config
['defines'] = {
57 k
: sanitized_bools(v
) for k
, v
in config
['DEFINES'].iteritems()
59 sanitized_config
['non_global_defines'] = config
['non_global_defines']
60 sanitized_config
['topsrcdir'] = config
['TOPSRCDIR']
61 sanitized_config
['topobjdir'] = config
['TOPOBJDIR']
62 sanitized_config
['mozconfig'] = config
.get('MOZCONFIG')
64 # Create config.status. Eventually, we'll want to just do the work it does
65 # here, when we're able to skip configure tests/use cached results/not rely
67 logging
.getLogger('moz.configure').info('Creating config.status')
68 encoding
= 'mbcs' if sys
.platform
== 'win32' else 'utf-8'
69 with codecs
.open('config.status', 'w', encoding
) as fh
:
70 fh
.write(textwrap
.dedent('''\
73 from __future__ import unicode_literals
74 from mozbuild.util import encode
75 encoding = '%(encoding)s'
76 ''') % {'python': config
['PYTHON'], 'encoding': encoding
})
77 # A lot of the build backend code is currently expecting byte
78 # strings and breaks in subtle ways with unicode strings. (bug 1296508)
79 for k
, v
in sanitized_config
.iteritems():
80 fh
.write('%s = encode(%s, encoding)\n' % (k
, indented_repr(v
)))
81 fh
.write("__all__ = ['topobjdir', 'topsrcdir', 'defines', "
82 "'non_global_defines', 'substs', 'mozconfig']")
84 if config
.get('MOZ_BUILD_APP') != 'js' or config
.get('JS_STANDALONE'):
85 fh
.write(textwrap
.dedent('''
86 if __name__ == '__main__':
87 from mozbuild.util import patch_main
89 from mozbuild.config_status import config_status
90 args = dict([(name, globals()[name]) for name in __all__])
94 partial_config
= PartialConfigEnvironment(config
['TOPOBJDIR'])
95 partial_config
.write_vars(sanitized_config
)
97 # Write out a file so the build backend knows to re-run configure when
98 # relevant Python changes.
99 with
open('config_status_deps.in', 'w') as fh
:
100 for f
in itertools
.chain(config
['CONFIG_STATUS_DEPS'],
101 iter_modules_in_path(config
['TOPOBJDIR'],
102 config
['TOPSRCDIR'])):
103 fh
.write('%s\n' % mozpath
.normpath(f
))
105 # Other things than us are going to run this file, so we need to give it
106 # executable permissions.
107 os
.chmod('config.status', 0o755)
108 if config
.get('MOZ_BUILD_APP') != 'js' or config
.get('JS_STANDALONE'):
109 from mozbuild
.config_status
import config_status
111 # Some values in sanitized_config also have more complex types, such as
112 # EnumString, which using when calling config_status would currently
113 # break the build, as well as making it inconsistent with re-running
114 # config.status. Fortunately, EnumString derives from unicode, so it's
115 # covered by converting unicode strings.
117 # A lot of the build backend code is currently expecting byte strings
118 # and breaks in subtle ways with unicode strings.
119 return config_status(args
=[], **encode(sanitized_config
, encoding
))
123 if __name__
== '__main__':
124 sys
.exit(main(sys
.argv
))