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:
...
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -3,29 +3,28 @@
# 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/.
# yasm detection
# ==============================================================
yasm = check_prog('YASM', ['yasm'], allow_missing=True)
-@depends(yasm)
+@depends_true(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
add_old_configure_assignment('_YASM_MAJOR_VERSION',
delayed_getattr(yasm_version, 'major'))
add_old_configure_assignment('_YASM_MINOR_VERSION',
delayed_getattr(yasm_version, 'minor'))
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -125,8 +125,21 @@ def delayed_getattr(func, key):
try:
return getattr(value, key)
except AttributeError:
# The @depends function we're being passed may have returned
# None, or an object that simply doesn't have the wanted 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_true(*args):
+ def decorator(func):
+ @depends(*args)
+ def wrapper(*args):
+ if any(arg for arg in args):
+ return func(*args)
+ return wrapper
+ return decorator