Bug 1520340 - Split prepare_configure and old_configure. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 16 Jan 2019 15:14:10 +0000
changeset 511281 dd78d3f82b497c212e0274b1fdaf8b4098b5f170
parent 511280 191f54a3dd6c24ec9025ed771112ef3226dc87de
child 511282 5e51e7031e8f239efd765328071a21b877e1d814
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1520340
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1520340 - Split prepare_configure and old_configure. r=froydnj So that individual parts can be reused downstream. Depends on D16620 Differential Revision: https://phabricator.services.mozilla.com/D16621
build/moz.configure/old.configure
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -57,18 +57,32 @@ def autoconf(mozconfig, autoconf):
         die('Could not find autoconf 2.13 at %s', autoconf)
 
     return autoconf
 
 
 set_config('AUTOCONF', autoconf)
 
 
-@depends('OLD_CONFIGURE', mozconfig, autoconf, check_build_environment, shell,
-         old_configure_assignments, build_project)
+@depends(mozconfig)
+def prepare_mozconfig(mozconfig):
+    if mozconfig['path']:
+        items = {}
+        for key, value in mozconfig['vars']['added'].items():
+            items[key] = (value, 'added')
+        for key, (old, value) in mozconfig['vars']['modified'].items():
+            items[key] = (value, 'modified')
+        for t in ('env', 'vars'):
+            for key in mozconfig[t]['removed'].keys():
+                items[key] = (None, 'removed ' + t)
+        return items
+
+
+@depends('OLD_CONFIGURE', prepare_mozconfig, autoconf, check_build_environment,
+         shell, old_configure_assignments, build_project)
 @imports(_from='__builtin__', _import='open')
 @imports(_from='__builtin__', _import='print')
 @imports(_from='__builtin__', _import='sorted')
 @imports('glob')
 @imports('itertools')
 @imports('subprocess')
 # Import getmtime without overwriting the sandbox os.path.
 @imports(_from='os.path', _import='getmtime')
@@ -121,30 +135,24 @@ def prepare_configure(old_configure, moz
     cmd = [shell, old_configure]
     with encoded_open('old-configure.vars', 'w') as out:
         log.debug('Injecting the following to old-configure:')
 
         def inject(command):
             print(command, file=out) # noqa Python 2vs3
             log.debug('| %s', command)
 
-        if mozconfig['path']:
+        if mozconfig:
             inject('# start of mozconfig values')
-            items = {}
-            for key, value in mozconfig['vars']['added'].items():
-                items[key] = (value, 'added')
-            for key, (old, value) in mozconfig['vars']['modified'].items():
-                items[key] = (value, 'modified')
-
-            for key, (value, action) in sorted(items.items()):
-                inject("%s=%s # %s" % (key, quote(value), action))
-
-            for t in ('env', 'vars'):
-                for key in sorted(mozconfig[t]['removed'].keys()):
-                    inject("unset %s # from %s" % (key, t))
+            for key, (value, action) in sorted(mozconfig.items()):
+                if action.startswith('removed '):
+                    inject("unset %s # from %s" % (
+                        key, action[len('removed '):]))
+                else:
+                    inject("%s=%s # %s" % (key, quote(value), action))
 
             inject('# end of mozconfig values')
 
         # Autoconf is special, because it might be passed from
         # mozconfig['make_extra'], which we don't pass automatically above.
         inject('export AUTOCONF=%s' % quote(autoconf))
 
         for k, v in old_configure_assignments:
@@ -157,18 +165,17 @@ def prepare_configure(old_configure, moz
 def old_configure_options(*options):
     for opt in options:
         option(opt, nargs='*', help='Help missing for old configure options')
 
     @dependable
     def all_options():
         return list(options)
 
-    return depends(prepare_configure, extra_old_configure_args, all_options,
-                   *options)
+    return depends(extra_old_configure_args, all_options, *options)
 
 
 @old_configure_options(
     '--cache-file',
     '--datadir',
     '--enable-content-sandbox',
     '--enable-cookies',
     '--enable-cpp-rtti',
@@ -258,54 +265,59 @@ def old_configure_options(*options):
     '--with-system-zlib',
     '--with-thumb',
     '--with-thumb-interwork',
     '--with-unify-dist',
     '--with-user-appdir',
     '--x-includes',
     '--x-libraries',
 )
+def prepare_configure_options(extra_old_configure_args, all_options, *options):
+    # 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.
+    options = [
+        value.format(name)
+        for name, value in zip(all_options, options)
+        if value.origin != 'default'
+    ]
+
+    extra_env = {}
+
+    # 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:
+        for arg in extra_old_configure_args:
+            if arg.startswith('-'):
+                options.append(arg)
+            else:
+                k, v = arg.split('=', 1)
+                extra_env[k] = v
+
+    return namespace(options=options, extra_env=extra_env, all_options=all_options)
+
+
+@depends(prepare_configure, prepare_configure_options)
 @imports(_from='__builtin__', _import='compile')
 @imports(_from='__builtin__', _import='open')
 @imports('logging')
 @imports('os')
 @imports('subprocess')
 @imports('sys')
 @imports('types')
 @imports(_from='mozbuild.shellutil', _import='quote')
 @imports(_from='mozbuild.shellutil', _import='split')
 @imports(_from='mozbuild.util', _import='encode')
-def old_configure(prepare_configure, extra_old_configure_args, all_options,
-                  *options):
-    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'
-    ]
+def old_configure(prepare_configure, prepare_configure_options):
+    cmd = prepare_configure + prepare_configure_options.options
+    extra_env = prepare_configure_options.extra_env
 
     env = dict(os.environ)
-    extra_env = {}
-
-    # 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:
-        for arg in extra_old_configure_args:
-            if arg.startswith('-'):
-                cmd.append(arg)
-            else:
-                k, v = arg.split('=', 1)
-                extra_env[k] = v
-
     if extra_env:
         env.update(extra_env)
 
     # For debugging purpose, in case it's not what we'd expect.
     log.debug('Running %s', quote(*cmd))
     if extra_env:
         log.debug('with extra environment: %s',
                   ' '.join('%s=%s' % pair for pair in extra_env.iteritems()))
@@ -340,17 +352,17 @@ def old_configure(prepare_configure, ext
         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 # noqa
 
     # Ensure all the flags known to old-configure appear in the
     # @old_configure_options above.
-    all_options = set(all_options)
+    all_options = set(prepare_configure_options.all_options)
     for flag in raw_config['flags']:
         if flag not in all_options:
             die('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')