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 # Combined with build/autoconf/config.status.m4, ConfigStatus is an almost
6 # drop-in replacement for autoconf 2.13's config.status, with features
7 # borrowed from autoconf > 2.5, and additional features.
9 from __future__
import print_function
15 from optparse
import OptionParser
17 from mach
.logging
import LoggingManager
18 from mozbuild
.backend
.configenvironment
import ConfigEnvironment
19 from mozbuild
.backend
.recursivemake
import RecursiveMakeBackend
20 from mozbuild
.frontend
.emitter
import TreeMetadataEmitter
21 from mozbuild
.frontend
.reader
import BuildReader
22 from mozbuild
.mozinfo
import write_mozinfo
25 log_manager
= LoggingManager()
28 def config_status(topobjdir
='.', topsrcdir
='.',
29 defines
=[], non_global_defines
=[], substs
=[]):
30 '''Main function, providing config.status functionality.
32 Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
35 Without the -n option, this program acts as config.status and considers
36 the current directory as the top object directory, even when config.status
37 is in a different directory. It will, however, treat the directory
38 containing config.status as the top object directory with the -n option.
40 The --recheck option, like with the original config.status, runs configure
41 again, with the options given in the "ac_configure_args" subst.
43 The options to this function are passed when creating the
44 ConfigEnvironment. These lists, as well as the actual wrapper script
45 around this function, are meant to be generated by configure.
46 See build/autoconf/config.status.m4.
49 if 'CONFIG_FILES' in os
.environ
:
50 raise Exception('Using the CONFIG_FILES environment variable is not '
52 if 'CONFIG_HEADERS' in os
.environ
:
53 raise Exception('Using the CONFIG_HEADERS environment variable is not '
56 if not os
.path
.isabs(topsrcdir
):
57 raise Exception('topsrcdir must be defined as an absolute directory: '
60 parser
= OptionParser()
61 parser
.add_option('--recheck', dest
='recheck', action
='store_true',
62 help='update config.status by reconfiguring in the same conditions')
63 parser
.add_option('-v', '--verbose', dest
='verbose', action
='store_true',
64 help='display verbose output')
65 parser
.add_option('-n', dest
='not_topobjdir', action
='store_true',
66 help='do not consider current directory as top object directory')
67 (options
, args
) = parser
.parse_args()
69 # Without -n, the current directory is meant to be the top object directory
70 if not options
.not_topobjdir
:
71 topobjdir
= os
.path
.abspath('.')
73 env
= ConfigEnvironment(topsrcdir
, topobjdir
, defines
=defines
,
74 non_global_defines
=non_global_defines
, substs
=substs
)
76 # mozinfo.json only needs written if configure changes and configure always
77 # passes this environment variable.
78 if 'WRITE_MOZINFO' in os
.environ
:
79 write_mozinfo(os
.path
.join(topobjdir
, 'mozinfo.json'), env
, os
.environ
)
81 reader
= BuildReader(env
)
82 emitter
= TreeMetadataEmitter(env
)
83 backend
= RecursiveMakeBackend(env
)
84 # This won't actually do anything because of the magic of generators.
85 definitions
= emitter
.emit(reader
.read_topsrcdir())
88 # Execute configure from the top object directory
90 os
.execlp('sh', 'sh', '-c', ' '.join([os
.path
.join(topsrcdir
, 'configure'), env
.substs
['ac_configure_args'], '--no-create', '--no-recursion']))
92 log_level
= logging
.DEBUG
if options
.verbose
else logging
.INFO
93 log_manager
.add_terminal_logging(level
=log_level
)
94 log_manager
.enable_unstructured()
96 print('Reticulating splines...', file=sys
.stderr
)
97 summary
= backend
.consume(definitions
)
99 for line
in summary
.summaries():
100 print(line
, file=sys
.stderr
)