Bug 1457047 [wpt PR 10645] - Update webidl2.js to v10.2.1, a=testonly
[gecko.git] / moz.configure
blob7cdf0d9afd435ec1f825362104167fec54c21308
1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 include('build/moz.configure/init.configure')
9 # Note:
10 # - Gecko-specific options and rules should go in toolkit/moz.configure.
11 # - Firefox-specific options and rules should go in browser/moz.configure.
12 # - Fennec-specific options and rules should go in
13 #   mobile/android/moz.configure.
14 # - Spidermonkey-specific options and rules should go in js/moz.configure.
15 # - etc.
17 option('--enable-artifact-builds', env='MOZ_ARTIFACT_BUILDS',
18        help='Download and use prebuilt binary artifacts.')
20 @depends('--enable-artifact-builds')
21 def artifact_builds(value):
22     if value:
23         return True
25 set_config('MOZ_ARTIFACT_BUILDS', artifact_builds)
27 imply_option('--enable-artifact-build-symbols',
28              depends(artifact_builds)(lambda v: False if v is None else None),
29              reason='--disable-artifact-builds')
31 option('--enable-artifact-build-symbols',
32        help='Download symbols when artifact builds are enabled.')
34 set_config('MOZ_ARTIFACT_BUILD_SYMBOLS',
35            depends_if('--enable-artifact-build-symbols')(lambda _: True))
37 @depends('--enable-artifact-builds')
38 def imply_disable_compile_environment(value):
39     if value:
40         return False
42 imply_option('--enable-compile-environment', imply_disable_compile_environment)
44 option('--disable-compile-environment',
45        help='Disable compiler/library checks')
47 @depends('--disable-compile-environment')
48 def compile_environment(compile_env):
49     if compile_env:
50         return True
52 set_config('COMPILE_ENVIRONMENT', compile_environment)
53 add_old_configure_assignment('COMPILE_ENVIRONMENT', compile_environment)
55 js_option('--disable-tests',
56           help='Do not build test libraries & programs')
58 @depends('--disable-tests')
59 def enable_tests(value):
60     if value:
61         return True
63 set_config('ENABLE_TESTS', enable_tests)
64 set_define('ENABLE_TESTS', enable_tests)
66 js_option(env='MOZILLA_OFFICIAL',
67           help='Build an official release')
69 @depends('MOZILLA_OFFICIAL')
70 def mozilla_official(official):
71     if official:
72         return True
74 set_config('MOZILLA_OFFICIAL', mozilla_official)
75 set_define('MOZILLA_OFFICIAL', mozilla_official)
76 add_old_configure_assignment('MOZILLA_OFFICIAL', mozilla_official)
78 @depends(enable_tests)
79 def gtest_has_rtti(value):
80     if value:
81         return '0'
83 set_define('GTEST_HAS_RTTI', gtest_has_rtti)
85 @depends(target, enable_tests)
86 def linux_gtest_defines(target, enable_tests):
87     if enable_tests and target.os == 'Android':
88         return namespace(os_linux_android=True,
89                          use_own_tr1_tuple=True,
90                          has_clone='0')
92 set_define('GTEST_OS_LINUX_ANDROID',
93            linux_gtest_defines.os_linux_android)
94 set_define('GTEST_USE_OWN_TR1_TUPLE',
95            linux_gtest_defines.use_own_tr1_tuple)
96 set_define('GTEST_HAS_CLONE',
97            linux_gtest_defines.has_clone)
99 js_option('--enable-debug',
100           nargs='?',
101           help='Enable building with developer debug info '
102                '(using the given compiler flags).')
104 @depends('--enable-debug')
105 def moz_debug(debug):
106     if debug:
107         return bool(debug)
109 set_config('MOZ_DEBUG', moz_debug)
110 set_define('MOZ_DEBUG', moz_debug)
111 # Override any value MOZ_DEBUG may have from the environment when passing it
112 # down to old-configure.
113 add_old_configure_assignment('MOZ_DEBUG',
114                              depends('--enable-debug')(lambda x: bool(x)))
116 js_option('--enable-rust-debug',
117           help='Build Rust code with debug assertions turned on.')
119 @depends('--enable-rust-debug', '--enable-debug')
120 def debug_rust(value, debug):
121     if value.origin == 'default':
122         return bool(debug) or None
123     elif bool(value):
124         return True
126 set_config('MOZ_DEBUG_RUST', debug_rust)
127 set_define('MOZ_DEBUG_RUST', debug_rust)
129 include('build/moz.configure/pkg.configure')
130 # Make this assignment here rather than in pkg.configure to avoid
131 # requiring this file in unit tests.
132 add_old_configure_assignment('PKG_CONFIG', pkg_config)
134 include('build/moz.configure/toolchain.configure',
135         when='--enable-compile-environment')
136 include('build/moz.configure/memory.configure',
137         when='--enable-compile-environment')
138 include('build/moz.configure/headers.configure',
139         when='--enable-compile-environment')
140 include('build/moz.configure/warnings.configure',
141         when='--enable-compile-environment')
142 include('build/moz.configure/flags.configure',
143         when='--enable-compile-environment')
146 @depends(target, host)
147 def is_openbsd(target, host):
148     return target.kernel == 'OpenBSD' or host.kernel == 'OpenBSD'
150 option(env='SO_VERSION', nargs=1, default='1.0', when=is_openbsd,
151        help='Shared library version for OpenBSD systems')
153 @depends('SO_VERSION', when=is_openbsd)
154 def so_version(value):
155     return value
157 @template
158 def library_name_info_template(host_or_target):
159     assert host_or_target in (host, target)
160     compiler = {
161         host: host_c_compiler,
162         target: c_compiler,
163     }[host_or_target]
165     @depends(host_or_target, compiler, so_version)
166     def library_name_info_impl(host_or_target, compiler, so_version):
167         if host_or_target.kernel == 'WINNT':
168             # There aren't artifacts for mingw builds, so it's OK that the
169             # results are inaccurate in that case.
170             if compiler and compiler.type not in ('msvc', 'clang-cl'):
171                 return namespace(
172                     dll=namespace(prefix='', suffix='.dll'),
173                     lib=namespace(prefix='lib', suffix='a'),
174                     import_lib=namespace(prefix='lib', suffix='a'),
175                     rust_lib=namespace(prefix='', suffix='lib'),
176                     obj=namespace(prefix='', suffix='o'),
177                 )
179             return namespace(
180                 dll=namespace(prefix='', suffix='.dll'),
181                 lib=namespace(prefix='', suffix='lib'),
182                 import_lib=namespace(prefix='', suffix='lib'),
183                 rust_lib=namespace(prefix='', suffix='lib'),
184                 obj=namespace(prefix='', suffix='obj'),
185             )
187         elif host_or_target.kernel == 'Darwin':
188             return namespace(
189                 dll=namespace(prefix='lib', suffix='.dylib'),
190                 lib=namespace(prefix='lib', suffix='a'),
191                 import_lib=namespace(prefix=None, suffix=''),
192                 rust_lib=namespace(prefix='lib', suffix='a'),
193                 obj=namespace(prefix='', suffix='o'),
194             )
195         elif so_version:
196             so = '.so.%s' % so_version
197         else:
198             so = '.so'
200         return namespace(
201             dll=namespace(prefix='lib', suffix=so),
202             lib=namespace(prefix='lib', suffix='a'),
203             import_lib=namespace(prefix=None, suffix=''),
204             rust_lib=namespace(prefix='lib', suffix='a'),
205             obj=namespace(prefix='', suffix='o'),
206         )
208     return library_name_info_impl
210 host_library_name_info = library_name_info_template(host)
211 library_name_info = library_name_info_template(target)
213 set_config('DLL_PREFIX', library_name_info.dll.prefix)
214 set_config('DLL_SUFFIX', library_name_info.dll.suffix)
215 set_config('LIB_PREFIX', library_name_info.lib.prefix)
216 set_config('LIB_SUFFIX', library_name_info.lib.suffix)
217 set_config('RUST_LIB_PREFIX', library_name_info.rust_lib.prefix)
218 set_config('RUST_LIB_SUFFIX', library_name_info.rust_lib.suffix)
219 set_config('OBJ_SUFFIX', library_name_info.obj.suffix)
220 # Lots of compilation tests depend on this variable being present.
221 add_old_configure_assignment('OBJ_SUFFIX', library_name_info.obj.suffix)
222 set_config('IMPORT_LIB_SUFFIX', library_name_info.import_lib.suffix)
223 set_define('MOZ_DLL_SUFFIX', depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s))
225 include(include_project_configure)
227 @depends('--help')
228 @imports(_from='mozbuild.backend', _import='backends')
229 def build_backends_choices(_):
230     return tuple(backends)
233 @deprecated_option('--enable-build-backend', nargs='+',
234                    choices=build_backends_choices)
235 def build_backend(backends):
236     if backends:
237         return tuple('+%s' % b for b in backends)
239 imply_option('--build-backends', build_backend)
242 @depends('--enable-artifact-builds', '--disable-compile-environment', '--help')
243 @imports('sys')
244 def build_backend_defaults(artifact_builds, compile_environment, _):
245     if artifact_builds:
246         all_backends = ['FasterMake+RecursiveMake']
247     else:
248         all_backends = ['RecursiveMake', 'FasterMake']
249     # Normally, we'd use target.os == 'WINNT', but a dependency on target
250     # would require target to depend on --help, as well as host and shell,
251     # and this is not a can of worms we can open at the moment.
252     if sys.platform == 'win32' and compile_environment:
253         all_backends.append('VisualStudio')
254     return tuple(all_backends)
256 option('--build-backends', nargs='+', default=build_backend_defaults,
257        choices=build_backends_choices, help='Build backends to generate')
259 @depends('--build-backends')
260 def build_backends(backends):
261     return backends
263 set_config('BUILD_BACKENDS', build_backends)
265 option('--disable-gtest-in-build',
266        help='Force disable building the gtest libxul during the build.',
267        when='--enable-compile-environment')
269 # Determine whether to build the gtest xul. This happens in automation
270 # on Desktop platforms with the exception of Windows PGO, where linking
271 # xul-gtest.dll takes too long.
272 @depends('MOZ_PGO', build_project, target, 'MOZ_AUTOMATION', '--disable-gtest-in-build',
273          enable_tests, when='--enable-compile-environment')
274 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
275     if not enable_tests or not enabled:
276         return None
277     if (automation and build_project == 'browser' and
278         not (pgo and target.os == 'WINNT')):
279         return True
281 set_config('LINK_GTEST_DURING_COMPILE', build_gtest)
283 # Localization
284 # ==============================================================
285 option('--enable-ui-locale', default='en-US',
286        help='Select the user interface locale (default: en-US)')
288 set_config('MOZ_UI_LOCALE', depends('--enable-ui-locale')(lambda x: x))
290 # clang-plugin location
291 # ==============================================================
292 @depends(library_name_info, check_build_environment, when='--enable-clang-plugin')
293 def clang_plugin_path(library_name_info, build_env):
294     topobjdir = build_env.topobjdir
295     if topobjdir.endswith('/js/src'):
296         topobjdir = topobjdir[:-7]
297     return os.path.abspath(
298         os.path.join(topobjdir, 'build', 'clang-plugin',
299                      '%sclang-plugin%s' % (library_name_info.dll.prefix,
300                                            library_name_info.dll.suffix))
301     )
303 add_old_configure_assignment('CLANG_PLUGIN', clang_plugin_path)
306 # Awk detection
307 # ==============================================================
308 awk = check_prog('AWK', ('gawk', 'mawk', 'nawk', 'awk'))
310 # Until the AWK variable is not necessary in old-configure
311 @depends(awk)
312 def awk_for_old_configure(value):
313     return value
315 add_old_configure_assignment('AWK', awk_for_old_configure)
318 # Perl detection
319 # ==============================================================
320 perl = check_prog('PERL', ('perl5', 'perl'))
322 # Until the PERL variable is not necessary in old-configure
323 @depends(perl)
324 def perl_for_old_configure(value):
325     return value
327 add_old_configure_assignment('PERL', perl_for_old_configure)
329 @template
330 def perl_version_check(min_version):
331     @depends(perl)
332     @checking('for minimum required perl version >= %s' % min_version)
333     def get_perl_version(perl):
334         return Version(check_cmd_output(
335             perl, '-e', 'print $]',
336             onerror=lambda: die('Failed to get perl version.')
337         ))
339     @depends(get_perl_version)
340     def check_perl_version(version):
341         if version < min_version:
342             die('Perl %s or higher is required.', min_version)
344     @depends(perl)
345     @checking('for full perl installation')
346     @imports('subprocess')
347     def has_full_perl_installation(perl):
348         ret = subprocess.call(
349             [perl, '-e', 'use Config; exit(!-d $Config{archlib})'])
350         return ret == 0
352     @depends(has_full_perl_installation)
353     def require_full_perl_installation(has_full_perl_installation):
354         if not has_full_perl_installation:
355             die('Cannot find Config.pm or $Config{archlib}. '
356                 'A full perl installation is required.')
358 perl_version_check('5.006')
361 # GNU make detection
362 # ==============================================================
363 option(env='MAKE', nargs=1, help='Path to GNU make')
365 @depends('MAKE', host)
366 def possible_makes(make, host):
367     candidates = []
368     if host.kernel == 'WINNT':
369         candidates.append('mingw32-make')
370     if make:
371         candidates.append(make[0])
372     if host.kernel == 'WINNT':
373         candidates.extend(('make', 'gmake'))
374     else:
375         candidates.extend(('gmake', 'make'))
376     return candidates
378 check_prog('GMAKE', possible_makes)
380 # tup detection
381 # ==============================================================
382 @depends(build_backends)
383 def tup_progs(build_backends):
384     for backend in build_backends:
385         if 'Tup' in backend:
386             return ['tup']
387     return None
389 tup = check_prog('TUP', tup_progs)
391 # watchman detection
392 # ==============================================================
394 option(env='WATCHMAN', nargs=1, help='Path to the watchman program')
396 @depends('WATCHMAN')
397 @checking('for watchman', callback=lambda w: w.path if w else 'not found')
398 def watchman(prog):
399     if not prog:
400         prog = find_program('watchman')
402     if not prog:
403         return
405     # `watchman version` will talk to the Watchman daemon service.
406     # This can hang due to permissions problems. e.g.
407     # https://github.com/facebook/watchman/issues/376. So use
408     # `watchman --version` to prevent a class of failures.
409     out = check_cmd_output(prog, '--version', onerror=lambda: None)
410     if out is None:
411         return
413     return namespace(path=prog, version=Version(out.strip()))
415 @depends_if(watchman)
416 @checking('for watchman version')
417 def watchman_version(w):
418     return w.version
420 set_config('WATCHMAN', watchman.path)
422 @depends_all(hg_version, hg_config, watchman)
423 @checking('for watchman Mercurial integration')
424 @imports('os')
425 def watchman_hg(hg_version, hg_config, watchman):
426     if hg_version < Version('3.8'):
427         return 'no (Mercurial 3.8+ required)'
429     ext_enabled = False
430     mode_disabled = False
432     for k in ('extensions.fsmonitor', 'extensions.hgext.fsmonitor'):
433         if k in hg_config and hg_config[k] != '!':
434             ext_enabled = True
436     mode_disabled = hg_config.get('fsmonitor.mode') == 'off'
438     if not ext_enabled:
439         return 'no (fsmonitor extension not enabled)'
440     if mode_disabled:
441         return 'no (fsmonitor.mode=off disables fsmonitor)'
443     return True
445 # Miscellaneous programs
446 # ==============================================================
447 check_prog('XARGS', ('xargs',))
449 @depends(target)
450 def extra_programs(target):
451     if target.kernel == 'Darwin':
452         return namespace(
453             DSYMUTIL=('dsymutil', 'llvm-dsymutil'),
454             MKFSHFS=('newfs_hfs', 'mkfs.hfsplus'),
455             HFS_TOOL=('hfsplus',)
456         )
457     if target.os == 'GNU' and target.kernel == 'Linux':
458         return namespace(RPMBUILD=('rpmbuild',))
460 check_prog('DSYMUTIL', extra_programs.DSYMUTIL,
461            allow_missing=True)
462 check_prog('MKFSHFS', extra_programs.MKFSHFS,
463            allow_missing=True)
464 check_prog('HFS_TOOL', extra_programs.HFS_TOOL,
465            allow_missing=True)
466 check_prog('RPMBUILD', extra_programs.RPMBUILD,
467            allow_missing=True)
469 option('--enable-system-hunspell',
470        help="Use system hunspell (located with pkgconfig)")
472 @depends('--enable-system-hunspell', compile_environment)
473 def check_for_hunspell(value, compile_env):
474     return value and compile_env
476 system_hunspell = pkg_check_modules('MOZ_HUNSPELL', 'hunspell',
477                                     when=check_for_hunspell)
479 set_config('MOZ_SYSTEM_HUNSPELL', depends_if(system_hunspell)(lambda _: True))
482 @depends(target)
483 @imports('os')
484 def makensis_progs(target):
485     if target.kernel != 'WINNT':
486         return
488     candidates = [
489         'makensis-3.01',
490         'makensis-3.0b3',
491         'makensis-3.0b1',
492         'makensis',
493     ]
495     # Look for nsis installed by msys environment. But only the 32-bit version.
496     # We use an absolute path and insert as the first entry so it is preferred
497     # over a 64-bit exe that may be in PATH.
498     if 'MSYSTEM_PREFIX' in os.environ:
499         prefix = os.path.dirname(os.environ['MSYSTEM_PREFIX'])
500         candidates.insert(0, os.path.join(prefix, 'mingw32', 'bin', 'makensis.exe'))
502     return tuple(candidates)
504 nsis = check_prog('MAKENSISU', makensis_progs, allow_missing=True)
506 # Make sure the version of makensis is up to date.
507 @depends_if(nsis)
508 @checking('for NSIS version')
509 @imports('re')
510 def nsis_version(nsis):
511     nsis_min_version = '3.0b1'
512     out = check_cmd_output(nsis, '-version',
513                            onerror=lambda: die('Failed to get nsis version.'))
514     m = re.search(r'(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?', out)
516     if not m:
517         raise FatalCheckError('Unknown version of makensis')
518     ver = Version(m.group(0))
520     # Versions comparisons don't quite work well with beta versions, so ensure
521     # it works for the non-beta version.
522     if ver < nsis_min_version and (ver >= '3.0a' or ver < '3'):
523         raise FatalCheckError('To build the installer you must have NSIS'
524                               ' version %s or greater in your path'
525                               % nsis_min_version)
527     return ver
529 # And that makensis is 32-bit (but only on Windows).
530 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == 'WINNT'))
531 @checking('for 32-bit NSIS')
532 def nsis_binary_type(nsis):
533     bin_type = windows_binary_type(nsis)
534     if bin_type != 'win32':
535         raise FatalCheckError('%s is not a 32-bit Windows application' % nsis)
537     return 'yes'
539 # And any flags we have to give to makensis
540 @depends(host)
541 def nsis_flags(host):
542     if host.kernel != 'WINNT':
543         return '-nocd'
544     return ''
546 set_config('MAKENSISU_FLAGS', nsis_flags)
548 check_prog('7Z', ('7z', '7za'), allow_missing=True, when=target_is_windows)
550 # Fallthrough to autoconf-based configure
551 include('build/moz.configure/old.configure')
553 @imports('__sandbox__')
554 def all_paths():
555     return __sandbox__._all_paths
557 set_config('ALL_CONFIGURE_PATHS', all_paths())
558 # Please do not add anything after setting ALL_CONFIGURE_PATHS.