Bug 1255312 - Limit the options we pass down to old-configure draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 10 Mar 2016 15:48:38 +0900
changeset 339428 8490d56cc8bea70be3ed4c8d778356d81d65cfed
parent 339427 07d255859aff97d5b835ed1ac5ca23dc844ecb71
child 515986 da123d15e0943994daa3b849faab440fd62b07ee
push id12726
push userbmo:mh+mozilla@glandium.org
push dateFri, 11 Mar 2016 05:58:39 +0000
bugs1255312
milestone48.0a1
Bug 1255312 - Limit the options we pass down to old-configure So far, we've been passing down all configure_args from mozconfig as well as every flag appearing on sys.argv. This is overly broad and causes problems for some options, like --enable-application. However, we don't need all these options to be passed. For the top-level old-configure, we need to pass the flags it can handle, as well as the flags that we want passed down to js/src/configure. For js/src/old-configure, we only need to pass the flags it can handle. The flags an old-configure can handle is defined by the list of flags in @old_configure_options. The list of flags to pass down to js/src/configure is defined by extra_old_configure_args. And since the mozconfig configure_args are being injected into python configure processing, the list of values we get in old_configure includes the mozconfig configure_args.
build/moz.configure/old.configure
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -53,24 +53,23 @@ def autoconf(mozconfig, autoconf):
     if not autoconf:
         error('Could not find autoconf 2.13')
 
     set_config('AUTOCONF', autoconf)
     return autoconf
 
 
 @depends('OLD_CONFIGURE', mozconfig, autoconf, check_build_environment, shell,
-         extra_old_configure_args, old_configure_assignments)
+         old_configure_assignments)
 @advanced
 def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell,
-                      extra_old_configure_args, old_configure_assignments):
+                      old_configure_assignments):
     import glob
     import itertools
     import subprocess
-    import sys
     # Import getmtime without overwriting the sandbox os.path.
     from os.path import getmtime
 
     from mozbuild.shellutil import quote
 
     # os.path.abspath in the sandbox will ensure forward slashes on Windows,
     # which is actually necessary because this path actually ends up literally
     # as $0, and backslashes there breaks autoconf's detection of the source
@@ -95,53 +94,48 @@ def prepare_configure(old_configure, moz
     if refresh:
         warn('Refreshing %s with %s' % (old_configure, autoconf))
         with open(old_configure, 'wb') as fh:
             subprocess.check_call([
                 shell, autoconf,
                 '--localdir=%s' % os.path.dirname(old_configure),
                 old_configure + '.in'], stdout=fh)
 
-    cmd = [shell, old_configure] + sys.argv[1:]
+    cmd = [shell, old_configure]
     with open('old-configure.vars', 'w') as out:
         if mozconfig['path']:
-            if mozconfig['configure_args']:
-                cmd += mozconfig['configure_args']
-
             for key, value in mozconfig['env']['added'].items():
                 print("export %s=%s" % (key, quote(value)), file=out)
             for key, (old, value) in mozconfig['env']['modified'].items():
                 print("export %s=%s" % (key, quote(value)), file=out)
             for key, value in mozconfig['vars']['added'].items():
                 print("%s=%s" % (key, quote(value)), file=out)
             for key, (old, value) in mozconfig['vars']['modified'].items():
                 print("%s=%s" % (key, quote(value)), file=out)
             for t in ('env', 'vars'):
                 for key in mozconfig[t]['removed'].keys():
                     print("unset %s" % key, file=out)
 
         for assignment in old_configure_assignments:
             print(assignment, file=out)
 
-    if extra_old_configure_args:
-        cmd += extra_old_configure_args
-
     return cmd
 
 
 @template
 def old_configure_options(*options):
     for opt in options:
         option(opt, nargs='*', help='Help missing for old configure options')
 
     @depends('--help')
     def all_options(help):
-        return set(options)
+        return list(options)
 
-    return depends(prepare_configure, all_options, *options)
+    return depends(prepare_configure, extra_old_configure_args, all_options,
+                   *options)
 
 
 @old_configure_options(
     '--cache-file',
     '--enable-accessibility',
     '--enable-address-sanitizer',
     '--enable-alsa',
     '--enable-android-apz',
@@ -355,38 +349,61 @@ def old_configure_options(*options):
 
     # Below are the configure flags used by comm-central.
     '--enable-ldap',
     '--enable-mapi',
     '--enable-calendar',
     '--enable-incomplete-external-linkage',
 )
 @advanced
-def old_configure(prepare_configure, all_options, *options):
+def old_configure(prepare_configure, extra_old_configure_args, all_options,
+                  *options):
     import codecs
     import os
     import subprocess
     import sys
     import types
+    from mozbuild.shellutil import quote
 
-    ret = subprocess.call(prepare_configure)
+    cmd = prepare_configure
+
+    # old-configure only supports the options listed in @old_configure_options
+    # so we don't need to pass it every single option we've been passed. Only
+    # the ones that are not supported by python configure need to.
+    cmd += [
+        value.format(name)
+        for name, value in zip(all_options, options)
+        if value.origin != 'default'
+    ]
+
+    # We also pass it the options from js/moz.configure so that it can pass
+    # them down to js/src/configure. Note this list is empty when running
+    # js/src/configure, in which case we don't need to pass those options
+    # to old-configure since old-configure doesn't handle them anyways.
+    if extra_old_configure_args:
+        cmd += extra_old_configure_args
+
+    # For debugging purpose, in case it's not what we'd expect.
+    warn('running %s' % ' '.join(quote(a) for a in cmd))
+    ret = subprocess.call(cmd)
     if ret:
         sys.exit(ret)
 
     raw_config = {}
     encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
     with codecs.open('config.data', 'r', encoding) as fh:
         code = compile(fh.read(), 'config.data', 'exec')
         # Every variation of the exec() function I tried led to:
         # SyntaxError: unqualified exec is not allowed in function 'main' it
         # contains a nested function with free variables
         exec code in raw_config
 
     # Ensure all the flags known to old-configure appear in the
     # @old_configure_options above.
+    all_options = set(all_options)
     for flag in raw_config['flags']:
         if flag not in all_options:
             error('Missing option in `@old_configure_options` in %s: %s'
                   % (__file__, flag))
 
     # If the code execution above fails, we want to keep the file around for
     # debugging.
     os.remove('config.data')