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.
15 def __init__(self
, path
):
17 self
._content
= open(path
, 'rb').read()
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
):
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
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+#')
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)
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')
70 def dump(dump_file
, shell
):
71 if os
.path
.exists('config.cache'):
73 if not os
.path
.exists('config.status'):
74 if os
.path
.exists(dump_file
):
78 config_files
= [File('config.status')]
80 # Scan the config.status output for information about configuration files
82 config_status_output
= subprocess
.check_output(
83 [shell
, '-c', './config.status --help'],
84 stderr
=subprocess
.STDOUT
).splitlines()
86 for line
in config_status_output
:
87 if line
.startswith('Configuration') and line
.endswith(':'):
89 elif not line
.startswith(' '):
91 elif state
== 'config':
92 for f
in (couple
.split(':')[0] for couple
in line
.split()):
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
):
107 with
open(dump_file
, 'rb') as f
:
108 config_files
= pickle
.load(f
)
112 for f
in config_files
:
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':