Bug 1251210 - In configure.py, take AUTOCONF from mozconfig (mk_add_options) as well. r=ted
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 26 Feb 2016 02:49:03 +0900
changeset 286100 0a02f7974084fb93344dab6f2d00d1e8edd55cf6
parent 286099 5069f5724e096916b540aabe2d0c7b5ed00ccbef
child 286101 cf5d8cf6d7d81d2c155638cb52482391a74c9efc
push idunknown
push userunknown
push dateunknown
reviewersted
bugs1251210
milestone47.0a1
Bug 1251210 - In configure.py, take AUTOCONF from mozconfig (mk_add_options) as well. r=ted
configure.py
--- a/configure.py
+++ b/configure.py
@@ -4,20 +4,23 @@
 
 from __future__ import print_function, unicode_literals
 
 import glob
 import itertools
 import os
 import subprocess
 import sys
+import re
 
 base_dir = os.path.dirname(__file__)
 sys.path.append(os.path.join(base_dir, 'python', 'which'))
+sys.path.append(os.path.join(base_dir, 'python', 'mozbuild'))
 from which import which, WhichError
+from mozbuild.mozconfig import MozconfigLoader
 
 
 # If feel dirty replicating this from python/mozbuild/mozbuild/mozconfig.py,
 # but the end goal being that the configure script would go away...
 shell = 'sh'
 if 'MOZILLABUILD' in os.environ:
     shell = os.environ['MOZILLABUILD'] + '/msys/bin/sh'
 if sys.platform == 'win32':
@@ -48,35 +51,52 @@ def autoconf_refresh(configure):
              os.path.join(os.path.dirname(configure), 'aclocal.m4')),
             glob.iglob(aclocal),
         ):
             if os.path.getmtime(input) > mtime:
                 break
         else:
             return
 
-    for ac in (os.environ.get('AUTOCONF'), 'autoconf-2.13', 'autoconf2.13',
-               'autoconf213'):
+    mozconfig_autoconf = None
+    configure_dir = os.path.dirname(configure)
+    # Don't read the mozconfig for the js configure (yay backwards
+    # compatibility)
+    if not configure_dir.replace(os.sep, '/').endswith('/js/src'):
+        loader = MozconfigLoader(os.path.dirname(configure))
+        project = os.environ.get('MOZ_CURRENT_PROJECT')
+        mozconfig = loader.find_mozconfig(env=os.environ)
+        mozconfig = loader.read_mozconfig(mozconfig, moz_build_app=project)
+        make_extra = mozconfig['make_extra']
+        if make_extra:
+            for assignment in make_extra:
+                m = re.match('(?:export\s+)?AUTOCONF\s*:?=\s*(.+)$',
+                             assignment)
+                if m:
+                    mozconfig_autoconf = m.group(1)
+
+    for ac in (mozconfig_autoconf, os.environ.get('AUTOCONF'), 'autoconf-2.13',
+               'autoconf2.13', 'autoconf213'):
         if ac:
             autoconf = find_program(ac)
             if autoconf:
                 break
     else:
         fink = find_program('fink')
         if fink:
             autoconf = os.path.normpath(os.path.join(
                 fink, '..', '..', 'lib', 'autoconf2.13', 'bin', 'autoconf'))
 
     if not autoconf:
         raise RuntimeError('Could not find autoconf 2.13')
 
     # Add or adjust AUTOCONF for subprocesses, especially the js/src configure
     os.environ['AUTOCONF'] = autoconf
 
-    print('Refreshing %s' % configure, file=sys.stderr)
+    print('Refreshing %s with %s' % (configure, autoconf), file=sys.stderr)
 
     with open(configure, 'wb') as fh:
         subprocess.check_call([
             shell, autoconf, '--localdir=%s' % os.path.dirname(configure),
             configure + '.in'], stdout=fh)
 
 
 def main(args):