2016-02-23 03:42:40 +03:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-07-08 20:34:09 +03:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2016-02-23 03:42:40 +03:00
|
|
|
|
2016-02-25 22:59:53 +03:00
|
|
|
import codecs
|
2020-03-06 05:19:21 +03:00
|
|
|
import io
|
2016-12-02 21:05:57 +03:00
|
|
|
import itertools
|
2019-01-17 02:42:12 +03:00
|
|
|
import logging
|
2016-02-23 03:42:40 +03:00
|
|
|
import os
|
|
|
|
import sys
|
2016-08-18 12:27:39 +03:00
|
|
|
import textwrap
|
2020-03-23 19:33:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
from collections.abc import Iterable
|
|
|
|
except ImportError:
|
|
|
|
from collections import Iterable
|
2016-08-19 05:11:57 +03:00
|
|
|
|
2016-02-25 22:59:53 +03:00
|
|
|
|
|
|
|
base_dir = os.path.abspath(os.path.dirname(__file__))
|
2016-07-11 20:42:11 +03:00
|
|
|
sys.path.insert(0, os.path.join(base_dir, 'python', 'mozbuild'))
|
2019-05-28 17:23:35 +03:00
|
|
|
sys.path.insert(0, os.path.join(base_dir, 'third_party', 'python', 'six'))
|
2019-02-15 16:52:47 +03:00
|
|
|
from mozbuild.configure import (
|
|
|
|
ConfigureSandbox,
|
|
|
|
TRACE,
|
|
|
|
)
|
2016-12-02 21:05:57 +03:00
|
|
|
from mozbuild.pythonutil import iter_modules_in_path
|
2017-08-18 17:41:50 +03:00
|
|
|
from mozbuild.backend.configenvironment import PartialConfigEnvironment
|
2016-08-18 12:27:39 +03:00
|
|
|
from mozbuild.util import (
|
2020-03-25 22:40:06 +03:00
|
|
|
write_indented_repr,
|
2016-08-18 12:27:39 +03:00
|
|
|
)
|
2018-05-22 00:01:50 +03:00
|
|
|
import mozpack.path as mozpath
|
2019-08-21 00:31:34 +03:00
|
|
|
import six
|
2016-02-23 03:42:40 +03:00
|
|
|
|
|
|
|
|
2016-03-04 11:31:10 +03:00
|
|
|
def main(argv):
|
|
|
|
config = {}
|
2019-02-15 16:52:47 +03:00
|
|
|
|
2016-03-04 11:31:10 +03:00
|
|
|
sandbox = ConfigureSandbox(config, os.environ, argv)
|
2019-02-15 16:52:47 +03:00
|
|
|
|
2019-11-20 00:49:13 +03:00
|
|
|
clobber_file = 'CLOBBER'
|
|
|
|
if not os.path.exists(clobber_file):
|
|
|
|
# Simply touch the file.
|
|
|
|
with open(clobber_file, 'a'):
|
|
|
|
pass
|
|
|
|
|
2019-02-15 16:52:47 +03:00
|
|
|
if os.environ.get('MOZ_CONFIGURE_TRACE'):
|
|
|
|
sandbox._logger.setLevel(TRACE)
|
|
|
|
|
2016-03-04 11:31:10 +03:00
|
|
|
sandbox.run(os.path.join(os.path.dirname(__file__), 'moz.configure'))
|
2016-02-25 22:59:53 +03:00
|
|
|
|
2016-03-04 11:31:10 +03:00
|
|
|
if sandbox._help:
|
|
|
|
return 0
|
2016-02-25 22:59:53 +03:00
|
|
|
|
2016-03-15 10:41:53 +03:00
|
|
|
return config_status(config)
|
|
|
|
|
|
|
|
|
2019-08-21 00:31:34 +03:00
|
|
|
def check_unicode(obj):
|
|
|
|
'''Recursively check that all strings in the object are unicode strings.'''
|
|
|
|
if isinstance(obj, dict):
|
|
|
|
result = True
|
|
|
|
for k, v in six.iteritems(obj):
|
|
|
|
if not check_unicode(k):
|
|
|
|
print("%s key is not unicode." % k, file=sys.stderr)
|
|
|
|
result = False
|
|
|
|
elif not check_unicode(v):
|
|
|
|
print("%s value is not unicode." % k, file=sys.stderr)
|
|
|
|
result = False
|
|
|
|
return result
|
|
|
|
if isinstance(obj, bytes):
|
|
|
|
return False
|
|
|
|
if isinstance(obj, six.text_type):
|
|
|
|
return True
|
|
|
|
if isinstance(obj, Iterable):
|
|
|
|
return all(check_unicode(o) for o in obj)
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2016-03-15 10:41:53 +03:00
|
|
|
def config_status(config):
|
2016-03-04 11:31:10 +03:00
|
|
|
# Sanitize config data to feed config.status
|
2016-03-22 08:03:26 +03:00
|
|
|
# Ideally, all the backend and frontend code would handle the booleans, but
|
|
|
|
# there are so many things involved, that it's easier to keep config.status
|
|
|
|
# untouched for now.
|
2020-04-08 01:08:48 +03:00
|
|
|
def sanitize_config(v):
|
2016-03-22 08:03:26 +03:00
|
|
|
if v is True:
|
|
|
|
return '1'
|
|
|
|
if v is False:
|
|
|
|
return ''
|
2020-04-08 01:08:48 +03:00
|
|
|
# Serialize types that look like lists and tuples as lists.
|
|
|
|
if not isinstance(v, (bytes, six.text_type, dict)) and isinstance(v, Iterable):
|
|
|
|
return list(v)
|
2016-03-22 08:03:26 +03:00
|
|
|
return v
|
|
|
|
|
2016-03-04 11:31:10 +03:00
|
|
|
sanitized_config = {}
|
|
|
|
sanitized_config['substs'] = {
|
2020-04-08 01:08:48 +03:00
|
|
|
k: sanitize_config(v) for k, v in six.iteritems(config)
|
2016-12-02 21:05:57 +03:00
|
|
|
if k not in ('DEFINES', 'non_global_defines', 'TOPSRCDIR', 'TOPOBJDIR',
|
2018-05-22 00:01:50 +03:00
|
|
|
'CONFIG_STATUS_DEPS')
|
2016-02-25 22:59:53 +03:00
|
|
|
}
|
2016-03-22 08:03:26 +03:00
|
|
|
sanitized_config['defines'] = {
|
2020-04-08 01:08:48 +03:00
|
|
|
k: sanitize_config(v) for k, v in six.iteritems(config['DEFINES'])
|
2016-03-22 08:03:26 +03:00
|
|
|
}
|
2016-03-04 11:31:10 +03:00
|
|
|
sanitized_config['non_global_defines'] = config['non_global_defines']
|
|
|
|
sanitized_config['topsrcdir'] = config['TOPSRCDIR']
|
|
|
|
sanitized_config['topobjdir'] = config['TOPOBJDIR']
|
2016-07-08 02:43:17 +03:00
|
|
|
sanitized_config['mozconfig'] = config.get('MOZCONFIG')
|
2016-02-25 22:59:53 +03:00
|
|
|
|
2019-08-21 00:31:34 +03:00
|
|
|
if not check_unicode(sanitized_config):
|
|
|
|
print("Configuration should be all unicode.", file=sys.stderr)
|
|
|
|
print("Please file a bug for the above.", file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-02-25 22:59:53 +03:00
|
|
|
# Create config.status. Eventually, we'll want to just do the work it does
|
|
|
|
# here, when we're able to skip configure tests/use cached results/not rely
|
|
|
|
# on autoconf.
|
2019-01-17 02:42:12 +03:00
|
|
|
logging.getLogger('moz.configure').info('Creating config.status')
|
2019-08-22 00:26:32 +03:00
|
|
|
with codecs.open('config.status', 'w', 'utf-8') as fh:
|
2016-08-18 12:27:39 +03:00
|
|
|
fh.write(textwrap.dedent('''\
|
|
|
|
#!%(python)s
|
2019-08-22 00:26:32 +03:00
|
|
|
# coding=utf-8
|
2016-08-18 12:27:39 +03:00
|
|
|
from __future__ import unicode_literals
|
2019-08-22 00:26:32 +03:00
|
|
|
''') % {'python': config['PYTHON']})
|
2019-08-21 01:22:14 +03:00
|
|
|
for k, v in six.iteritems(sanitized_config):
|
2020-03-25 22:40:06 +03:00
|
|
|
fh.write('%s = ' % k)
|
|
|
|
write_indented_repr(fh, v)
|
2016-02-25 22:59:53 +03:00
|
|
|
fh.write("__all__ = ['topobjdir', 'topsrcdir', 'defines', "
|
2016-07-08 02:43:17 +03:00
|
|
|
"'non_global_defines', 'substs', 'mozconfig']")
|
2016-02-25 22:59:53 +03:00
|
|
|
|
2016-03-18 12:33:18 +03:00
|
|
|
if config.get('MOZ_BUILD_APP') != 'js' or config.get('JS_STANDALONE'):
|
2016-08-18 12:27:39 +03:00
|
|
|
fh.write(textwrap.dedent('''
|
|
|
|
if __name__ == '__main__':
|
2016-12-22 03:28:28 +03:00
|
|
|
from mozbuild.util import patch_main
|
|
|
|
patch_main()
|
2016-08-18 12:27:39 +03:00
|
|
|
from mozbuild.config_status import config_status
|
|
|
|
args = dict([(name, globals()[name]) for name in __all__])
|
|
|
|
config_status(**args)
|
|
|
|
'''))
|
2016-08-19 05:11:57 +03:00
|
|
|
|
2017-08-18 17:41:50 +03:00
|
|
|
partial_config = PartialConfigEnvironment(config['TOPOBJDIR'])
|
|
|
|
partial_config.write_vars(sanitized_config)
|
|
|
|
|
2018-05-22 00:01:50 +03:00
|
|
|
# Write out a file so the build backend knows to re-run configure when
|
|
|
|
# relevant Python changes.
|
2020-03-06 05:19:21 +03:00
|
|
|
with io.open('config_status_deps.in', 'w', encoding='utf-8',
|
|
|
|
newline='\n') as fh:
|
2018-05-22 00:01:50 +03:00
|
|
|
for f in itertools.chain(config['CONFIG_STATUS_DEPS'],
|
|
|
|
iter_modules_in_path(config['TOPOBJDIR'],
|
|
|
|
config['TOPSRCDIR'])):
|
|
|
|
fh.write('%s\n' % mozpath.normpath(f))
|
2016-12-02 21:05:57 +03:00
|
|
|
|
2016-02-25 22:59:53 +03:00
|
|
|
# Other things than us are going to run this file, so we need to give it
|
|
|
|
# executable permissions.
|
2016-08-08 14:45:17 +03:00
|
|
|
os.chmod('config.status', 0o755)
|
2016-03-18 12:33:18 +03:00
|
|
|
if config.get('MOZ_BUILD_APP') != 'js' or config.get('JS_STANDALONE'):
|
2016-08-19 05:11:57 +03:00
|
|
|
from mozbuild.config_status import config_status
|
2016-08-18 12:27:39 +03:00
|
|
|
|
|
|
|
# Some values in sanitized_config also have more complex types, such as
|
|
|
|
# EnumString, which using when calling config_status would currently
|
|
|
|
# break the build, as well as making it inconsistent with re-running
|
2019-08-21 01:22:14 +03:00
|
|
|
# config.status, for which they are normalized to plain strings via
|
|
|
|
# indented_repr. Likewise for non-dict non-string iterables being
|
|
|
|
# converted to lists.
|
|
|
|
def normalize(obj):
|
|
|
|
if isinstance(obj, dict):
|
|
|
|
return {
|
|
|
|
k: normalize(v)
|
|
|
|
for k, v in six.iteritems(obj)
|
|
|
|
}
|
|
|
|
if isinstance(obj, six.text_type):
|
|
|
|
return six.text_type(obj)
|
|
|
|
if isinstance(obj, Iterable):
|
|
|
|
return [normalize(o) for o in obj]
|
|
|
|
return obj
|
|
|
|
return config_status(args=[], **normalize(sanitized_config))
|
2016-02-25 22:59:53 +03:00
|
|
|
return 0
|
2016-02-23 03:42:40 +03:00
|
|
|
|
2016-03-15 10:41:53 +03:00
|
|
|
|
2016-02-23 03:42:40 +03:00
|
|
|
if __name__ == '__main__':
|
2016-03-04 11:31:10 +03:00
|
|
|
sys.exit(main(sys.argv))
|