Source code

Revision control

Other Tools

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/.
4
5
@depends(check_build_environment, prepare_configure_options, prepare_mozconfig,
6
old_configure, old_configure_assignments, '--cache-file')
7
@imports('errno')
8
@imports('itertools')
9
@imports('logging')
10
@imports('os')
11
@imports('pickle')
12
@imports('sys')
13
@imports(_from='__main__', _import='config_status')
14
@imports(_from='__builtin__', _import='OSError')
15
@imports(_from='__builtin__', _import='open')
16
@imports(_from='__builtin__', _import='object')
17
@imports(_from='mozbuild.configure', _import='ConfigureSandbox')
18
@imports(_from='mozbuild.configure.util', _import='ConfigureOutputHandler')
19
def js_subconfigure(build_env, prepare_configure_options, mozconfig,
20
old_configure, old_configure_assignments, cache_file):
21
22
class PrefixOutput(object):
23
def __init__(self, prefix, fh):
24
self._fh = fh
25
self._begin_line = True
26
self._prefix = prefix
27
28
def write(self, content):
29
if self._begin_line:
30
self._fh.write(self._prefix)
31
self._fh.write(('\n' + self._prefix).join(content.splitlines()))
32
self._begin_line = content.endswith('\n')
33
if self._begin_line:
34
self._fh.write('\n')
35
36
def flush(self):
37
self._fh.flush()
38
39
logger = logging.getLogger('moz.configure')
40
formatter = logging.Formatter('js/src> %(levelname)s: %(message)s')
41
for handler in logger.handlers:
42
handler.setFormatter(formatter)
43
if isinstance(handler, ConfigureOutputHandler):
44
handler._stdout = PrefixOutput('js/src> ', handler._stdout)
45
46
substs = dict(old_configure['substs'])
47
assignments = dict(old_configure_assignments)
48
environ = dict(os.environ)
49
if prepare_configure_options.extra_env:
50
environ.update(prepare_configure_options.extra_env)
51
52
options = [
53
o for o in prepare_configure_options.options
54
# --with-system-nspr will have been converted into the relevant $NSPR_CFLAGS
55
# and $NSPR_LIBS.
56
if not o.startswith('--with-system-nspr')
57
]
58
59
if not substs.get('ENABLE_INTL_API'):
60
options.append('--without-intl-api')
61
62
if substs.get('NSPR_CFLAGS') or substs.get('NSPR_LIBS'):
63
options.append(
64
'--with-nspr-cflags=%s' % ' '.join(substs.get('NSPR_CFLAGS', [])))
65
options.append(
66
'--with-nspr-libs=%s' % ' '.join(substs.get('NSPR_LIBS', [])))
67
68
options.append('--prefix=%s/dist' % build_env.topobjdir)
69
70
if substs.get('ZLIB_IN_MOZGLUE'):
71
substs['MOZ_ZLIB_LIBS'] = ''
72
73
environ['MOZILLA_CENTRAL_PATH'] = build_env.topsrcdir
74
if 'MOZ_BUILD_APP' in environ:
75
del environ['MOZ_BUILD_APP']
76
77
# Here, we mimic what we used to do from old-configure, which makes this
78
# all awkward.
79
80
# The following variables were saved at the beginning of old-configure,
81
# and restored before invoking the subconfigure. Which means their value
82
# should be taken from the old_configure_assignments or mozconfig.
83
from_assignment = set(
84
('CC', 'CXX', 'CPPFLAGS', 'CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'HOST_CC',
85
'HOST_CXXFLAGS', 'HOST_LDFLAGS'))
86
87
# Variables that were explicitly exported from old-configure, and those
88
# explicitly set in the environment when invoking old-configure, were
89
# automatically inherited from subconfigure. We assume the relevant ones
90
# have a corresponding AC_SUBST in old-configure, making them available
91
# in `substs`.
92
for var in itertools.chain((
93
'MOZ_SYSTEM_ZLIB', 'MOZ_ZLIB_CFLAGS', 'MOZ_ZLIB_LIBS',
94
'MOZ_APP_NAME', 'MOZ_APP_REMOTINGNAME', 'MOZ_DEV_EDITION',
95
'STLPORT_LIBS', 'DIST', 'MOZ_LINKER', 'ZLIB_IN_MOZGLUE', 'RANLIB',
96
'AR', 'CPP', 'CC', 'CXX', 'CPPFLAGS', 'CFLAGS', 'CXXFLAGS',
97
'LDFLAGS', 'HOST_CC', 'HOST_CXX', 'HOST_CPPFLAGS',
98
'HOST_CXXFLAGS', 'HOST_LDFLAGS'
99
), prepare_configure_options.extra_env):
100
if var not in from_assignment and var in substs:
101
value = substs[var]
102
elif var in assignments:
103
value = assignments[var]
104
elif mozconfig and var in mozconfig and \
105
not mozconfig[var][1].startswith('removed'):
106
value = mozconfig[var][0]
107
else:
108
continue
109
if isinstance(value, list):
110
value = ' '.join(value)
111
environ[var] = value
112
113
options.append('JS_STANDALONE=')
114
115
srcdir = os.path.join(build_env.topsrcdir, 'js', 'src')
116
objdir = os.path.join(build_env.topobjdir, 'js', 'src')
117
118
data_file = os.path.join(objdir, 'configure.pkl')
119
previous_args = None
120
if os.path.exists(data_file):
121
with open(data_file, 'rb') as f:
122
previous_args = pickle.load(f)
123
124
cache_file = cache_file or './config.cache'
125
cache_file = os.path.join(build_env.topobjdir, cache_file)
126
127
try:
128
os.makedirs(objdir)
129
except OSError as e:
130
if e.errno != errno.EEXIST:
131
raise
132
133
with open(data_file, 'wb') as f:
134
pickle.dump(options, f)
135
136
# Only run configure if one of the following is true:
137
# - config.status doesn't exist
138
# - config.status is older than an input to configure
139
# - the configure arguments changed
140
configure = os.path.join(srcdir, 'old-configure')
141
config_status_path = os.path.join(objdir, 'config.status')
142
skip_configure = True
143
if not os.path.exists(config_status_path):
144
skip_configure = False
145
else:
146
config_status_deps = os.path.join(objdir, 'config_status_deps.in')
147
if not os.path.exists(config_status_deps):
148
skip_configure = False
149
else:
150
with open(config_status_deps, 'r') as fh:
151
dep_files = fh.read().splitlines() + [configure]
152
if (any(not os.path.exists(f) or
153
(os.path.getmtime(config_status_path) < os.path.getmtime(f))
154
for f in dep_files) or
155
((previous_args or options) != options)):
156
skip_configure = False
157
158
ret = 0
159
if not skip_configure:
160
oldpwd = os.getcwd()
161
os.chdir(objdir)
162
command = [
163
os.path.join(build_env.topsrcdir, 'configure.py'),
164
'--enable-project=js',
165
]
166
environ['OLD_CONFIGURE'] = os.path.join(
167
os.path.dirname(configure), 'old-configure')
168
command += options
169
command += ['--cache-file=%s' % cache_file]
170
171
log.info('configuring')
172
log.info('running %s' % ' '.join(command[:-1]))
173
config = {}
174
sandbox = ConfigureSandbox(config, environ, command, logger=logger)
175
sandbox.run(os.path.join(build_env.topsrcdir, 'moz.configure'))
176
ret = config_status(config)
177
os.chdir(oldpwd)
178
179
# Restore unprefixed logging.
180
formatter = logging.Formatter('%(levelname)s: %(message)s')
181
for handler in logger.handlers:
182
handler.setFormatter(formatter)
183
if isinstance(handler, ConfigureOutputHandler):
184
handler._stdout.flush()
185
handler._stdout = handler._stdout._fh
186
187
return ret