Bug 1457047 [wpt PR 10645] - Update webidl2.js to v10.2.1, a=testonly
[gecko.git] / configure.py
blob9b2bae9a91c83ae469522bdc8918b44edbfa3679
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
7 import codecs
8 import itertools
9 import os
10 import sys
11 import textwrap
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 (
21 indented_repr,
22 encode,
26 def main(argv):
27 config = {}
28 sandbox = ConfigureSandbox(config, os.environ, argv)
29 sandbox.run(os.path.join(os.path.dirname(__file__), 'moz.configure'))
31 if sandbox._help:
32 return 0
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
41 # untouched for now.
42 def sanitized_bools(v):
43 if v is True:
44 return '1'
45 if v is False:
46 return ''
47 return v
49 sanitized_config = {}
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
65 # on autoconf.
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('''\
70 #!%(python)s
71 # coding=%(encoding)s
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
87 patch_main()
88 from mozbuild.config_status import config_status
89 args = dict([(name, globals()[name]) for name in __all__])
90 config_status(**args)
91 '''))
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
97 # changes.
98 mk = Makefile()
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:
105 mk.dump(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))
123 return 0
126 if __name__ == '__main__':
127 sys.exit(main(sys.argv))