Bug 1259354 - Avoid "checking yasm version" being written out when yasm was not found. r=ted

The reason the "checking" string always appears is that @depends
functions are always called, regardless of the value of the dependency.

This introduces a new decorator @depends_true, which works like
@depends, but the decorated function is not called unless one of the
dependency value resolves to True.

The new decorator can also be used to replace many cases where we do
@depends(foo)
def bar(foo):
    if foo:
        ...
This commit is contained in:
Mike Hommey 2016-03-24 15:26:32 +09:00
Родитель 8a90d1c8e4
Коммит 78d9b6ffa4
2 изменённых файлов: 22 добавлений и 10 удалений

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

@ -8,19 +8,18 @@
# ==============================================================
yasm = check_prog('YASM', ['yasm'], allow_missing=True)
@depends(yasm)
@depends_if(yasm)
@checking('yasm version')
@advanced
def yasm_version(yasm):
if yasm:
import subprocess
try:
version = Version(subprocess.check_output(
[yasm, '--version']
).splitlines()[0].split()[1])
return version
except subprocess.CalledProcessError as e:
error('Failed to get yasm version: %s' % e.message)
import subprocess
try:
version = Version(subprocess.check_output(
[yasm, '--version']
).splitlines()[0].split()[1])
return version
except subprocess.CalledProcessError as e:
error('Failed to get yasm version: %s' % e.message)
# Until we move all the yasm consumers out of old-configure.
# bug 1257904

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

@ -130,3 +130,16 @@ def delayed_getattr(func, key):
# In that case, just return None.
return None
return result
# Like @depends, but the decorated function is only called if one of the
# arguments it would be called with has a positive value (bool(value) is True)
@template
def depends_if(*args):
def decorator(func):
@depends(*args)
def wrapper(*args):
if any(arg for arg in args):
return func(*args)
return wrapper
return decorator