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
17 from mozbuild
.makeutil
import Makefile
18 from mozbuild
.pythonutil
import iter_modules_in_path
19 from mozbuild
.backend
.configenvironment
import PartialConfigEnvironment
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 partial_config
= PartialConfigEnvironment(config
['TOPOBJDIR'])
94 partial_config
.write_vars(sanitized_config
)
96 # Write out a depfile so Make knows to re-run configure when relevant Python
99 rule
= mk
.create_rule()
100 rule
.add_targets(["%s/config.status" % config
['TOPOBJDIR']])
101 rule
.add_dependencies(itertools
.chain(config
['ALL_CONFIGURE_PATHS'],
102 iter_modules_in_path(config
['TOPOBJDIR'],
103 config
['TOPSRCDIR'])))
104 with
open('configure.d', 'w') as fh
:
107 # Other things than us are going to run this file, so we need to give it
108 # executable permissions.
109 os
.chmod('config.status', 0o755)
110 if config
.get('MOZ_BUILD_APP') != 'js' or config
.get('JS_STANDALONE'):
111 os
.environ
[b
'WRITE_MOZINFO'] = b
'1'
112 from mozbuild
.config_status
import config_status
114 # Some values in sanitized_config also have more complex types, such as
115 # EnumString, which using when calling config_status would currently
116 # break the build, as well as making it inconsistent with re-running
117 # config.status. Fortunately, EnumString derives from unicode, so it's
118 # covered by converting unicode strings.
120 # A lot of the build backend code is currently expecting byte strings
121 # and breaks in subtle ways with unicode strings.
122 return config_status(args
=[], **encode(sanitized_config
, encoding
))
126 if __name__
== '__main__':
127 sys
.exit(main(sys
.argv
))