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_APP_NAME', 'MOZ_APP_REMOTINGNAME', 'MOZ_DEV_EDITION',
81 'STLPORT_LIBS', 'DIST', 'MOZ_LINKER', 'ZLIB_IN_MOZGLUE', 'RANLIB',
82 'AR', 'CPP', 'CC', 'CXX', 'CPPFLAGS', 'CFLAGS', 'CXXFLAGS',
83 'LDFLAGS', 'HOST_CC', 'HOST_CXX', 'HOST_CPPFLAGS',
84 'HOST_CXXFLAGS', 'HOST_LDFLAGS'
86 if var not in from_assignment and var in substs:
88 elif var in assignments:
89 value = assignments[var]
90 elif mozconfig and var in mozconfig and \
91 not mozconfig[var][1].startswith('removed'):
92 value = mozconfig[var][0]
95 if isinstance(value, list):
96 value = ' '.join(value)
99 options.append('JS_STANDALONE=')
101 srcdir = os.path.join(build_env.topsrcdir, 'js', 'src')
102 objdir = os.path.join(build_env.topobjdir, 'js', 'src')
104 data_file = os.path.join(objdir, 'configure.pkl')
106 if os.path.exists(data_file):
107 with open(data_file, 'rb') as f:
108 previous_args = pickle.load(f)
110 cache_file = cache_file[0] if cache_file else './config.cache'
111 cache_file = os.path.join(build_env.topobjdir, cache_file)
116 if e.errno != errno.EEXIST:
119 with open(data_file, 'wb') as f:
120 pickle.dump(options, f)
122 # Only run configure if one of the following is true:
123 # - config.status doesn't exist
124 # - config.status is older than an input to configure
125 # - the configure arguments changed
126 configure = os.path.join(srcdir, 'old-configure')
127 config_status_path = os.path.join(objdir, 'config.status')
128 skip_configure = True
129 if not os.path.exists(config_status_path):
130 skip_configure = False
132 config_status_deps = os.path.join(objdir, 'config_status_deps.in')
133 if not os.path.exists(config_status_deps):
134 skip_configure = False
136 with open(config_status_deps, 'r') as fh:
137 dep_files = fh.read().splitlines() + [configure]
138 if (any(not os.path.exists(f) or
139 (os.path.getmtime(config_status_path) < os.path.getmtime(f))
140 for f in dep_files) or
141 ((previous_args or options) != options)):
142 skip_configure = False
145 if not skip_configure:
149 os.path.join(build_env.topsrcdir, 'configure.py'),
150 '--enable-project=js',
152 environ['OLD_CONFIGURE'] = os.path.join(
153 os.path.dirname(configure), 'old-configure')
155 command += ['--cache-file=%s' % cache_file]
157 log.info('configuring')
158 log.info('running %s' % ' '.join(command[:-1]))
160 sandbox = ConfigureSandbox(config, environ, command, logger=logger)
161 sandbox.run(os.path.join(build_env.topsrcdir, 'moz.configure'))
162 ret = config_status(config)
165 # Restore unprefixed logging.
166 formatter = logging.Formatter('%(levelname)s: %(message)s')
167 for handler in logger.handlers:
168 handler.setFormatter(formatter)
169 if isinstance(handler, ConfigureOutputHandler):
170 handler._stdout.flush()
171 handler._stdout = handler._stdout._fh