Bug 1468402 - Part 3: Add test for subgrids in the grid list. r=pbro
[gecko.git] / js / sub.configure
blob242a7568a6468269aa5d087f12ef8ab6fcee8c45
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')
7 @imports('errno')
8 @imports('itertools')
9 @imports('logging')
10 @imports('os')
11 @imports('pickle')
12 @imports('subprocess')
13 @imports('sys')
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):
26             self._fh = fh
27             self._begin_line = True
28             self._prefix = prefix
30         def write(self, content):
31             if self._begin_line:
32                 self._fh.write(self._prefix)
33             self._fh.write(('\n' + self._prefix).join(content.splitlines()))
34             self._begin_line = content.endswith('\n')
35             if self._begin_line:
36                 self._fh.write('\n')
38         def flush(self):
39             self._fh.flush()
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)
54     options = [
55         o for o in prepare_configure_options.options
56         # --with-system-nspr will have been converted into the relevant $NSPR_CFLAGS
57         # and $NSPR_LIBS.
58         if not o.startswith('--with-system-nspr')
59     ]
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'):
65         options.append(
66             '--with-nspr-cflags=%s' % ' '.join(substs.get('NSPR_CFLAGS', [])))
67         options.append(
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
80     # all awkward.
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
93     # in `substs`.
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:
103             value = substs[var]
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]
109         else:
110             continue
111         if isinstance(value, list):
112             value = ' '.join(value)
113         environ[var] = 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')
121     previous_args = None
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)
129     try:
130         os.makedirs(objdir)
131     except OSError as e:
132         if e.errno != errno.EEXIST:
133             raise
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
147     else:
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
151         else:
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
160     ret = 0
161     if not skip_configure:
162         oldpwd = os.getcwd()
163         os.chdir(objdir)
164         command = [
165             os.path.join(build_env.topsrcdir, 'configure.py'),
166             '--enable-project=js',
167         ]
168         environ['OLD_CONFIGURE'] = os.path.join(
169             os.path.dirname(configure), 'old-configure')
170         command += options
171         command += ['--cache-file=%s' % cache_file]
173         log.info('configuring')
174         log.info('running %s' % ' '.join(command[:-1]))
175         config = {}
176         sandbox = ConfigureSandbox(config, environ, command, logger=logger)
177         sandbox.run(os.path.join(build_env.topsrcdir, 'moz.configure'))
178         ret = config_status(config)
179         os.chdir(oldpwd)
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
189     return ret