Skip to content
Snippets Groups Projects
Commit 9bf72e69 authored by Mike Hommey's avatar Mike Hommey
Browse files

Bug 1256573 - Switch moz.configure to use @imports instead of @advanced. r=nalexander

parent 9877dc7b
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,8 @@
# _declare_exceptions template, and add it to the return statement. Then
# destructure in the assignment below the function declaration.
@template
@advanced
@imports(_from='__builtin__', _import='Exception')
@imports(_from='__builtin__', _import='__name__')
def _declare_exceptions():
class FatalCheckError(Exception):
'''An exception to throw from a function decorated with @checking.
......@@ -89,11 +90,9 @@ def checking(what, callback=None):
# it can find. If PROG is already set from the environment or command line,
# use that value instead.
@template
@advanced
@imports(_from='mozbuild.shellutil', _import='quote')
@imports(_from='mozbuild.configure', _import='DependsFunction')
def check_prog(var, progs, what=None, input=None, allow_missing=False):
from mozbuild.shellutil import quote
from mozbuild.configure import DependsFunction
if input:
# Wrap input with type checking and normalization.
@depends(input)
......
......@@ -83,10 +83,8 @@ option(env='MOZCONFIG', nargs=1, help='Mozconfig location')
# be called when --help is passed, and the mozconfig wouldn't be read.
@depends('MOZ_CURRENT_PROJECT', 'MOZCONFIG', 'OLD_CONFIGURE',
check_build_environment, '--help')
@advanced
@imports(_from='mozbuild.mozconfig', _import='MozconfigLoader')
def mozconfig(current_project, mozconfig, old_configure, build_env, help):
from mozbuild.mozconfig import MozconfigLoader
if not old_configure:
die('The OLD_CONFIGURE environment variable must be set')
......@@ -130,13 +128,12 @@ def extra_old_configure_args(help):
return []
@template
@advanced
@imports(_from='mozbuild.configure', _import='DependsFunction')
def add_old_configure_assignment(var, value_func):
from mozbuild.configure import DependsFunction
assert isinstance(value_func, DependsFunction)
@depends(old_configure_assignments, value_func)
@advanced
@imports(_from='mozbuild.shellutil', _import='quote')
def add_assignment(assignments, value):
if value is None:
return
......@@ -145,7 +142,6 @@ def add_old_configure_assignment(var, value_func):
elif value is False:
assignments.append('%s=' % var)
else:
from mozbuild.shellutil import quote
if isinstance(value, (list, tuple)):
value = ' '.join(quote(v) for v in value)
assignments.append('%s=%s' % (var, quote(value)))
......@@ -162,17 +158,14 @@ option(env='PYTHON', nargs=1, help='Python interpreter')
# Setup python virtualenv
# ==============================================================
@depends('PYTHON', check_build_environment, mozconfig)
@advanced
@imports('os')
@imports('sys')
@imports('subprocess')
@imports(_from='mozbuild.configure.util', _import='LineIO')
@imports(_from='mozbuild.virtualenv', _import='VirtualenvManager')
@imports(_from='mozbuild.virtualenv', _import='verify_python_version')
@imports('distutils.sysconfig')
def virtualenv_python(env_python, build_env, mozconfig):
import os
import sys
import subprocess
from mozbuild.configure.util import LineIO
from mozbuild.virtualenv import (
VirtualenvManager,
verify_python_version,
)
python = env_python[0] if env_python else None
# Ideally we'd rely on the mozconfig injection from mozconfig_options,
......@@ -228,7 +221,6 @@ def virtualenv_python(env_python, build_env, mozconfig):
sys.exit(subprocess.call([python] + sys.argv))
# We are now in the virtualenv
import distutils.sysconfig
if not distutils.sysconfig.get_python_lib():
die('Could not determine python site packages directory')
......@@ -239,25 +231,16 @@ add_old_configure_assignment('PYTHON', virtualenv_python)
# Inject mozconfig options
# ==============================================================
@template
@advanced
def command_line_helper():
# This escapes the sandbox. Don't copy this. This is only here because
# it is a one off and because the required functionality doesn't need
# to be exposed for other usecases.
return depends.__self__._helper
# All options defined above this point can't be injected in mozconfig_options
# below, so collect them.
@template
def early_options():
@depends('--help')
@advanced
@imports('__sandbox__')
def early_options(help):
return set(
option.env
for option in depends.__self__._options.itervalues()
for option in __sandbox__._options.itervalues()
if option.env
)
return early_options
......@@ -315,9 +298,11 @@ def wanted_mozconfig_variables(help):
@depends(mozconfig, wanted_mozconfig_variables, '--help')
# This gives access to the sandbox. Don't copy this blindly.
@imports('__sandbox__')
def mozconfig_options(mozconfig, wanted_mozconfig_variables, help):
if mozconfig['path']:
helper = command_line_helper()
helper = __sandbox__._helper
log.info('Adding configure options from %s' % mozconfig['path'])
for arg in mozconfig['configure_args']:
log.info(' %s' % arg)
......@@ -343,9 +328,6 @@ def mozconfig_options(mozconfig, wanted_mozconfig_variables, help):
add(key, value)
del command_line_helper
# Mozilla-Build
# ==============================================================
option(env='MOZILLABUILD', nargs=1,
......@@ -354,10 +336,8 @@ option(env='MOZILLABUILD', nargs=1,
# It feels dirty replicating this from python/mozbuild/mozbuild/mozconfig.py,
# but the end goal being that the configure script would go away...
@depends('MOZILLABUILD')
@advanced
@imports('sys')
def shell(mozillabuild):
import sys
shell = 'sh'
if mozillabuild:
shell = mozillabuild[0] + '/msys/bin/sh'
......@@ -461,9 +441,8 @@ def split_triplet(triplet):
@template
@advanced
@imports('subprocess')
def config_sub(shell, triplet):
import subprocess
config_sub = os.path.join(os.path.dirname(__file__), '..',
'autoconf', 'config.sub')
return subprocess.check_output([shell, config_sub, triplet]).strip()
......@@ -471,10 +450,9 @@ def config_sub(shell, triplet):
@depends('--host', shell)
@checking('for host system type', lambda h: h.alias)
@advanced
@imports('subprocess')
def host(value, shell):
if not value:
import subprocess
config_guess = os.path.join(os.path.dirname(__file__), '..',
'autoconf', 'config.guess')
host = subprocess.check_output([shell, config_guess]).strip()
......@@ -674,7 +652,7 @@ add_old_configure_assignment('MOZ_BUILD_APP', build_project)
# - otherwise, if we have "a" in GRE_MILESTONE, we're building Nightly or Aurora
# - otherwise, we're building Release/Beta (define RELEASE_BUILD)
@depends(check_build_environment)
@advanced
@imports(_from='__builtin__', _import='open')
def milestone(build_env):
milestone_path = os.path.join(build_env.topsrcdir,
'config',
......
......@@ -5,10 +5,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
@template
@advanced
@imports('codecs')
@imports('sys')
def encoded_open(path, mode):
import codecs
import sys
encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
return codecs.open(path, mode, encoding)
......@@ -16,10 +15,8 @@ def encoded_open(path, mode):
option(env='AUTOCONF', nargs=1, help='Path to autoconf 2.13')
@depends(mozconfig, 'AUTOCONF')
@advanced
@imports('re')
def autoconf(mozconfig, autoconf):
import re
mozconfig_autoconf = None
if mozconfig['path']:
make_extra = mozconfig['make_extra']
......@@ -63,11 +60,12 @@ set_config('AUTOCONF', autoconf)
# See comment in mozconfig_options() from build/moz.configure/init.configure
@template
@advanced
# This gives access to the sandbox. Don't copy this blindly.
@imports('__sandbox__')
def check_mozconfig_variables():
# This escapes the sandbox. Don't copy this. This is only here because it
# is a one off until old-configure is gone.
all_options = depends.__self__._options.itervalues()
all_options = __sandbox__._options.itervalues()
@depends(early_options, wanted_mozconfig_variables)
def check_mozconfig_variables(early_options, wanted_mozconfig_variables):
......@@ -82,17 +80,16 @@ check_mozconfig_variables()
@depends('OLD_CONFIGURE', mozconfig, autoconf, check_build_environment, shell,
old_configure_assignments, build_project)
@advanced
@imports(_from='__builtin__', _import='open')
@imports(_from='__builtin__', _import='print')
@imports('glob')
@imports('itertools')
@imports('subprocess')
# Import getmtime without overwriting the sandbox os.path.
@imports(_from='os.path', _import='getmtime')
@imports(_from='mozbuild.shellutil', _import='quote')
def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell,
old_configure_assignments, build_project):
import glob
import itertools
import subprocess
# Import getmtime without overwriting the sandbox os.path.
from os.path import getmtime
from mozbuild.shellutil import quote
# os.path.abspath in the sandbox will ensure forward slashes on Windows,
# which is actually necessary because this path actually ends up literally
# as $0, and backslashes there breaks autoconf's detection of the source
......@@ -369,15 +366,16 @@ def old_configure_options(*options):
'--enable-calendar',
'--enable-incomplete-external-linkage',
)
@advanced
@imports(_from='__builtin__', _import='compile')
@imports(_from='__builtin__', _import='open')
@imports(_from='__builtin__', _import='zip')
@imports('logging')
@imports('os')
@imports('subprocess')
@imports('sys')
@imports(_from='mozbuild.shellutil', _import='quote')
def old_configure(prepare_configure, extra_old_configure_args, all_options,
*options):
import logging
import os
import subprocess
import sys
from mozbuild.shellutil import quote
cmd = prepare_configure
# old-configure only supports the options listed in @old_configure_options
......@@ -456,10 +454,8 @@ def set_old_configure_define(name, value):
@depends(old_configure)
@advanced
@imports('types')
def post_old_configure(raw_config):
import types
for k, v in raw_config['substs']:
set_old_configure_config(
k[1:-1], v[1:-1] if isinstance(v, types.StringTypes) else v)
......
......@@ -10,9 +10,8 @@ yasm = check_prog('YASM', ['yasm'], allow_missing=True)
@depends_if(yasm)
@checking('yasm version')
@advanced
@imports('subprocess')
def yasm_version(yasm):
import subprocess
try:
version = Version(subprocess.check_output(
[yasm, '--version']
......@@ -85,9 +84,8 @@ def using_ccache(ccache):
set_config('MOZ_USING_CCACHE', using_ccache)
@depends('--with-compiler-wrapper', ccache)
@advanced
@imports(_from='mozbuild.shellutil', _import='split', _as='shell_split')
def compiler_wrapper(wrapper, ccache):
from mozbuild.shellutil import split as shell_split
if ccache:
if wrapper:
return tuple([ccache] + shell_split(wrapper[0]))
......
......@@ -5,45 +5,45 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
@template
@advanced
@imports('sys')
def die(*args):
'Print an error and terminate configure.'
import sys
log.error(*args)
sys.exit(1)
@template
@advanced
@imports(_from='mozbuild.configure', _import='ConfigureError')
def configure_error(message):
'''Raise a programming error and terminate configure.
Primarily for use in moz.configure templates to sanity check
their inputs from moz.configure usage.'''
from mozbuild.configure import ConfigureError
raise ConfigureError(message)
@template
@advanced
@imports('os')
def is_absolute_or_relative(path):
import os
if os.altsep and os.altsep in path:
return True
return os.sep in path
@template
@advanced
@imports(_import='mozpack.path', _as='mozpath')
def normsep(path):
import mozpack.path as mozpath
return mozpath.normsep(path)
@template
@advanced
# This unlocks the sandbox. Do not copy blindly.
@imports(_import='__builtin__', _as='__builtins__')
def find_program(file):
if is_absolute_or_relative(file):
return os.path.abspath(file) if os.path.isfile(file) else None
# We can't use @imports here because it imports at declaration time,
# and the declaration of find_program happens before we ensure the
# which module is available in sys.path somehow.
from which import which, WhichError
try:
return normsep(which(file))
......@@ -60,10 +60,9 @@ def unique_list(l):
return result
@template
@advanced
@imports(_from='mozbuild.configure.util', _import='Version', _as='_Version')
def Version(v):
'A version number that can be compared usefully.'
from mozbuild.configure.util import Version as _Version
return _Version(v)
# Denotes a deprecated option. Combines option() and @depends:
......@@ -92,9 +91,8 @@ def deprecated_option(*args, **kwargs):
# from mozbuild.util import ReadOnlyNamespace as namespace
@template
@advanced
@imports(_from='mozbuild.util', _import='ReadOnlyNamespace')
def namespace(**kwargs):
from mozbuild.util import ReadOnlyNamespace
return ReadOnlyNamespace(**kwargs)
......@@ -110,7 +108,7 @@ def namespace(**kwargs):
@template
def delayed_getattr(func, key):
@depends(func)
@advanced
@imports(_from='__builtin__', _import='getattr')
def result(value):
try:
return getattr(value, key)
......
......@@ -62,9 +62,8 @@ include(toolchain_include)
@depends('--help')
@advanced
@imports(_from='mozbuild.backend', _import='backends')
def build_backends_choices(help):
from mozbuild.backend import backends
return tuple(backends)
......@@ -110,9 +109,8 @@ add_old_configure_assignment('PERL', perl_for_old_configure)
def perl_version_check(min_version):
@depends(perl)
@checking('for minimum required perl version >= %s' % min_version)
@advanced
@imports('subprocess')
def get_perl_version(perl):
import subprocess
try:
return Version(subprocess.check_output([perl, '-e', 'print $]']))
except subprocess.CalledProcessError as e:
......@@ -125,9 +123,8 @@ def perl_version_check(min_version):
@depends(perl)
@checking('for full perl installation')
@advanced
@imports('subprocess')
def has_full_perl_installation(perl):
import subprocess
ret = subprocess.call(
[perl, '-e', 'use Config; exit(!-d $Config{archlib})'])
return ret == 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment