Bug 1259960 - Allow to pass a string to check_prog to describe what is being looked for. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Sat, 26 Mar 2016 08:35:13 +0900
changeset 290983 273794fe2b2cbaa28a52d17ceae069aa26bcb9d1
parent 290982 7ebd549a0af91d9bc1a3cfbe8e55631becf6f3b8
child 290984 58ea10aa8c8975d72b5a931d76077f74212d2746
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1259960
milestone48.0a1
Bug 1259960 - Allow to pass a string to check_prog to describe what is being looked for. r=chmanchester So far, we've been using the lowercase of the variable name, but it's not enough for some special cases. Those special cases could do their own business, but then, they'd have to duplicate 90% of check_prog, which is less desirable.
build/moz.configure/checks.configure
python/mozbuild/mozbuild/test/configure/test_checks_configure.py
--- a/build/moz.configure/checks.configure
+++ b/build/moz.configure/checks.configure
@@ -64,44 +64,54 @@ def checking(what, callback=None):
                 if error:
                     die(error)
             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
+# - `var` is the name of the variable that will be set with `set_config` when
+#   the program is found.
+# - `progs` is a list (or tuple) of program names that will be searched for.
+# - `what` is a human readable description of what is being looked for. It
+#   defaults to the lowercase version of `var`.
+# - `allow_missing` indicates whether not finding the program is an error.
+#
+# The simplest form is:
+#   check_prog('PROG', ('a', 'b'))
+# This 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):
+def check_prog(var, progs, what=None, allow_missing=False):
     from mozbuild.shellutil import quote
 
-    option(env=var, nargs=1, help='Path to the %s program' % var.lower())
+    option(env=var, nargs=1,
+           help='Path to %s' % (what or 'the %s program' % var.lower()))
+    what = what or var.lower()
 
-    if not (isinstance(progs, tuple) or isinstance(progs, list)):
+    if not isinstance(progs, (tuple, 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')
+    @checking('for %s' % what, lambda x: quote(x) if x else 'not found')
     def check(value):
         if value:
             progs[:] = value
         for prog in progs:
             log.debug('%s: Trying %s', var.lower(), quote(prog))
             result = find_program(prog)
             if result:
                 return result
 
         if not allow_missing or value:
-            raise FatalCheckError('Cannot find %s' % var.lower())
+            raise FatalCheckError('Cannot find %s' % what)
 
     @depends(check)
     def normalized_for_config(value):
         return ':' if value is None else value
 
     set_config(var, normalized_for_config)
 
     return check
--- a/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
@@ -147,16 +147,34 @@ class TestChecksConfigure(unittest.TestC
             'check_prog("FOO", ("unknown", "unknown-2", "unknown 3"), '
             'allow_missing=True)', ['FOO=unknown'])
         self.assertEqual(status, 1)
         self.assertEqual(config, {})
         self.assertEqual(out, 'checking for foo... not found\n'
                               'DEBUG: foo: Trying unknown\n'
                               'ERROR: Cannot find foo\n')
 
+    def test_check_prog_what(self):
+        config, out, status = self.get_result(
+            'check_prog("CC", ("known-a",), what="the target C compiler")')
+        self.assertEqual(status, 0)
+        self.assertEqual(config, {'CC': '/usr/bin/known-a'})
+        self.assertEqual(out, 'checking for the target C compiler... /usr/bin/known-a\n')
+
+        config, out, status = self.get_result(
+            'check_prog("CC", ("unknown", "unknown-2", "unknown 3"),'
+            '           what="the target C compiler")')
+        self.assertEqual(status, 1)
+        self.assertEqual(config, {})
+        self.assertEqual(out, 'checking for the target C compiler... not found\n'
+                              'DEBUG: cc: Trying unknown\n'
+                              'DEBUG: cc: Trying unknown-2\n'
+                              "DEBUG: cc: Trying 'unknown 3'\n"
+                              'ERROR: Cannot find the target C compiler\n')
+
     def test_check_prog_configure_error(self):
         with self.assertRaises(ConfigureError) as e:
             self.get_result('check_prog("FOO", "foo")')
 
         self.assertEqual(e.exception.message,
                          'progs should be a list or tuple!')