Bug 1257823 - Move set_define() to the global scope. r=nalexander

For the same reasons as set_config is being moved to the global scope,
we're moving set_define to the global scope here. An additional change
is that set_define is now part of the sandbox itself instead of being
defined within the sandbox, which makes it share the implementation
details with set_config.
This commit is contained in:
Mike Hommey 2016-03-23 10:22:08 +09:00
Родитель 7cd6c430c1
Коммит e5cde501da
9 изменённых файлов: 232 добавлений и 79 удалений

Просмотреть файл

@ -14,10 +14,16 @@ def mozttdir(value):
path = value[0]
if not os.path.isdir(path):
error('MOZTTDIR "%s" is not a valid directory' % path)
set_define('PACKAGE_MOZTT', True)
return path
set_config('MOZTTDIR', mozttdir)
@depends('MOZTTDIR')
def package_moztt(value):
if value:
return True
set_define('PACKAGE_MOZTT', package_moztt)
include('../toolkit/moz.configure')

Просмотреть файл

@ -547,24 +547,49 @@ def host_variables(host):
set_config('HOST_OS_ARCH', delayed_getattr(host_variables, 'HOST_OS_ARCH'))
@depends(target)
def target_platform_defines(target):
def target_is_windows(target):
if target.kernel == 'WINNT':
set_define('_WINDOWS', True)
set_define('WIN32', True)
set_define('XP_WIN', True)
set_define('XP_WIN32', True)
else:
set_define('XP_UNIX', True)
return True
set_define('_WINDOWS', target_is_windows)
set_define('WIN32', target_is_windows)
set_define('XP_WIN', target_is_windows)
set_define('XP_WIN32', target_is_windows)
@depends(target)
def target_is_unix(target):
if target.kernel != 'WINNT':
return True
set_define('XP_UNIX', target_is_unix)
@depends(target)
def target_is_darwin(target):
if target.kernel == 'Darwin':
set_define('XP_DARWIN', True)
if target.os == 'iOS':
set_define('XP_IOS', True)
elif target.os == 'OSX':
set_define('XP_MACOSX', True)
elif target.kernel == 'Linux':
set_define('XP_LINUX', True)
return True
set_define('XP_DARWIN', target_is_darwin)
@depends(target)
def target_is_ios(target):
if target.kernel == 'Darwin' and target.os == 'iOS':
return True
set_define('XP_IOS', target_is_ios)
@depends(target)
def target_is_osx(target):
if target.kernel == 'Darwin' and target.os == 'OSX':
return True
set_define('XP_MACOSX', target_is_osx)
@depends(target)
def target_is_linux(target):
if target.kernel == 'Linux':
return True
set_define('XP_LINUX', target_is_linux)
# The application/project to build
# ==============================================================
@ -618,11 +643,11 @@ set_config('EXTERNAL_SOURCE_DIR', external_source_dir)
def build_project(include_project_configure, build_env, help):
ret = os.path.dirname(os.path.relpath(include_project_configure,
build_env.topsrcdir))
set_define('MOZ_BUILD_APP', ret)
add_old_configure_assignment('MOZ_BUILD_APP', ret)
return ret
set_config('MOZ_BUILD_APP', build_project)
set_define('MOZ_BUILD_APP', build_project)
# set RELEASE_BUILD and NIGHTLY_BUILD variables depending on the cycle we're in
@ -642,11 +667,9 @@ def milestone(build_env):
is_nightly = is_release = None
if 'a1' in milestone:
set_define('NIGHTLY_BUILD', True)
add_old_configure_assignment('NIGHTLY_BUILD', True)
is_nightly = True
elif 'a' not in milestone:
set_define('RELEASE_BUILD', True)
add_old_configure_assignment('RELEASE_BUILD', True)
is_release = True
@ -656,7 +679,9 @@ def milestone(build_env):
set_config('GRE_MILESTONE', delayed_getattr(milestone, 'version'))
set_config('NIGHTLY_BUILD', delayed_getattr(milestone, 'is_nightly'))
set_define('NIGHTLY_BUILD', delayed_getattr(milestone, 'is_nightly'))
set_config('RELEASE_BUILD', delayed_getattr(milestone, 'is_release'))
set_define('RELEASE_BUILD', delayed_getattr(milestone, 'is_release'))
# This is temporary until js/src/configure and configure are merged.

Просмотреть файл

