gecko-dev/build/moz.configure/checks.configure

84 строки
2.5 KiB
Plaintext
Исходник Обычный вид История

# -*- 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/.
# Templates implementing some generic checks.
# Helper to display "checking" messages
# @checking('for foo')
# def foo():
# return 'foo'
# is equivalent to:
# def foo():
# log.info('checking for foo... ')
# ret = foo
# log.info(ret)
# return ret
# This can be combined with e.g. @depends:
# @depends(some_option)
# @checking('for something')
# def check(value):
# ...
# An optional callback can be given, that will be used to format the returned
# value when displaying it.
@template
def checking(what, callback=None):
def decorator(func):
def wrapped(*args, **kwargs):
log.info('checking %s... ', what)
ret = func(*args, **kwargs)
if callback:
log.info(callback(ret))
elif ret is True:
log.info('yes')
elif ret is False:
log.info('no')
else:
log.info(ret)
return ret
return wrapped
return decorator
# Template to check for programs in $PATH.
# check('PROG', ('a', 'b'))
# will look for 'a' or 'b' in $PATH, and set_config PROG to the one
# it can find. If PROG is already set from the environment or command line,
# use that value instead.
@template
@advanced
def check_prog(var, progs, allow_missing=False):
from mozbuild.shellutil import quote
option(env=var, nargs=1, help='Path to the %s program' % var.lower())
if not (isinstance(progs, tuple) or isinstance(progs, list)):
configure_error('progs should be a list or tuple!')
progs = list(progs)
@depends(var)
@checking('for %s' % var.lower(), lambda x: quote(x) if x else 'not found')
def check(value):
if value:
progs[:] = value
for prog in progs:
result = find_program(prog)
if result:
return result
@depends(check, var)
def postcheck(value, raw_value):
if value is None and (not allow_missing or raw_value):
die('Cannot find %s (tried: %s)', var.lower(),
', '.join(quote(p) for p in progs))
@depends(check)
def normalized_for_config(value):
return ':' if value is None else value
set_config(var, normalized_for_config)
return check