Bug 1467572 - Part 14: Set the minimum viewport dimension to 50px. r=rcaliman
[gecko.git] / configure.py
blob4a1f07281ab434e7cf35fdb7f59a58b05c691417
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.pythonutil import iter_modules_in_path
18 from mozbuild.backend.configenvironment import PartialConfigEnvironment
19 from mozbuild.util import (
20 indented_repr,
21 encode,
23 import mozpack.path as mozpath
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 'CONFIG_STATUS_DEPS')
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 file so the build backend knows to re-run configure when
97 # relevant Python changes.
98 with open('config_status_deps.in', 'w') as fh:
99 for f in itertools.chain(config['CONFIG_STATUS_DEPS'],
100 iter_modules_in_path(config['TOPOBJDIR'],
101 config['TOPSRCDIR'])):
102 fh.write('%s\n' % mozpath.normpath(f))
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 from mozbuild.config_status import config_status
110 # Some values in sanitized_config also have more complex types, such as
111 # EnumString, which using when calling config_status would currently
112 # break the build, as well as making it inconsistent with re-running
113 # config.status. Fortunately, EnumString derives from unicode, so it's
114 # covered by converting unicode strings.
116 # A lot of the build backend code is currently expecting byte strings
117 # and breaks in subtle ways with unicode strings.
118 return config_status(args=[], **encode(sanitized_config, encoding))
119 return 0
122 if __name__ == '__main__':
123 sys.exit(main(sys.argv))