@ -427,6 +427,11 @@ def old_configure(prepare_configure, extra_old_configure_args, all_options,
def set_old_configure_config(name, value):
set_config(name, value)
# Same as set_old_configure_config, but for set_define.
@template
def set_old_configure_define(name, value):
set_define(name, value)
@depends(old_configure)
@advanced
@ -438,7 +443,7 @@ def post_old_configure(raw_config):
k[1:-1], v[1:-1] if isinstance(v, types.StringTypes) else v)
for k, v in dict(raw_config['defines']).iteritems():
set_define(k[1:-1], v[1:-1])
set_old_configure_define(k[1:-1], v[1:-1])
set_old_configure_config('non_global_defines',
raw_config['non_global_defines'])

Просмотреть файл

@ -44,10 +44,10 @@ js_option('--enable-sm-promise', help='Enable SpiderMonkey promises')
@depends('--enable-sm-promise')
def sm_promise(value):
if value:
set_define('SPIDERMONKEY_PROMISE', True)
return True
set_config('SPIDERMONKEY_PROMISE', sm_promise)
set_define('SPIDERMONKEY_PROMISE', sm_promise)
# SpiderMonkey as a shared library, and how its symbols are exported
# ==================================================================
@ -58,25 +58,36 @@ js_option('--disable-export-js', default=building_js,
help='Do not mark JS symbols as DLL exported/visible')
@depends('--disable-shared-js', '--disable-export-js')
def static_js(shared_js, export_js):
def shared_js(shared_js, export_js):
if shared_js:
if not export_js:
error('Must export JS symbols when building a shared library.')
add_old_configure_assignment('JS_SHARED_LIBRARY', True)
else:
if export_js:
set_define('STATIC_EXPORTABLE_JS_API', True)
else:
set_define('STATIC_JS_API', True)
set_define('MOZ_STATIC_JS', True)
@depends('--disable-shared-js')
def shared_js(value):
if value:
return True
set_config('JS_SHARED_LIBRARY', shared_js)
@depends('--disable-shared-js', '--disable-export-js')
def exportable_js_api(shared_js, export_js):
if not shared_js and export_js:
return True
set_define('STATIC_EXPORTABLE_JS_API', exportable_js_api)
@depends('--disable-shared-js', '--disable-export-js')
def static_js_api(shared_js, export_js):
if not shared_js and not export_js:
return True
set_define('STATIC_JS_API', static_js_api)
@depends('--disable-shared-js')
def static_js(value):
if not value:
return True
set_define('MOZ_STATIC_JS', static_js)
@deprecated_option(env='DISABLE_SHARED_JS', nargs='?')
def disable_shared_js(value):
# DISABLE_SHARED_JS=1 gets us an empty PositiveOptionValue
@ -111,12 +122,12 @@ def instruments(value, target):
error('--enable-instruments cannot be used when targeting %s'
% target.os)
if value:
set_define('MOZ_INSTRUMENTS', True)
add_old_configure_assignment('MOZ_INSTRUMENTS', True)
imply_option('--enable-profiling', reason='--enable-instruments')
return True
set_config('MOZ_INSTRUMENTS', instruments)
set_define('MOZ_INSTRUMENTS', instruments)
js_option('--enable-callgrind', env='MOZ_CALLGRIND',
help='Enable callgrind profiling')
@ -124,9 +135,10 @@ js_option('--enable-callgrind', env='MOZ_CALLGRIND',
@depends('--enable-callgrind')
def callgrind(value):
if value:
set_define('MOZ_CALLGRIND', True)
imply_option('--enable-profiling')
return True
set_define('MOZ_CALLGRIND', callgrind)
js_option('--enable-profiling', env='MOZ_PROFILING',
help='Set compile flags necessary for using sampling profilers '
@ -135,7 +147,6 @@ js_option('--enable-profiling', env='MOZ_PROFILING',
@depends('--enable-profiling', target)
def profiling(value, target):
if value:
set_define('MOZ_PROFILING', True)
add_old_configure_assignment('MOZ_PROFILING', True)
if target.kernel == 'WINNT' or (target.kernel == 'Linux' and
@ -144,6 +155,7 @@ def profiling(value, target):
return True
set_config('MOZ_PROFILING', profiling)
set_define('MOZ_PROFILING', profiling)
js_option('--enable-vtune', env='MOZ_VTUNE', help='Enable vtune profiling')
@ -151,7 +163,7 @@ js_option('--enable-vtune', env='MOZ_VTUNE', help='Enable vtune profiling')
@depends('--enable-vtune')
def vtune(value):
if value:
set_define('MOZ_VTUNE', True)
return True
set_config('MOZ_VTUNE', vtune)
set_define('MOZ_VTUNE', vtune)

Просмотреть файл

@ -20,10 +20,10 @@ include('build/moz.configure/checks.configure')
@depends(milestone)
def e10s_testing_only(milestone):
if not milestone.is_release:
set_define('E10S_TESTING_ONLY', True)
return True
set_config('E10S_TESTING_ONLY', e10s_testing_only)
set_define('E10S_TESTING_ONLY', e10s_testing_only)
option('--enable-artifact-builds', env='MOZ_ARTIFACT_BUILDS',

Просмотреть файл

@ -138,6 +138,7 @@ class ConfigureSandbox(dict):
self._helper = CommandLineHelper(environ, argv)
assert isinstance(config, dict)
self._config, self._stdout, self._stderr = config, stdout, stderr
self._help = None
@ -290,11 +291,9 @@ class ConfigureSandbox(dict):
The decorated function is altered to use a different global namespace
for its execution. This different global namespace exposes a limited
set of functions from os.path, and two additional functions:
`imply_option` and `set_define`. The former allows to inject
additional options as if they had been passed on the command line.
The latter declares new defines, stored in a DEFINES configuration
item.
set of functions from os.path, and one additional functions:
`imply_option`. It allows to inject additional options as if they had
been passed on the command line.
'''
if not args:
raise ConfigureError('@depends needs at least one argument')
@ -334,7 +333,6 @@ class ConfigureSandbox(dict):
result = DependsOutput()
glob.update(
imply_option=result.imply_option,
set_define=self._set_define,
)
dummy = wraps(func)(DummyFunction())
self._depends[dummy] = func
@ -406,6 +404,7 @@ class ConfigureSandbox(dict):
depends=self.depends_impl,
option=self.option_impl,
set_config=self.set_config_impl,
set_define=self.set_define_impl,
)
self._templates.add(template)
return template
@ -419,13 +418,7 @@ class ConfigureSandbox(dict):
glob.update(__builtins__=__builtins__)
return func
def set_config_impl(self, name, value):
'''Implementation of set_config().
Set the configuration items with the given name to the given value.
Both `name` and `value` can be references to @depends functions,
in which case the result from these functions is used. If the result
of either function is None, the configuration item is not set.
'''
def _resolve_and_set(self, data, name, value):
# Don't set anything when --help was on the command line
if self._help:
return
@ -434,19 +427,33 @@ class ConfigureSandbox(dict):
return
if not isinstance(name, types.StringTypes):
raise TypeError("Unexpected type: '%s'" % type(name))
if name in self._config:
if name in data:
raise ConfigureError(
"Cannot add '%s' to configuration: Key already "
"exists" % name)
value = self._resolve(value, need_help_dependency=False)
if value is not None:
self._config[name] = value
data[name] = value
def _set_define(self, name, value):
def set_config_impl(self, name, value):
'''Implementation of set_config().
Set the configuration items with the given name to the given value.
Both `name` and `value` can be references to @depends functions,
in which case the result from these functions is used. If the result
of either function is None, the configuration item is not set.
'''
self._resolve_and_set(self._config, name, value)
def set_define_impl(self, name, value):
'''Implementation of set_define().
Set the define with the given name to the given value. Both `name` and
`value` can be references to @depends functions, in which case the
result from these functions is used. If the result of either function
is None, the define is not set. If the result is False, the define is
explicitly undefined (-U).
'''
defines = self._config.setdefault('DEFINES', {})
if name in defines:
raise ConfigureError("'%s' is already defined" % name)
defines[name] = value
self._resolve_and_set(defines, name, value)
def _prepare_function(self, func):
'''Alter the given function global namespace with the common ground

Просмотреть файл

@ -0,0 +1,43 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
option('--set-foo', help='set foo')
@depends('--set-foo')
def foo(value):
if value:
return True
set_define('FOO', foo)
option('--set-bar', help='set bar')
@depends('--set-bar')
def bar(value):
return bool(value)
set_define('BAR', bar)
option('--set-value', nargs=1, help='set value')
@depends('--set-value')
def set_value(value):
if value:
return value[0]
set_define('VALUE', set_value)
option('--set-name', nargs=1, help='set name')
@depends('--set-name')
def set_name(value):
if value:
return value[0]
set_define(set_name, True)

Просмотреть файл

@ -339,6 +339,39 @@ class TestConfigure(unittest.TestCase):
# set_config('FOO'...)
get_config(['--set-foo', '--set-name=FOO'])
def test_set_define(self):
def get_config(*args):
return self.get_config(*args, configure='set_define.configure')
config, out = self.get_result(['--help'],
configure='set_define.configure')
self.assertEquals(config, {'DEFINES': {}})
config = get_config(['--set-foo'])
self.assertIn('FOO', config['DEFINES'])
self.assertEquals(config['DEFINES']['FOO'], True)
config = get_config(['--set-bar'])
self.assertNotIn('FOO', config['DEFINES'])
self.assertIn('BAR', config['DEFINES'])
self.assertEquals(config['DEFINES']['BAR'], True)
config = get_config(['--set-value=qux'])
self.assertIn('VALUE', config['DEFINES'])
self.assertEquals(config['DEFINES']['VALUE'], 'qux')
config = get_config(['--set-name=hoge'])
self.assertIn('hoge', config['DEFINES'])
self.assertEquals(config['DEFINES']['hoge'], True)
config = get_config([])
self.assertEquals(config['DEFINES'], {'BAR': False})
with self.assertRaises(ConfigureError):
# Both --set-foo and --set-name=FOO are going to try to
# set_define('FOO'...)
get_config(['--set-foo', '--set-name=FOO'])
if __name__ == '__main__':
main()

Просмотреть файл

@ -18,7 +18,9 @@ def systrace(value, target):
error('--enable-systrace cannot be used when targetting %s'
% target.os)
if value:
set_define('MOZ_USE_SYSTRACE', True)
return True
set_define('MOZ_USE_SYSTRACE', systrace)
option('--enable-jprof', env='MOZ_JPROF',
@ -27,11 +29,11 @@ option('--enable-jprof', env='MOZ_JPROF',
@depends('--enable-jprof')
def jprof(value):
if value:
set_define('MOZ_JPROF', True)
imply_option('--enable-profiling')
return True
set_config('MOZ_JPROF', jprof)
set_define('MOZ_JPROF', jprof)
@depends(target)
def sps_profiler(target):
@ -44,10 +46,10 @@ def sps_profiler(target):
@depends(sps_profiler)
def sps_profiler_define(value):
if value:
set_define('MOZ_ENABLE_PROFILER_SPS', True)
return True
set_config('MOZ_ENABLE_PROFILER_SPS', sps_profiler_define)
set_define('MOZ_ENABLE_PROFILER_SPS', sps_profiler_define)
option('--enable-dmd', env='MOZ_DMD',
@ -57,12 +59,12 @@ option('--enable-dmd', env='MOZ_DMD',
@depends('--enable-dmd')
def dmd(value):
if value:
set_define('MOZ_DMD', True)
add_old_configure_assignment('MOZ_DMD', True)
imply_option('--enable-profiling')
return True
set_config('MOZ_DMD', dmd)
set_define('MOZ_DMD', dmd)
# Javascript engine
# ==============================================================
@ -138,17 +140,26 @@ def toolkit(toolkit):
widget_toolkit = toolkit.replace('cairo-', '')
add_old_configure_assignment('MOZ_WIDGET_TOOLKIT', widget_toolkit)
if widget_toolkit == 'gtk2':
set_define('MOZ_WIDGET_GTK', '2')
elif widget_toolkit == 'gtk3':
set_define('MOZ_WIDGET_GTK', '3')
elif widget_toolkit != 'windows':
set_define('MOZ_WIDGET_%s' % widget_toolkit.upper(), True)
return widget_toolkit
set_config('MOZ_WIDGET_TOOLKIT', toolkit)
@depends(toolkit)
def toolkit_gtk(toolkit):
if toolkit == 'gtk2':
return '2'
elif toolkit == 'gtk3':
return '3'
set_define('MOZ_WIDGET_GTK', toolkit_gtk)
@depends(toolkit)
def toolkit_define(toolkit):
if toolkit not in ('gtk2', 'gtk3', 'windows'):
return 'MOZ_WIDGET_%s' % toolkit.upper()
set_define(toolkit_define, True)
option('--without-x', env='WITHOUT_X', help='Disable X11 support')
@ -163,14 +174,14 @@ def x11(value, toolkit):
% ','.join(x11_toolkits))
if value and toolkit in x11_toolkits:
set_define('MOZ_ENABLE_XREMOTE', True)
set_define('MOZ_X11', True)
add_old_configure_assignment('MOZ_X11', True)
return True if value and toolkit in x11_toolkits else None
set_config('MOZ_ENABLE_XREMOTE', x11)
set_define('MOZ_ENABLE_XREMOTE', x11)
set_config('MOZ_X11', x11)
set_define('MOZ_X11', x11)
# GL Provider
# ==============================================================
@ -179,22 +190,33 @@ option('--with-gl-provider', nargs=1, help='Set GL provider backend type')
@depends('--with-gl-provider')
def gl_provider(value):
if value:
provider = value[0]
set_define('MOZ_GL_PROVIDER', 'GLContextProvider%s' % provider)
set_define('GL_PROVIDER_%s' % provider, True)
return provider
return value[0]
@depends(gl_provider)
def gl_provider_define(provider):
if provider:
return 'GLContextProvider%s' % provider
set_define('MOZ_GL_PROVIDER', gl_provider_define)
@depends(gl_provider, x11)
def gl_default_provider(value, x11):
if value:
return value
elif x11:
set_define('GL_PROVIDER_GLX', True)
return 'GLX'
set_config('MOZ_GL_PROVIDER', gl_provider)
set_config('MOZ_GL_DEFAULT_PROVIDER', gl_default_provider)
@depends(gl_default_provider)
def gl_provider_define(provider):
if provider:
return 'GL_PROVIDER_%s' % provider
set_define(gl_provider_define, True)
# PDF printing
# ==============================================================
@depends(toolkit)
@ -223,10 +245,10 @@ option(env='MOZ_INSTRUMENT_EVENT_LOOP',
def instrument_event_loop(value, toolkit):
if value or (toolkit in ('windows', 'gtk2', 'gtk3', 'cocoa', 'android',
'gonk') and value.origin == 'default'):
set_define('MOZ_INSTRUMENT_EVENT_LOOP', True)
return True
set_config('MOZ_INSTRUMENT_EVENT_LOOP', instrument_event_loop)
set_define('MOZ_INSTRUMENT_EVENT_LOOP', instrument_event_loop)
# Fontconfig Freetype
@ -246,11 +268,11 @@ def fc_freetype(value, toolkit):
@depends(toolkit)
def applemedia(toolkit):
if toolkit in ('cocoa', 'uikit'):
set_define('MOZ_APPLEMEDIA', True)
add_old_configure_assignment('MOZ_APPLEMEDIA', True)
return True
set_config('MOZ_APPLEMEDIA', applemedia)
set_define('MOZ_APPLEMEDIA', applemedia)
# Windows Media Foundation support
# ==============================================================
@ -269,10 +291,10 @@ def wmf(value, target):
error('Cannot enable Windows Media Foundation support on %s'
% target.os)
if enabled:
set_define('MOZ_WMF', True)
return True
set_config('MOZ_WMF', wmf)
set_define('MOZ_WMF', wmf)
# FFmpeg H264/AAC Decoding Support
# ==============================================================
@ -285,11 +307,11 @@ def ffmpeg(value, target):
if value.origin == 'default':
enabled = target.os not in ('Android', 'WINNT')
if enabled:
set_define('MOZ_FFMPEG', True)
imply_option('--enable-fmp4', '--enable-ffmpeg')
return True
set_config('MOZ_FFMPEG', ffmpeg)
set_define('MOZ_FFMPEG', ffmpeg)
# Built-in fragmented MP4 support.
# ==============================================================
@ -303,11 +325,11 @@ def fmp4(value, target, wmf, applemedia):
# target.os == 'Android' includes all B2G versions
enabled = wmf or applemedia or target.os == 'Android'
if enabled:
set_define('MOZ_FMP4', True)
add_old_configure_assignment('MOZ_FMP4', True)
return True
set_config('MOZ_FMP4', fmp4)
set_define('MOZ_FMP4', fmp4)
# EME Support
# ==============================================================
@ -323,7 +345,6 @@ def eme(value, fmp4):
error('Encrypted Media Extension support requires '
'Fragmented MP4 support')
if enabled:
set_define('MOZ_EME', True)
return True
@depends('--enable-eme')
@ -335,4 +356,5 @@ def eme_modules(value):
return list(value) if value else []
set_config('MOZ_EME', eme)
set_define('MOZ_EME', eme)
set_config('MOZ_EME_MODULES', eme_modules)