Commit 47d916d8 authored by Mike Hommey's avatar Mike Hommey
Browse files

Bug 1257516 - Expose a sandboxed logger to moz.configure and use it. r=ted

This removes the warn() function and makes the die() function use the logger
instead of print.
parent c15e6d00
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -12,9 +12,9 @@
#       return 'foo'
# is equivalent to:
#   def foo():
#       sys.stdout.write('checking for foo... ')
#       log.info('checking for foo... ')
#       ret = foo
#       sys.stdout.write(ret + '\n')
#       log.info(ret)
#       return ret
# This can be combined with e.g. @depends:
#   @depends(some_option)
@@ -26,21 +26,17 @@
@template
def checking(what, callback=None):
    def decorator(func):
        @advanced
        def wrapped(*args, **kwargs):
            import sys
            print('checking', what, end='... ')
            sys.stdout.flush()
            log.info('checking %s... ', what)
            ret = func(*args, **kwargs)
            if callback:
                print(callback(ret))
                log.info(callback(ret))
            elif ret is True:
                print('yes')
                log.info('yes')
            elif ret is False:
                print('no')
                log.info('no')
            else:
                print(ret)
            sys.stdout.flush()
                log.info(ret)
            return ret
        return wrapped
    return decorator
+5 −5
Original line number Diff line number Diff line
@@ -209,13 +209,13 @@ def virtualenv_python(env_python, build_env, mozconfig):
        python = sys.executable

    if not manager.up_to_date(python):
        warn('Creating Python environment')
        log.info('Creating Python environment')
        manager.build(python)

    python = normsep(manager.python_path)

    if python != normsep(sys.executable):
        warn('Reexecuting in the virtualenv')
        log.info('Reexecuting in the virtualenv')
        if env_python:
            del os.environ['PYTHON']
        # One would prefer to use os.execl, but that's completely borked on
@@ -311,9 +311,9 @@ def wanted_mozconfig_variables(help):
def mozconfig_options(mozconfig, wanted_mozconfig_variables, help):
    if mozconfig['path']:
        helper = command_line_helper()
        warn('Adding configure options from %s' % mozconfig['path'])
        log.info('Adding configure options from %s' % mozconfig['path'])
        for arg in mozconfig['configure_args']:
            warn('  %s' % arg)
            log.info('  %s' % arg)
            # We could be using imply_option() here, but it has other
            # contraints that don't really apply to the command-line
            # emulation that mozconfig provides.
@@ -323,7 +323,7 @@ def mozconfig_options(mozconfig, wanted_mozconfig_variables, help):
            # See comment above wanted_mozconfig_variables
            if key in wanted_mozconfig_variables:
                arg = '%s=%s' % (key, value)
                warn('  %s' % arg)
                log.info('  %s' % arg)
                helper.add(arg, origin='mozconfig', args=helper._args)

        for key, value in mozconfig['env']['added'].iteritems():
+2 −2
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell,
            refresh = False

    if refresh:
        warn('Refreshing %s with %s' % (old_configure, autoconf))
        log.info('Refreshing %s with %s', old_configure, autoconf)
        with open(old_configure, 'wb') as fh:
            subprocess.check_call([
                shell, autoconf,
@@ -392,7 +392,7 @@ def old_configure(prepare_configure, extra_old_configure_args, all_options,
        cmd += extra_old_configure_args

    # For debugging purpose, in case it's not what we'd expect.
    warn('running %s' % ' '.join(quote(a) for a in cmd))
    log.info('running %s', ' '.join(quote(a) for a in cmd))
    ret = subprocess.call(cmd)
    if ret:
        sys.exit(ret)
+2 −12
Original line number Diff line number Diff line
@@ -6,20 +6,10 @@

@template
@advanced
def warn(*args):
    'Print a warning.'
    import sys
    print(*args, file=sys.stderr)
    sys.stderr.flush()


@template
@advanced
def die(format, *args):
def die(*args):
    'Print an error and terminate configure.'
    import sys
    print(format % args, file=sys.stderr)
    sys.stderr.flush()
    log.error(*args)
    sys.exit(1)


+7 −1
Original line number Diff line number Diff line
@@ -140,6 +140,11 @@ class ConfigureSandbox(dict):
        else:
            assert isinstance(logger, logging.Logger)

        self.log_impl = ReadOnlyNamespace(**{
                k: getattr(logger, k)
                for k in ('debug', 'info', 'warning', 'error')
        })

        self._help = None
        self._help_option = self.option_impl('--help',
                                             help='print this message')
@@ -199,7 +204,7 @@ class ConfigureSandbox(dict):
                )

        if self._help:
            with LineIO(logging.getLogger('moz.configure').info) as out:
            with LineIO(self.log_impl.info) as out:
                self._help.usage(out)

    def __getitem__(self, key):
@@ -518,6 +523,7 @@ class ConfigureSandbox(dict):
            __builtins__=self.BUILTINS,
            __file__=self._paths[-1],
            os=self.OS,
            log=self.log_impl,
        )
        func = wraps(func)(types.FunctionType(
            func.func_code,