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 @depends(check_build_environment, prepare_configure_options, prepare_mozconfig,
6 old_configure, old_configure_assignments, '--cache-file')
12 @imports('subprocess')
14 @imports(_from='__main__', _import='config_status')
15 @imports(_from='__builtin__', _import='OSError')
16 @imports(_from='__builtin__', _import='open')
17 @imports(_from='__builtin__', _import='object')
18 @imports(_from='mozbuild.configure', _import='ConfigureSandbox')
19 @imports(_from='mozbuild.configure.util', _import='ConfigureOutputHandler')
20 @imports(_from='mozbuild.util', _import='encode')
21 def js_subconfigure(build_env, prepare_configure_options, 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)
51 if prepare_configure_options.extra_env:
52 environ.update(prepare_configure_options.extra_env)
55 o for o in prepare_configure_options.options
56 # --with-system-nspr will have been converted into the relevant $NSPR_CFLAGS
58 if not o.startswith('--with-system-nspr')
61 if not substs.get('ENABLE_INTL_API'):
62 options.append('--without-intl-api')
64 if substs.get('NSPR_CFLAGS') or substs.get('NSPR_LIBS'):
66 '--with-nspr-cflags=%s' % ' '.join(substs.get('NSPR_CFLAGS', [])))
68 '--with-nspr-libs=%s' % ' '.join(substs.get('NSPR_LIBS', [])))
70 options.append('--prefix=%s/dist' % build_env.topobjdir)
72 if substs.get('ZLIB_IN_MOZGLUE'):
73 substs['MOZ_ZLIB_LIBS'] = ''
75 environ['MOZILLA_CENTRAL_PATH'] = build_env.topsrcdir
76 if 'MOZ_BUILD_APP' in environ:
77 del environ['MOZ_BUILD_APP']
79 # Here, we mimic what we used to do from old-configure, which makes this
82 # The following variables were saved at the beginning of old-configure,
83 # and restored before invoking the subconfigure. Which means their value
84 # should be taken from the old_configure_assignments or mozconfig.
85 from_assignment = set(
86 ('CC', 'CXX', 'CPPFLAGS', 'CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'HOST_CC',
87 'HOST_CXXFLAGS', 'HOST_LDFLAGS'))
89 # Variables that were explicitly exported from old-configure, and those
90 # explicitly set in the environment when invoking old-configure, were
91 # automatically inherited from subconfigure. We assume the relevant ones
92 # have a corresponding AC_SUBST in old-configure, making them available
94 for var in itertools.chain((
95 'MOZ_SYSTEM_ZLIB', 'MOZ_ZLIB_CFLAGS', 'MOZ_ZLIB_LIBS',
96 'MOZ_APP_NAME', 'MOZ_APP_REMOTINGNAME', 'MOZ_DEV_EDITION',
97 'STLPORT_LIBS', 'DIST', 'MOZ_LINKER', 'ZLIB_IN_MOZGLUE', 'RANLIB',
98 'AR', 'CPP', 'CC', 'CXX', 'CPPFLAGS', 'CFLAGS', 'CXXFLAGS',
99 'LDFLAGS', 'HOST_CC', 'HOST_CXX', 'HOST_CPPFLAGS',
100 'HOST_CXXFLAGS', 'HOST_LDFLAGS'
101 ), prepare_configure_options.extra_env):
102 if var not in from_assignment and var in substs:
104 elif var in assignments:
105 value = assignments[var]
106 elif mozconfig and var in mozconfig and \
107 not mozconfig[var][1].startswith('removed'):
108 value = mozconfig[var][0]
111 if isinstance(value, list):
112 value = ' '.join(value)
115 options.append('JS_STANDALONE=')
117 srcdir = os.path.join(build_env.topsrcdir, 'js', 'src')
118 objdir = os.path.join(build_env.topobjdir, 'js', 'src')
120 data_file = os.path.join(objdir, 'configure.pkl')
122 if os.path.exists(data_file):
123 with open(data_file, 'rb') as f:
124 previous_args = pickle.load(f)
126 cache_file = cache_file or './config.cache'
127 cache_file = os.path.join(build_env.topobjdir, cache_file)
132 if e.errno != errno.EEXIST:
135 with open(data_file, 'wb') as f:
136 pickle.dump(options, f)
138 # Only run configure if one of the following is true:
139 # - config.status doesn't exist
140 # - config.status is older than an input to configure
141 # - the configure arguments changed
142 configure = os.path.join(srcdir, 'old-configure')
143 config_status_path = os.path.join(objdir, 'config.status')
144 skip_configure = True
145 if not os.path.exists(config_status_path):
146 skip_configure = False
148 config_status_deps = os.path.join(objdir, 'config_status_deps.in')
149 if not os.path.exists(config_status_deps):
150 skip_configure = False
152 with open(config_status_deps, 'r') as fh:
153 dep_files = fh.read().splitlines() + [configure]
154 if (any(not os.path.exists(f) or
155 (os.path.getmtime(config_status_path) < os.path.getmtime(f))
156 for f in dep_files) or
157 ((previous_args or options) != options)):
158 skip_configure = False
161 if not skip_configure:
165 os.path.join(build_env.topsrcdir, 'configure.py'),
166 '--enable-project=js',
168 environ['OLD_CONFIGURE'] = os.path.join(
169 os.path.dirname(configure), 'old-configure')
171 command += ['--cache-file=%s' % cache_file]
173 log.info('configuring')
174 log.info('running %s' % ' '.join(command[:-1]))
176 sandbox = ConfigureSandbox(config, environ, command, logger=logger)
177 sandbox.run(os.path.join(build_env.topsrcdir, 'moz.configure'))
178 ret = config_status(config)
181 # Restore unprefixed logging.
182 formatter = logging.Formatter('%(levelname)s: %(message)s')
183 for handler in logger.handlers:
184 handler.setFormatter(formatter)
185 if isinstance(handler, ConfigureOutputHandler):
186 handler._stdout.flush()
187 handler._stdout = handler._stdout._fh