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/.
|
|
|
|
|
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
2016-02-25 22:59:53 +03:00
|
|
|
import codecs
|
2016-12-02 21:05:57 +03:00
|
|
|
import itertools
|
2016-02-23 03:42:40 +03:00
|
|
|
import os
|
|
|
|
import sys
|
2016-08-18 12:27:39 +03:00
|
|
|
import textwrap
|
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'))
|
2016-03-04 11:31:10 +03:00
|
|
|
from mozbuild.configure import ConfigureSandbox
|
2016-12-02 21:05:57 +03:00
|
|
|
from mozbuild.makeutil import Makefile
|
|
|
|
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 (
|
|
|
|
indented_repr,
|
|
|
|
encode,
|
|
|
|
)
|
2016-02-23 03:42:40 +03:00
|
|
|
|
|
|
|
|
2016-03-04 11:31:10 +03:00
|
|
|
def main(argv):
|
|
|
|
config = {}
|
|
|
|
sandbox = ConfigureSandbox(config, os.environ, argv)
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
def sanitized_bools(v):
|
|
|
|
if v is True:
|
|
|
|
return '1'
|
|
|
|
if v is False:
|
|
|
|
return ''
|
|
|
|
return v
|
|
|
|
|
2016-03-04 11:31:10 +03:00
|
|
|
sanitized_config = {}
|
|
|
|
sanitized_config['substs'] = {
|
2016-03-22 08:03:26 +03:00
|
|
|
k: sanitized_bools(v) for k, v in config.iteritems()
|
2016-12-02 21:05:57 +03:00
|
|
|
if k not in ('DEFINES', 'non_global_defines', 'TOPSRCDIR', 'TOPOBJDIR',
|
|
|
|
'ALL_CONFIGURE_PATHS')
|
2016-02-25 22:59:53 +03:00
|
|
|
}
|
2016-03-22 08:03:26 +03:00
|
|
|
sanitized_config['defines'] = {
|
|
|
|
k: sanitized_bools(v) for k, v in config['DEFINES'].iteritems()
|
|
|
|
}
|
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
|
|
|
|
|
|
|
# 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.
|
|
|
|
print("Creating config.status", file=sys.stderr)
|
2016-03-04 11:31:10 +03:00
|
|
|
encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
|
2016-02-25 22:59:53 +03:00
|
|
|
with codecs.open('config.status', 'w', encoding) as fh:
|
2016-08-18 12:27:39 +03:00
|
|
|
fh.write(textwrap.dedent('''\
|
|
|
|
#!%(python)s
|
|
|
|
# coding=%(encoding)s
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from mozbuild.util import encode
|
|
|
|
encoding = '%(encoding)s'
|
|
|
|
''') % {'python': config['PYTHON'], 'encoding': encoding})
|
|
|
|
# A lot of the build backend code is currently expecting byte
|
|
|
|
# strings and breaks in subtle ways with unicode strings. (bug 1296508)
|
2016-03-04 11:31:10 +03:00
|
|
|
for k, v in sanitized_config.iteritems():
|
2016-08-18 12:27:39 +03:00
|
|
|
fh.write('%s = encode(%s, encoding)\n' % (k, indented_repr(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)
|
|
|
|
|
2016-12-02 21:05:57 +03:00
|
|
|
# Write out a depfile so Make knows to re-run configure when relevant Python
|
|
|
|
# changes.
|
|
|
|
mk = Makefile()
|
|
|
|
rule = mk.create_rule()
|
|
|
|
rule.add_targets(["$(OBJDIR)/config.status"])
|
|
|
|
rule.add_dependencies(itertools.chain(config['ALL_CONFIGURE_PATHS'],
|
|
|
|
iter_modules_in_path(config['TOPOBJDIR'],
|
|
|
|
config['TOPSRCDIR'])))
|
|
|
|
with open('configure.d', 'w') as fh:
|
|
|
|
mk.dump(fh)
|
|
|
|
|
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
|
|
|
os.environ[b'WRITE_MOZINFO'] = b'1'
|
|
|
|
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
|
|
|
|
# config.status. Fortunately, EnumString derives from unicode, so it's
|
|
|
|
# covered by converting unicode strings.
|
|
|
|
|
|
|
|
# A lot of the build backend code is currently expecting byte strings
|
|
|
|
# and breaks in subtle ways with unicode strings.
|
|
|
|
return config_status(args=[], **encode(sanitized_config, encoding))
|
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))
|