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
.makeutil
import Makefile
19 from mozbuild
.pythonutil
import iter_modules_in_path
20 from mozbuild
.util
import (
28 sandbox
= ConfigureSandbox(config
, os
.environ
, argv
)
29 sandbox
.run(os
.path
.join(os
.path
.dirname(__file__
), 'moz.configure'))
34 return config_status(config
)
37 def config_status(config
):
38 # Sanitize config data to feed config.status
39 # Ideally, all the backend and frontend code would handle the booleans, but
40 # there are so many things involved, that it's easier to keep config.status
42 def sanitized_bools(v
):
50 sanitized_config
['substs'] = {
51 k
: sanitized_bools(v
) for k
, v
in config
.iteritems()
52 if k
not in ('DEFINES', 'non_global_defines', 'TOPSRCDIR', 'TOPOBJDIR',
53 'ALL_CONFIGURE_PATHS')
55 sanitized_config
['defines'] = {
56 k
: sanitized_bools(v
) for k
, v
in config
['DEFINES'].iteritems()
58 sanitized_config
['non_global_defines'] = config
['non_global_defines']
59 sanitized_config
['topsrcdir'] = config
['TOPSRCDIR']
60 sanitized_config
['topobjdir'] = config
['TOPOBJDIR']
61 sanitized_config
['mozconfig'] = config
.get('MOZCONFIG')
63 # Create config.status. Eventually, we'll want to just do the work it does
64 # here, when we're able to skip configure tests/use cached results/not rely
66 print("Creating config.status", file=sys
.stderr
)
67 encoding
= 'mbcs' if sys
.platform
== 'win32' else 'utf-8'
68 with codecs
.open('config.status', 'w', encoding
) as fh
:
69 fh
.write(textwrap
.dedent('''\
72 from __future__ import unicode_literals
73 from mozbuild.util import encode
74 encoding = '%(encoding)s'
75 ''') % {'python': config
['PYTHON'], 'encoding': encoding
})
76 # A lot of the build backend code is currently expecting byte
77 # strings and breaks in subtle ways with unicode strings. (bug 1296508)
78 for k
, v
in sanitized_config
.iteritems():
79 fh
.write('%s = encode(%s, encoding)\n' % (k
, indented_repr(v
)))
80 fh
.write("__all__ = ['topobjdir', 'topsrcdir', 'defines', "
81 "'non_global_defines', 'substs', 'mozconfig']")
83 if config
.get('MOZ_BUILD_APP') != 'js' or config
.get('JS_STANDALONE'):
84 fh
.write(textwrap
.dedent('''
85 if __name__ == '__main__':
86 from mozbuild.util import patch_main
88 from mozbuild.config_status import config_status
89 args = dict([(name, globals()[name]) for name in __all__])
93 # Write out a depfile so Make knows to re-run configure when relevant Python
96 rule
= mk
.create_rule()
97 rule
.add_targets(["$(OBJDIR)/config.status"])
98 rule
.add_dependencies(itertools
.chain(config
['ALL_CONFIGURE_PATHS'],
99 iter_modules_in_path(config
['TOPOBJDIR'],
100 config
['TOPSRCDIR'])))
101 with
open('configure.d', 'w') as fh
:
104 # Other things than us are going to run this file, so we need to give it
105 # executable permissions.
106 os
.chmod('config.status', 0o755)
107 if config
.get('MOZ_BUILD_APP') != 'js' or config
.get('JS_STANDALONE'):
108 os
.environ
[b
'WRITE_MOZINFO'] = b
'1'
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
))