mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
1e15ba1bf0
The code only actually handles autoconf 2.5 cache, and was useful when we have such subconfigures, that would die when things changed in ways that would make the subconfigure abort on its own. But we have no such things left, and while we may want to clear the cache for old-configure (for e.g. bug 1520232), this is not helping to get there. Differential Revision: https://phabricator.services.mozilla.com/D16636 --HG-- extra : moz-landing-system : lando
144 lines
4.9 KiB
Python
144 lines
4.9 KiB
Python
# 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 errno
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import pickle
|
|
|
|
import mozpack.path as mozpath
|
|
|
|
|
|
CONFIGURE_DATA = 'configure.pkl'
|
|
|
|
|
|
def prepare(srcdir, objdir, args):
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--cache-file', type=str)
|
|
# The --srcdir argument is simply ignored. It's a useless autoconf feature
|
|
# that we don't support well anyways. This makes it stripped from `others`
|
|
# and allows to skip setting it when calling the subconfigure (configure
|
|
# will take it from the configure path anyways).
|
|
parser.add_argument('--srcdir', type=str)
|
|
|
|
data_file = os.path.join(objdir, CONFIGURE_DATA)
|
|
previous_args = None
|
|
if os.path.exists(data_file):
|
|
with open(data_file, 'rb') as f:
|
|
data = pickle.load(f)
|
|
previous_args = data['args']
|
|
|
|
args, others = parser.parse_known_args(args)
|
|
|
|
data = {
|
|
'args': others,
|
|
'srcdir': srcdir,
|
|
'objdir': objdir,
|
|
'env': os.environ,
|
|
}
|
|
|
|
if args.cache_file:
|
|
data['cache-file'] = mozpath.normpath(mozpath.join(os.getcwd(),
|
|
args.cache_file))
|
|
else:
|
|
data['cache-file'] = mozpath.join(objdir, 'config.cache')
|
|
|
|
if previous_args is not None:
|
|
data['previous-args'] = previous_args
|
|
|
|
try:
|
|
os.makedirs(objdir)
|
|
except OSError as e:
|
|
if e.errno != errno.EEXIST:
|
|
raise
|
|
|
|
with open(data_file, 'wb') as f:
|
|
pickle.dump(data, f)
|
|
|
|
return data
|
|
|
|
|
|
def prefix_lines(text, prefix):
|
|
return ''.join('%s> %s' % (prefix, line) for line in text.splitlines(True))
|
|
|
|
|
|
def execute_and_prefix(*args, **kwargs):
|
|
prefix = kwargs['prefix']
|
|
del kwargs['prefix']
|
|
proc = subprocess.Popen(*args, stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT, **kwargs)
|
|
while True:
|
|
line = proc.stdout.readline()
|
|
if not line:
|
|
break
|
|
print(prefix_lines(line.rstrip(), prefix))
|
|
sys.stdout.flush()
|
|
return proc.wait()
|
|
|
|
|
|
def run(data):
|
|
objdir = data['objdir']
|
|
relobjdir = data['relobjdir'] = os.path.relpath(objdir, os.getcwd())
|
|
|
|
cache_file = data['cache-file']
|
|
|
|
# Only run configure if one of the following is true:
|
|
# - config.status doesn't exist
|
|
# - config.status is older than an input to configure
|
|
# - the configure arguments changed
|
|
configure = mozpath.join(data['srcdir'], 'old-configure')
|
|
config_status_path = mozpath.join(objdir, 'config.status')
|
|
skip_configure = True
|
|
if not os.path.exists(config_status_path):
|
|
skip_configure = False
|
|
else:
|
|
config_status_deps = mozpath.join(objdir, 'config_status_deps.in')
|
|
if not os.path.exists(config_status_deps):
|
|
skip_configure = False
|
|
else:
|
|
with open(config_status_deps, 'r') as fh:
|
|
dep_files = fh.read().splitlines() + [configure]
|
|
if (any(not os.path.exists(f) or
|
|
(os.path.getmtime(config_status_path) < os.path.getmtime(f))
|
|
for f in dep_files) or
|
|
data.get('previous-args', data['args']) != data['args']):
|
|
skip_configure = False
|
|
|
|
if not skip_configure:
|
|
# Because configure is a shell script calling a python script
|
|
# calling a shell script, on Windows, with msys screwing the
|
|
# environment, we lose the benefits from our own efforts in this
|
|
# script to get past the msys problems. So manually call the python
|
|
# script instead, so that we don't do a native->msys transition
|
|
# here. Then the python configure will still have the right
|
|
# environment when calling the shell configure.
|
|
command = [
|
|
sys.executable,
|
|
os.path.join(os.path.dirname(__file__), '..', 'configure.py'),
|
|
'--enable-project=js',
|
|
]
|
|
data['env']['OLD_CONFIGURE'] = os.path.join(
|
|
os.path.dirname(configure), 'old-configure')
|
|
command += data['args']
|
|
command += ['--cache-file=%s' % cache_file]
|
|
|
|
# Pass --no-create to configure so that it doesn't run config.status.
|
|
# We're going to run it ourselves.
|
|
command += ['--no-create']
|
|
|
|
print(prefix_lines('configuring', relobjdir))
|
|
print(prefix_lines('running %s' % ' '.join(command[:-1]), relobjdir))
|
|
sys.stdout.flush()
|
|
returncode = execute_and_prefix(command, cwd=objdir, env=data['env'],
|
|
prefix=relobjdir)
|
|
if returncode:
|
|
return returncode
|
|
|
|
return 0
|