Bug 906403 - Avoid subconfigure fail in incremental builds when some variable like CFLAGS change. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 20 Aug 2013 15:26:23 +0900
changeset 143187 e616268dba3cef144faa33f3f1ee27674309482f
parent 143186 f6f98e1ea1ef6139d838555f9d97727821e5c96f
child 143188 a727146d85e208f0b9a1f62a8d26150c6e118516
push id32654
push usermh@glandium.org
push dateTue, 20 Aug 2013 06:27:22 +0000
treeherdermozilla-inbound@e616268dba3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs906403
milestone26.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 906403 - Avoid subconfigure fail in incremental builds when some variable like CFLAGS change. r=gps
build/subconfigure.py
js/src/build/subconfigure.py
--- a/build/subconfigure.py
+++ b/build/subconfigure.py
@@ -1,16 +1,17 @@
 # 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 os
+import re
 import subprocess
 import sys
 import pickle
 
 class File(object):
     def __init__(self, path):
         self._path = path
         self._content = open(path, 'rb').read()
@@ -20,17 +21,60 @@ class File(object):
     def update_time(self):
         '''If the file hasn't changed since the instance was created,
            restore its old modification time.'''
         if not os.path.exists(self._path):
             return
         if open(self._path, 'rb').read() == self._content:
             os.utime(self._path, self._times)
 
+
+# As defined in the various sub-configures in the tree
+PRECIOUS_VARS = set([
+    'build_alias',
+    'host_alias',
+    'target_alias',
+    'CC',
+    'CFLAGS',
+    'LDFLAGS',
+    'LIBS',
+    'CPPFLAGS',
+    'CPP',
+    'CCC',
+    'CXXFLAGS',
+    'CXX',
+    'CCASFLAGS',
+    'CCAS',
+])
+
+
+# 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():
+    comment = re.compile(r'^\s+#')
+    cache = {}
+    with open('config.cache') as f:
+        for line in f.readlines():
+            if not comment.match(line) and '=' in line:
+                key, value = line.split('=', 1)
+                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]):
+            os.remove('config.cache')
+            return
+
+
 def dump(dump_file, shell):
+    if os.path.exists('config.cache'):
+        maybe_clear_cache()
     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
--- a/js/src/build/subconfigure.py
+++ b/js/src/build/subconfigure.py
@@ -1,16 +1,17 @@
 # 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 os
+import re
 import subprocess
 import sys
 import pickle
 
 class File(object):
     def __init__(self, path):
         self._path = path
         self._content = open(path, 'rb').read()
@@ -20,17 +21,60 @@ class File(object):
     def update_time(self):
         '''If the file hasn't changed since the instance was created,
            restore its old modification time.'''
         if not os.path.exists(self._path):
             return
         if open(self._path, 'rb').read() == self._content:
             os.utime(self._path, self._times)
 
+
+# As defined in the various sub-configures in the tree
+PRECIOUS_VARS = set([
+    'build_alias',
+    'host_alias',
+    'target_alias',
+    'CC',
+    'CFLAGS',
+    'LDFLAGS',
+    'LIBS',
+    'CPPFLAGS',
+    'CPP',
+    'CCC',
+    'CXXFLAGS',
+    'CXX',
+    'CCASFLAGS',
+    'CCAS',
+])
+
+
+# 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():
+    comment = re.compile(r'^\s+#')
+    cache = {}
+    with open('config.cache') as f:
+        for line in f.readlines():
+            if not comment.match(line) and '=' in line:
+                key, value = line.split('=', 1)
+                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]):
+            os.remove('config.cache')
+            return
+
+
 def dump(dump_file, shell):
+    if os.path.exists('config.cache'):
+        maybe_clear_cache()
     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