Bug 1036645 part 3 - Fix the subconfigure wrapper heuristics to decide when to kill config.cache. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 11 Jul 2014 19:06:14 +0900
changeset 215494 a0ab7fa5dd58ee0a92aae12474c8b11b026e90f2
parent 215493 93f1af4bb4b205fd8cbbaf91fb0af8c70420283d
child 215495 54cdce960e73eb9f0402fe1126102bc4e474472a
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1036645
milestone33.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 1036645 part 3 - Fix the subconfigure wrapper heuristics to decide when to kill config.cache. r=gps
build/autoconf/hooks.m4
build/subconfigure.py
--- a/build/autoconf/hooks.m4
+++ b/build/autoconf/hooks.m4
@@ -43,17 +43,17 @@ for moz_config_dir in $1; do
     _CONFIG_SHELL=$(cd $(dirname $_CONFIG_SHELL); pwd -W)/$(basename $_CONFIG_SHELL)
     if test ! -e "$_CONFIG_SHELL" -a -e "${_CONFIG_SHELL}.exe"; then
         _CONFIG_SHELL="${_CONFIG_SHELL}.exe"
     fi
     ;;
   esac
 
   if test -d "$moz_config_dir"; then
-    (cd "$moz_config_dir"; $PYTHON $_topsrcdir/build/subconfigure.py dump "$_CONFIG_SHELL")
+    (cd "$moz_config_dir"; eval $PYTHON $_topsrcdir/build/subconfigure.py dump "$_CONFIG_SHELL" $ac_configure_args)
   else
     mkdir -p "$moz_config_dir"
   fi
   _save_cache_file="$cache_file"
   ifelse($2,,cache_file="$moz_config_dir/config.cache",cache_file="$2")
   _MOZ_AC_OUTPUT_SUBDIRS($moz_config_dir)
   cache_file="$_save_cache_file"
   (cd "$moz_config_dir"; $PYTHON $_topsrcdir/build/subconfigure.py adjust $ac_sub_configure)
--- a/build/subconfigure.py
+++ b/build/subconfigure.py
@@ -1,15 +1,16 @@
 # 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/.
 
 # This script is used to capture the content of config.status-generated
 # files and subsequently restore their timestamp if they haven't changed.
 
+import argparse
 import os
 import re
 import subprocess
 import sys
 import pickle
 
 class File(object):
     def __init__(self, path):
@@ -55,34 +56,64 @@ PRECIOUS_VARS = set([
 
 
 # Autoconf, in some of the sub-configures used in the tree, likes to error
 # out when "precious" variables change in value. The solution it gives to
 # straighten things is to either run make distclean or remove config.cache.
 # There's no reason not to do the latter automatically instead of failing,
 # doing the cleanup (which, on buildbots means a full clobber), and
 # restarting from scratch.
-def maybe_clear_cache():
+def maybe_clear_cache(args):
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--target', type=str)
+    parser.add_argument('--host', type=str)
+    parser.add_argument('--build', type=str)
+    args, others = parser.parse_known_args(args)
+    env = dict(os.environ)
+    for kind in ('target', 'host', 'build'):
+        arg = getattr(args, kind)
+        if arg is not None:
+            env['%s_alias' % kind] = arg
+    # configure can take variables assignments in its arguments, and that
+    # overrides whatever is in the environment.
+    for arg in others:
+        if arg[:1] != '-' and '=' in arg:
+            key, value = arg.split('=', 1)
+            env[key] = value
+
     comment = re.compile(r'^\s+#')
     cache = {}
     with open('config.cache') as f:
-        for line in f.readlines():
+        for line in f:
             if not comment.match(line) and '=' in line:
-                key, value = line.split('=', 1)
+                key, value = line.rstrip(os.linesep).split('=', 1)
+                # If the value is quoted, unquote it
+                if value[:1] == "'":
+                    value = value[1:-1].replace("'\\''", "'")
                 cache[key] = value
     for precious in PRECIOUS_VARS:
-        entry = 'ac_cv_env_%s_value' % precious
-        if entry in cache and (not precious in os.environ or os.environ[precious] != cache[entry]):
+        # If there is no entry at all for that precious variable, then
+        # its value is not precious for that particular configure.
+        if 'ac_cv_env_%s_set' % precious not in cache:
+            continue
+        is_set = cache.get('ac_cv_env_%s_set' % precious) == 'set'
+        value = cache.get('ac_cv_env_%s_value' % precious) if is_set else None
+        if value != env.get(precious):
+            print 'Removing config.cache because of %s value change from:' \
+                % precious
+            print '  %s' % (value if value is not None else 'undefined')
+            print 'to:'
+            print '  %s' % env.get(precious, 'undefined')
             os.remove('config.cache')
             return
 
 
-def dump(dump_file, shell):
+def dump(dump_file, shell, args):
     if os.path.exists('config.cache'):
-        maybe_clear_cache()
+        maybe_clear_cache(args)
     if not os.path.exists('config.status'):
         if os.path.exists(dump_file):
             os.remove(dump_file)
         return
 
     config_files = [File('config.status')]
 
     # Scan the config.status output for information about configuration files
@@ -127,11 +158,11 @@ def adjust(dump_file, configure):
 
     os.remove(dump_file)
 
 
 CONFIG_DUMP = 'config_files.pkl'
 
 if __name__ == '__main__':
     if sys.argv[1] == 'dump':
-        dump(CONFIG_DUMP, sys.argv[2])
+        dump(CONFIG_DUMP, sys.argv[2], sys.argv[3:])
     elif sys.argv[1] == 'adjust':
         adjust(CONFIG_DUMP, sys.argv[2] if len(sys.argv) > 2 else None)