1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 @depends(host_for_sub_configure, target_for_sub_configure, check_build_environment,
8 js_configure_args, prepare_mozconfig, old_configure,
9 old_configure_assignments, '--cache-file')
15 @imports(_from='__main__', _import='config_status')
16 @imports(_from='__builtin__', _import='OSError')
17 @imports(_from='__builtin__', _import='open')
18 @imports(_from='__builtin__', _import='object')
19 @imports(_from='mozbuild.configure', _import='ConfigureSandbox')
20 @imports(_from='mozbuild.configure.util', _import='ConfigureOutputHandler')
21 def js_subconfigure(host, target, build_env, js_configure_args, mozconfig,
22 old_configure, old_configure_assignments, cache_file):
24 class PrefixOutput(object):
25 def __init__(self, prefix, fh):
27 self._begin_line = True
30 def write(self, content):
32 self._fh.write(self._prefix)
33 self._fh.write(('\n' + self._prefix).join(content.splitlines()))
34 self._begin_line = content.endswith('\n')
41 logger = logging.getLogger('moz.configure')
42 formatter = logging.Formatter('js/src> %(levelname)s: %(message)s')
43 for handler in logger.handlers:
44 handler.setFormatter(formatter)
45 if isinstance(handler, ConfigureOutputHandler):
46 handler._stdout = PrefixOutput('js/src> ', handler._stdout)
48 substs = dict(old_configure['substs'])
49 assignments = dict(old_configure_assignments)
50 environ = dict(os.environ)
52 options = [host, target] + js_configure_args
54 options.append('--prefix=%s/dist' % build_env.topobjdir)
56 if substs.get('ZLIB_IN_MOZGLUE'):
57 substs['MOZ_ZLIB_LIBS'] = ''
59 environ['MOZILLA_CENTRAL_PATH'] = build_env.topsrcdir
60 if 'MOZ_BUILD_APP' in environ:
61 del environ['MOZ_BUILD_APP']
63 # Here, we mimic what we used to do from old-configure, which makes this
66 # The following variables were saved at the beginning of old-configure,
67 # and restored before invoking the subconfigure. Which means their value
68 # should be taken from the old_configure_assignments or mozconfig.
69 from_assignment = set(
70 ('CC', 'CXX', 'CPPFLAGS', 'CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'HOST_CC',
71 'HOST_CXXFLAGS', 'HOST_LDFLAGS'))
73 # Variables that were explicitly exported from old-configure, and those
74 # explicitly set in the environment when invoking old-configure, were
75 # automatically inherited from subconfigure. We assume the relevant ones
76 # have a corresponding AC_SUBST in old-configure, making them available
79 'MOZ_SYSTEM_ZLIB', 'MOZ_ZLIB_CFLAGS', 'MOZ_ZLIB_LIBS',
80 'MOZ_DEV_EDITION', 'STLPORT_LIBS', 'DIST', 'MOZ_LINKER',
81 'ZLIB_IN_MOZGLUE', 'RANLIB', 'AR', 'CPP', 'CC', 'CXX', 'CPPFLAGS',
82 'CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'HOST_CC', 'HOST_CXX', 'HOST_CPPFLAGS',
83 'HOST_CXXFLAGS', 'HOST_LDFLAGS'
85 if var not in from_assignment and var in substs:
87 elif var in assignments:
88 value = assignments[var]
89 elif mozconfig and var in mozconfig and \
90 not mozconfig[var][1].startswith('removed'):
91 value = mozconfig[var][0]
94 if isinstance(value, list):
95 value = ' '.join(value)
98 options.append('JS_STANDALONE=')
100 srcdir = os.path.join(build_env.topsrcdir, 'js', 'src')
101 objdir = os.path.join(build_env.topobjdir, 'js', 'src')
103 data_file = os.path.join(objdir, 'configure.pkl')
105 if os.path.exists(data_file):
106 with open(data_file, 'rb') as f:
107 previous_args = pickle.load(f)
109 cache_file = cache_file[0] if cache_file else './config.cache'
110 cache_file = os.path.join(build_env.topobjdir, cache_file)
115 if e.errno != errno.EEXIST:
118 with open(data_file, 'wb') as f:
119 pickle.dump(options, f)
121 # Only run configure if one of the following is true:
122 # - config.status doesn't exist
123 # - config.status is older than an input to configure
124 # - the configure arguments changed
125 configure = os.path.join(srcdir, 'old-configure')
126 config_status_path = os.path.join(objdir, 'config.status')
127 skip_configure = True
128 if not os.path.exists(config_status_path):
129 skip_configure = False
131 config_status_deps = os.path.join(objdir, 'config_status_deps.in')
132 if not os.path.exists(config_status_deps):
133 skip_configure = False
135 with open(config_status_deps, 'r') as fh:
136 dep_files = fh.read().splitlines() + [configure]
137 if (any(not os.path.exists(f) or
138 (os.path.getmtime(config_status_path) < os.path.getmtime(f))
139 for f in dep_files) or
140 ((previous_args or options) != options)):
141 skip_configure = False
144 if not skip_configure:
148 os.path.join(build_env.topsrcdir, 'configure.py'),
149 '--enable-project=js',
151 environ['OLD_CONFIGURE'] = os.path.join(
152 os.path.dirname(configure), 'old-configure')
154 command += ['--cache-file=%s' % cache_file]
156 log.info('configuring')
157 log.info('running %s' % ' '.join(command[:-1]))
159 sandbox = ConfigureSandbox(config, environ, command, logger=logger)
160 sandbox.run(os.path.join(build_env.topsrcdir, 'moz.configure'))
161 ret = config_status(config)
164 # Restore unprefixed logging.
165 formatter = logging.Formatter('%(levelname)s: %(message)s')
166 for handler in logger.handlers:
167 handler.setFormatter(formatter)
168 if isinstance(handler, ConfigureOutputHandler):
169 handler._stdout.flush()
170 handler._stdout = handler._stdout._fh