2016-03-15 04:45:12 +03:00
|
|
|
# -*- 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():
|
2016-03-25 10:30:42 +03:00
|
|
|
# log.info('checking for foo... ')
|
2016-03-15 04:45:12 +03:00
|
|
|
# ret = foo
|
2016-03-25 10:30:42 +03:00
|
|
|
# log.info(ret)
|
2016-03-15 04:45:12 +03:00
|
|
|
# return ret
|
|
|
|
# This can be combined with e.g. @depends:
|
|
|
|
# @depends(some_option)
|
|
|
|
# @checking('for something')
|
|
|
|
# def check(value):
|
|
|
|
# ...
|
2016-03-24 11:43:31 +03:00
|
|
|
# An optional callback can be given, that will be used to format the returned
|
|
|
|
# value when displaying it.
|
2016-03-15 04:45:12 +03:00
|
|
|
@template
|
2016-03-24 11:43:31 +03:00
|
|
|
def checking(what, callback=None):
|
2016-03-15 04:45:12 +03:00
|
|
|
def decorator(func):
|
|
|
|
def wrapped(*args, **kwargs):
|
2016-03-25 10:30:42 +03:00
|
|
|
log.info('checking %s... ', what)
|
2016-03-15 04:45:12 +03:00
|
|
|
ret = func(*args, **kwargs)
|
2016-03-24 11:43:31 +03:00
|
|
|
if callback:
|
2016-03-25 10:30:42 +03:00
|
|
|
log.info(callback(ret))
|
2016-03-24 11:43:31 +03:00
|
|
|
elif ret is True:
|
2016-03-25 10:30:42 +03:00
|
|
|
log.info('yes')
|
2016-03-15 05:23:29 +03:00
|
|
|
elif ret is False:
|
2016-03-25 10:30:42 +03:00
|
|
|
log.info('no')
|
2016-03-15 05:23:29 +03:00
|
|
|
else:
|
2016-03-25 10:30:42 +03:00
|
|
|
log.info(ret)
|
2016-03-15 04:45:12 +03:00
|
|
|
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
|
2016-03-25 11:15:47 +03:00
|
|
|
@advanced
|
2016-03-15 04:45:12 +03:00
|
|
|
def check_prog(var, progs, allow_missing=False):
|
2016-03-25 11:15:47 +03:00
|
|
|
from mozbuild.shellutil import quote
|
|
|
|
|
2016-03-16 04:36:16 +03:00
|
|
|
option(env=var, nargs=1, help='Path to the %s program' % var.lower())
|
2016-03-15 04:45:12 +03:00
|
|
|
|
2016-03-17 18:04:12 +03:00
|
|
|
if not (isinstance(progs, tuple) or isinstance(progs, list)):
|
|
|
|
configure_error('progs should be a list or tuple!')
|
2016-03-15 04:45:12 +03:00
|
|
|
progs = list(progs)
|
|
|
|
|
|
|
|
@depends(var)
|
2016-03-25 11:15:47 +03:00
|
|
|
@checking('for %s' % var.lower(), lambda x: quote(x) if x else 'not found')
|
2016-03-15 04:45:12 +03:00
|
|
|
def check(value):
|
|
|
|
if value:
|
|
|
|
progs[:] = value
|
|
|
|
for prog in progs:
|
|
|
|
result = find_program(prog)
|
|
|
|
if result:
|
|
|
|
return result
|
|
|
|
|
2016-03-24 09:34:09 +03:00
|
|
|
@depends(check, var)
|
|
|
|
def postcheck(value, raw_value):
|
2016-03-24 11:43:31 +03:00
|
|
|
if value is None and (not allow_missing or raw_value):
|
2016-03-25 09:48:21 +03:00
|
|
|
die('Cannot find %s (tried: %s)', var.lower(),
|
|
|
|
', '.join(quote(p) for p in progs))
|
2016-03-15 04:45:12 +03:00
|
|
|
|
2016-03-24 11:43:31 +03:00
|
|
|
@depends(check)
|
2016-03-22 08:21:32 +03:00
|
|
|
def normalized_for_config(value):
|
|
|
|
return ':' if value is None else value
|
|
|
|
|
|
|
|
set_config(var, normalized_for_config)
|
|
|
|
|
2016-03-24 11:43:31 +03:00
|
|
|
return check
|