@imports(_from='os.path', _import='getmtime')
@imports(_from='os.path', _import='exists')
@imports(_from='mozbuild.shellutil', _import='quote')
+@imports(_from='tempfile', _import='NamedTemporaryFile')
+@imports(_from='os', _import='remove')
+@imports(_from='os', _import='rename')
+@imports(_from='__builtin__', _import='OSError')
def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell,
old_configure_assignments, build_project):
# os.path.abspath in the sandbox will ensure forward slashes on Windows,
# This could be done with a m4 macro, but it's way easier this way
script = script.replace('>./config.log', '>>${CONFIG_LOG=./config.log}')
- with open(old_configure, 'wb') as fh:
+ with NamedTemporaryFile(mode='wb', prefix=os.path.basename(old_configure),
+ dir=os.path.dirname(old_configure), delete=False) as fh:
fh.write(script)
+ try:
+ rename(fh.name, old_configure)
+ except OSError:
+ try:
+ # Likely the file already existed (on Windows). Retry after removing it.
+ remove(old_configure)
+ rename(fh.name, old_configure)
+ except OSError:
+ die('Failed creating old-configure')
+
cmd = [shell, old_configure]
with encoded_open('old-configure.vars', 'w') as out:
log.debug('Injecting the following to old-configure:')