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