Bug 1259354 - Avoid "checking yasm version" being written out when yasm was not found. r?ted draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 24 Mar 2016 15:26:32 +0900
changeset 344291 c32b322d226c774f5ed03f5eb467008b2a7088a1
parent 344287 a2bb2effab4c61afafded875112868e656d1c722
child 344292 61ca733785a6753e1aa98712629b7eb01d8fdee4
push id13784
push userbmo:mh+mozilla@glandium.org
push dateThu, 24 Mar 2016 06:30:16 +0000
reviewersted
bugs1259354
milestone48.0a1
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: ...
build/moz.configure/toolchain.configure
build/moz.configure/util.configure
--- 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