Bug 932076 - Add check for MediaExtractor creation failure. r=doublec
[gecko.git] / build / subconfigure.py
blob17ef57d0bd44dd38885bdcfeb7aa51ce6c815c5a
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 # This script is used to capture the content of config.status-generated
6 # files and subsequently restore their timestamp if they haven't changed.
8 import os
9 import re
10 import subprocess
11 import sys
12 import pickle
14 class File(object):
15 def __init__(self, path):
16 self._path = path
17 self._content = open(path, 'rb').read()
18 stat = os.stat(path)
19 self._times = (stat.st_atime, stat.st_mtime)
21 def update_time(self):
22 '''If the file hasn't changed since the instance was created,
23 restore its old modification time.'''
24 if not os.path.exists(self._path):
25 return
26 if open(self._path, 'rb').read() == self._content:
27 os.utime(self._path, self._times)
30 # As defined in the various sub-configures in the tree
31 PRECIOUS_VARS = set([
32 'build_alias',
33 'host_alias',
34 'target_alias',
35 'CC',
36 'CFLAGS',
37 'LDFLAGS',
38 'LIBS',
39 'CPPFLAGS',
40 'CPP',
41 'CCC',
42 'CXXFLAGS',
43 'CXX',
44 'CCASFLAGS',
45 'CCAS',
49 # Autoconf, in some of the sub-configures used in the tree, likes to error
50 # out when "precious" variables change in value. The solution it gives to
51 # straighten things is to either run make distclean or remove config.cache.
52 # There's no reason not to do the latter automatically instead of failing,
53 # doing the cleanup (which, on buildbots means a full clobber), and
54 # restarting from scratch.
55 def maybe_clear_cache():
56 comment = re.compile(r'^\s+#')
57 cache = {}
58 with open('config.cache') as f:
59 for line in f.readlines():
60 if not comment.match(line) and '=' in line:
61 key, value = line.split('=', 1)
62 cache[key] = value
63 for precious in PRECIOUS_VARS:
64 entry = 'ac_cv_env_%s_value' % precious
65 if entry in cache and (not precious in os.environ or os.environ[precious] != cache[entry]):
66 os.remove('config.cache')
67 return
70 def dump(dump_file, shell):
71 if os.path.exists('config.cache'):
72 maybe_clear_cache()
73 if not os.path.exists('config.status'):
74 if os.path.exists(dump_file):
75 os.remove(dump_file)
76 return
78 config_files = [File('config.status')]
80 # Scan the config.status output for information about configuration files
81 # it generates.
82 config_status_output = subprocess.check_output(
83 [shell, '-c', './config.status --help'],
84 stderr=subprocess.STDOUT).splitlines()
85 state = None
86 for line in config_status_output:
87 if line.startswith('Configuration') and line.endswith(':'):
88 state = 'config'
89 elif not line.startswith(' '):
90 state = None
91 elif state == 'config':
92 for f in (couple.split(':')[0] for couple in line.split()):
93 if os.path.isfile(f):
94 config_files.append(File(f))
96 with open(dump_file, 'wb') as f:
97 pickle.dump(config_files, f)
100 def adjust(dump_file):
101 if not os.path.exists(dump_file):
102 return
104 config_files = []
106 try:
107 with open(dump_file, 'rb') as f:
108 config_files = pickle.load(f)
109 except Exception:
110 pass
112 for f in config_files:
113 f.update_time()
115 os.remove(dump_file)
118 CONFIG_DUMP = 'config_files.pkl'
120 if __name__ == '__main__':
121 if sys.argv[1] == 'dump':
122 dump(CONFIG_DUMP, sys.argv[2])
123 elif sys.argv[1] == 'adjust':
124 adjust(CONFIG_DUMP)