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 files
= [], headers
= []):
31 '''Main function, providing config.status functionality.
33 Contrary to config.status, it doesn't use CONFIG_FILES or CONFIG_HEADERS
34 variables, but like config.status from autoconf 2.6, single files may be
35 generated with the --file and --header options. Several such options can
36 be given to generate several files at the same time.
38 Without the -n option, this program acts as config.status and considers
39 the current directory as the top object directory, even when config.status
40 is in a different directory. It will, however, treat the directory
41 containing config.status as the top object directory with the -n option,
42 while files given to the --file and --header arguments are considered
43 relative to the current directory.
45 The --recheck option, like with the original config.status, runs configure
46 again, with the options given in the "ac_configure_args" subst.
48 The options to this function are passed when creating the
49 ConfigEnvironment, except for files and headers, which contain the list
50 of files and headers to be generated by default. These lists, as well as
51 the actual wrapper script around this function, are meant to be generated
52 by configure. See build/autoconf/config.status.m4.
54 Unlike config.status behaviour with CONFIG_FILES and CONFIG_HEADERS,
55 but like config.status behaviour with --file and --header, providing
56 files or headers on the command line inhibits the default generation of
57 files when given headers and headers when given files.
59 Unlike config.status, the FILE:TEMPLATE syntax is not supported for
60 files and headers. The template is always the filename suffixed with
61 '.in', in the corresponding directory under the top source directory.
64 if 'CONFIG_FILES' in os
.environ
:
65 raise Exception, 'Using the CONFIG_FILES environment variable is not supported. Use --file instead.'
66 if 'CONFIG_HEADERS' in os
.environ
:
67 raise Exception, 'Using the CONFIG_HEADERS environment variable is not supported. Use --header instead.'
69 parser
= OptionParser()
70 parser
.add_option('--recheck', dest
='recheck', action
='store_true',
71 help='update config.status by reconfiguring in the same conditions')
72 parser
.add_option('--file', dest
='files', metavar
='FILE', action
='append',
73 help='instantiate the configuration file FILE')
74 parser
.add_option('--header', dest
='headers', metavar
='FILE', action
='append',
75 help='instantiate the configuration header FILE')
76 parser
.add_option('-v', '--verbose', dest
='verbose', action
='store_true',
77 help='display verbose output')
78 parser
.add_option('-n', dest
='not_topobjdir', action
='store_true',
79 help='do not consider current directory as top object directory')
80 (options
, args
) = parser
.parse_args()
82 # Without -n, the current directory is meant to be the top object directory
83 if not options
.not_topobjdir
:
84 topobjdir
= os
.path
.abspath('.')
86 env
= ConfigEnvironment(topsrcdir
, topobjdir
, defines
=defines
,
87 non_global_defines
=non_global_defines
, substs
=substs
)
89 # mozinfo.json only needs written if configure changes and configure always
90 # passes this environment variable.
91 if 'WRITE_MOZINFO' in os
.environ
:
92 write_mozinfo(os
.path
.join(topobjdir
, 'mozinfo.json'), env
, os
.environ
)
94 reader
= BuildReader(env
)
95 emitter
= TreeMetadataEmitter(env
)
96 backend
= RecursiveMakeBackend(env
)
97 # This won't actually do anything because of the magic of generators.
98 definitions
= emitter
.emit(reader
.read_topsrcdir())
101 # Execute configure from the top object directory
102 if not os
.path
.isabs(topsrcdir
):
103 topsrcdir
= relpath(topsrcdir
, topobjdir
)
105 os
.execlp('sh', 'sh', '-c', ' '.join([os
.path
.join(topsrcdir
, 'configure'), env
.substs
['ac_configure_args'], '--no-create', '--no-recursion']))
108 files
= options
.files
111 headers
= options
.headers
112 if not options
.files
:
114 # Default to display messages when giving --file or --headers on the
116 log_level
= logging
.INFO
118 if options
.files
or options
.headers
or options
.verbose
:
119 log_level
= logging
.DEBUG
121 log_manager
.add_terminal_logging(level
=log_level
)
122 log_manager
.enable_unstructured()
124 if not options
.files
and not options
.headers
:
125 print('Reticulating splines...', file=sys
.stderr
)
126 summary
= backend
.consume(definitions
)
128 for line
in summary
.summaries():
129 print(line
, file=sys
.stderr
)
131 files
= [os
.path
.join(topobjdir
, f
) for f
in files
]
132 headers
= [os
.path
.join(topobjdir
, f
) for f
in headers
]
135 env
.create_config_file(file)
136 for header
in headers
:
137 env
.create_config_header(header
)