Bug 1256568 - Move awk detection to moz.configure. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 15 Mar 2016 10:45:12 +0900
changeset 312524 c71929474f668a7d47191287d820639ba833926f
parent 312523 8b2a1bed177abbcc55a06e70e8fbcc2c67c943e3
child 312525 4a2a46087a28a0b061f1f68be74d0182910b0c83
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1256568
milestone48.0a1
Bug 1256568 - Move awk detection to moz.configure. r=gps
build/moz.configure/checks.configure
build/moz.configure/init.configure
js/src/old-configure.in
moz.configure
old-configure.in
new file mode 100644
--- /dev/null
+++ b/build/moz.configure/checks.configure
@@ -0,0 +1,73 @@
+# -*- 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():
+#       sys.stdout.write('checking for foo... ')
+#       ret = foo
+#       sys.stdout.write(ret + '\n')
+#       return ret
+# This can be combined with e.g. @depends:
+#   @depends(some_option)
+#   @checking('for something')
+#   def check(value):
+#       ...
+@template
+def checking(what):
+    def decorator(func):
+        @advanced
+        def wrapped(*args, **kwargs):
+            import sys
+            print('checking', what, end='... ')
+            sys.stdout.flush()
+            ret = func(*args, **kwargs)
+            print(ret)
+            sys.stdout.flush()
+            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
+def check_prog(var, progs, allow_missing=False):
+    option(env=var, nargs=1, help=var)
+
+    not_found = 'not found'
+    progs = list(progs)
+
+    @depends(var)
+    @checking('for %s' % var.lower())
+    def check(value):
+        if value:
+            progs[:] = value
+        for prog in progs:
+            result = find_program(prog)
+            if result:
+                return result
+        return not_found
+
+    @depends(check)
+    @advanced
+    def postcheck(value):
+        if value is not not_found:
+            set_config(var, value)
+        elif not allow_missing:
+            from mozbuild.shellutil import quote
+            error('Cannot find %s (tried: %s)'
+                  % (var.lower(), ', '.join(quote(p) for p in progs)))
+
+    return check
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -243,16 +243,17 @@ early_options = early_options()
 # But we don't know all the options that moz.configure knows about until all
 # moz.configure files are executed, so we keep a manual list here, that is
 # checked in old.configure (we'll assume it's the last moz.configure file
 # processed). This is tedious but necessary for now.
 @depends('--help')
 def wanted_mozconfig_variables(help):
      return set([
          'AUTOCONF',
+         'AWK',
          'DISABLE_EXPORT_JS',
          'DISABLE_SHARED_JS',
          'EXTERNAL_SOURCE_DIR',
          'MOZILLABUILD',
          'MOZ_ARTIFACT_BUILDS',
          'MOZ_BUILD_APP',
      ])
 
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -58,17 +58,16 @@ PERL_VERSION=5.006
 WINDRES_VERSION=2.14.90
 W32API_VERSION=3.14
 
 MSMANIFEST_TOOL=
 
 dnl Set various checks
 dnl ========================================================
 MISSING_X=
-AC_PROG_AWK
 
 dnl Initialize the Pthread test variables early so they can be
 dnl  overridden by each platform.
 dnl ========================================================
 USE_PTHREADS=
 _PTHREAD_LDFLAGS=""
 
 dnl Do not allow objdir == srcdir builds
--- a/moz.configure
+++ b/moz.configure
@@ -1,15 +1,16 @@
 # -*- 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/.
 
 include('build/moz.configure/init.configure')
+include('build/moz.configure/checks.configure')
 
 # Note:
 # - Gecko-specific options and rules should go in toolkit/moz.configure.
 # - Firefox-specific options and rules should go in browser/moz.configure.
 # - Fennec-specific options and rules should go in
 #   mobile/android/moz.configure.
 # - Spidermonkey-specific options and rules should go in js/moz.configure.
 # - etc.
@@ -51,10 +52,20 @@ def build_backend(backends, artifact_bui
     if artifact_builds:
         all_backends = ['FasterMake+RecursiveMake']
     else:
         all_backends = ['RecursiveMake', 'FasterMake']
     all_backends.extend(backends)
     set_config('BUILD_BACKENDS', unique_list(all_backends))
 
 
+# Awk detection
+# ==============================================================
+awk = check_prog('AWK', ('gawk', 'mawk', 'nawk', 'awk'))
+
+# Until the AWK variable is not necessary in old-configure
+@depends(awk)
+def awk_for_old_configure(value):
+    add_old_configure_assignment('AWK', value)
+
+
 # Fallthrough to autoconf-based configure
 include('build/moz.configure/old.configure')
--- a/old-configure.in
+++ b/old-configure.in
@@ -78,17 +78,16 @@ DBUS_VERSION=0.60
 SQLITE_VERSION=3.11.0
 FONTCONFIG_VERSION=2.7.0
 
 MSMANIFEST_TOOL=
 
 dnl Set various checks
 dnl ========================================================
 MISSING_X=
-AC_PROG_AWK
 
 dnl Initialize the Pthread test variables early so they can be
 dnl  overridden by each platform.
 dnl ========================================================
 MOZ_USE_PTHREADS=
 _PTHREAD_LDFLAGS=""
 
 dnl Do not allow objdir == srcdir builds.