Bug 1577199 pass error message as well as name to top-level test window r=jib
[gecko.git] / moz.configure
blob54cd84d2aaa945766dd14fcea6c6dd130ab3384a
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(
18     "--enable-artifact-builds",
19     env="MOZ_ARTIFACT_BUILDS",
20     help="Download and use prebuilt binary artifacts.",
24 @depends("--enable-artifact-builds")
25 def artifact_builds(value):
26     if value:
27         return True
30 set_config("MOZ_ARTIFACT_BUILDS", artifact_builds)
32 imply_option(
33     "--enable-artifact-build-symbols",
34     depends(artifact_builds)(lambda v: False if v is None else None),
35     reason="--disable-artifact-builds",
38 option(
39     "--enable-artifact-build-symbols",
40     nargs="?",
41     choices=("full",),
42     help="Download symbols when artifact builds are enabled.",
46 @depends("--enable-artifact-build-symbols", "MOZ_AUTOMATION", target)
47 def enable_artifact_build_symbols(value, automation, target):
48     if len(value):
49         return value[0]
50     if bool(value):
51         if target.os == "Android" and not automation:
52             return "full"
53         return True
54     return None
57 set_config("MOZ_ARTIFACT_BUILD_SYMBOLS", enable_artifact_build_symbols)
60 @depends("--enable-artifact-builds")
61 def imply_disable_compile_environment(value):
62     if value:
63         return False
66 option(
67     env="MOZ_COPY_PDBS",
68     help="For builds that do not support symbols in the normal fashion,"
69     " generate and copy them into the resulting build archive.",
72 set_config("MOZ_COPY_PDBS", depends_if("MOZ_COPY_PDBS")(lambda _: True))
74 imply_option("--enable-compile-environment", imply_disable_compile_environment)
76 option("--disable-compile-environment", help="Disable compiler/library checks")
79 @depends("--disable-compile-environment")
80 def compile_environment(compile_env):
81     if compile_env:
82         return True
85 set_config("COMPILE_ENVIRONMENT", compile_environment)
86 add_old_configure_assignment("COMPILE_ENVIRONMENT", compile_environment)
88 option("--disable-tests", help="Do not build test libraries & programs")
91 @depends("--disable-tests")
92 def enable_tests(value):
93     if value:
94         return True
97 set_config("ENABLE_TESTS", enable_tests)
98 set_define("ENABLE_TESTS", enable_tests)
101 @depends(enable_tests)
102 def gtest_has_rtti(value):
103     if value:
104         return "0"
107 set_define("GTEST_HAS_RTTI", gtest_has_rtti)
110 @depends(target, enable_tests)
111 def linux_gtest_defines(target, enable_tests):
112     if enable_tests and target.os == "Android":
113         return namespace(os_linux_android=True, use_own_tr1_tuple=True, has_clone="0")
116 set_define("GTEST_OS_LINUX_ANDROID", linux_gtest_defines.os_linux_android)
117 set_define("GTEST_USE_OWN_TR1_TUPLE", linux_gtest_defines.use_own_tr1_tuple)
118 set_define("GTEST_HAS_CLONE", linux_gtest_defines.has_clone)
120 option(
121     "--enable-debug",
122     nargs="?",
123     help="Enable building with developer debug info "
124     "(using the given compiler flags).",
128 @depends("--enable-debug")
129 def moz_debug(debug):
130     if debug:
131         return bool(debug)
134 set_config("MOZ_DEBUG", moz_debug)
135 set_define("MOZ_DEBUG", moz_debug)
136 # Override any value MOZ_DEBUG may have from the environment when passing it
137 # down to old-configure.
138 add_old_configure_assignment("MOZ_DEBUG", depends("--enable-debug")(lambda x: bool(x)))
140 option(
141     "--with-debug-label",
142     nargs="+",
143     help="Debug DEBUG_<value> for each comma-separated value given",
147 @depends(moz_debug, "--with-debug-label")
148 def debug_defines(debug, labels):
149     if debug:
150         return ["DEBUG"] + ["DEBUG_%s" % label for label in labels]
151     return ["NDEBUG", "TRIMMED"]
154 set_config("MOZ_DEBUG_DEFINES", debug_defines)
156 option(env="MOZ_PGO", help="Build with profile guided optimizations")
158 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
161 imply_option("--enable-release", mozilla_official)
162 imply_option("--enable-release", depends_if("MOZ_AUTOMATION")(lambda x: True))
164 option(
165     "--enable-release",
166     default=milestone.is_release_or_beta,
167     help="{Build|Do not build} with more conservative, release "
168     "engineering-oriented options.{ This may slow down builds.|}",
172 @depends("--enable-release")
173 def developer_options(value):
174     if not value:
175         return True
178 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
179 set_config("DEVELOPER_OPTIONS", developer_options)
182 option(
183     env="MOZ_FETCHES_DIR",
184     nargs=1,
185     when="MOZ_AUTOMATION",
186     help="Directory containing fetched artifacts",
190 @depends("MOZ_FETCHES_DIR", when="MOZ_AUTOMATION")
191 def moz_fetches_dir(value):
192     if value:
193         return value[0]
196 @depends(vcs_checkout_type, milestone.is_nightly, "MOZ_AUTOMATION")
197 def bootstrap_default(vcs_checkout_type, is_nightly, automation):
198     if automation:
199         return False
200     # We only enable if building off a VCS checkout of central.
201     if is_nightly and vcs_checkout_type:
202         return True
205 option(
206     "--enable-bootstrap",
207     default=bootstrap_default,
208     help="{Automatically bootstrap or update some toolchains|Disable bootstrap or update of toolchains}",
212 @depends(developer_options, "--enable-bootstrap", moz_fetches_dir)
213 def bootstrap_search_path_order(developer_options, bootstrap, moz_fetches_dir):
214     if moz_fetches_dir:
215         log.debug("Prioritizing MOZ_FETCHES_DIR in toolchain path.")
216         return "prepend"
218     if bootstrap:
219         log.debug(
220             "Prioritizing mozbuild state dir in toolchain paths because "
221             "bootstrap mode is enabled."
222         )
223         return "prepend"
225     if developer_options:
226         log.debug(
227             "Prioritizing mozbuild state dir in toolchain paths because "
228             "you are not building in release mode."
229         )
230         return "prepend"
232     log.debug(
233         "Prioritizing system over mozbuild state dir in "
234         "toolchain paths because you are building in "
235         "release mode."
236     )
237     return "append"
240 toolchains_base_dir = moz_fetches_dir | mozbuild_state_path
243 @dependable
244 @imports("os")
245 @imports(_from="os", _import="environ")
246 def original_path():
247     return environ["PATH"].split(os.pathsep)
250 @depends(host, when="--enable-bootstrap")
251 @imports("os")
252 @imports(_from="mozbuild.toolchains", _import="toolchain_task_definitions")
253 @imports(_from="__builtin__", _import="Exception")
254 def bootstrap_toolchain_tasks(host):
255     prefix = {
256         ("x86_64", "GNU", "Linux"): "linux64",
257         ("x86_64", "OSX", "Darwin"): "macosx64",
258         ("aarch64", "OSX", "Darwin"): "macosx64-aarch64",
259         ("x86_64", "WINNT", "WINNT"): "win64",
260     }.get((host.cpu, host.os, host.kernel))
261     try:
262         return namespace(prefix=prefix, tasks=toolchain_task_definitions())
263     except Exception:
264         return None
267 @template
268 def bootstrap_path(path, **kwargs):
269     when = kwargs.pop("when", None)
270     if kwargs:
271         configure_error("bootstrap_path only takes `when` as a keyword argument")
273     @depends(
274         "--enable-bootstrap",
275         toolchains_base_dir,
276         bootstrap_toolchain_tasks,
277         shell,
278         check_build_environment,
279         dependable(path),
280         when=when,
281     )
282     @imports("os")
283     @imports("subprocess")
284     @imports(_from="mozbuild.util", _import="ensureParentDir")
285     @imports(_from="__builtin__", _import="open")
286     @imports(_from="__builtin__", _import="Exception")
287     def bootstrap_path(bootstrap, toolchains_base_dir, tasks, shell, build_env, path):
288         path_parts = path.split("/")
290         def try_bootstrap(exists):
291             if not tasks:
292                 return False
293             prefixes = [""]
294             if tasks.prefix:
295                 prefixes.insert(0, "{}-".format(tasks.prefix))
296             for prefix in prefixes:
297                 label = "toolchain-{}{}".format(prefix, path_parts[0])
298                 task = tasks.tasks.get(label)
299                 if task:
300                     break
301             log.debug("Trying to bootstrap %s", label)
302             if not task:
303                 return False
304             task_index = task.optimization.get("index-search")
305             if not task_index:
306                 return False
307             log.debug("Resolved %s to %s", label, task_index[0])
308             task_index = task_index[0].split(".")[-1]
309             artifact = task.attributes["toolchain-artifact"]
310             # `mach artifact toolchain` doesn't support authentication for
311             # private artifacts.
312             if not artifact.startswith("public/"):
313                 log.debug("Cannot bootstrap %s: not a public artifact", label)
314                 return False
315             index_file = os.path.join(toolchains_base_dir, "indices", path_parts[0])
316             try:
317                 with open(index_file) as fh:
318                     index = fh.read().strip()
319             except Exception:
320                 index = None
321             if index == task_index and exists:
322                 log.debug("%s is up-to-date", label)
323                 return True
324             log.info(
325                 "%s bootstrapped toolchain in %s",
326                 "Updating" if exists else "Installing",
327                 os.path.join(toolchains_base_dir, path_parts[0]),
328             )
329             subprocess.run(
330                 [
331                     shell,
332                     os.path.join(build_env.topsrcdir, "mach"),
333                     "--log-no-times",
334                     "artifact",
335                     "toolchain",
336                     "--from-build",
337                     label,
338                 ],
339                 cwd=toolchains_base_dir,
340                 check=True,
341             )
342             ensureParentDir(index_file)
343             with open(index_file, "w") as fh:
344                 fh.write(task_index)
345             return True
347         path = os.path.join(toolchains_base_dir, *path_parts)
348         if bootstrap:
349             try:
350                 if not try_bootstrap(os.path.exists(path)):
351                     # If there aren't toolchain artifacts to use for this build,
352                     # don't return a path.
353                     return None
354             except Exception as e:
355                 log.error("%s", e)
356                 die("If you can't fix the above, retry with --disable-bootstrap.")
357         # We re-test whether the path exists because it may have been created by
358         # try_bootstrap. Automation will not have gone through the bootstrap
359         # process, but we want to return the path if it exists.
360         if os.path.exists(path):
361             return path
363     return bootstrap_path
366 @template
367 def bootstrap_search_path(path, paths=original_path, **kwargs):
368     @depends(
369         bootstrap_path(path, **kwargs),
370         bootstrap_search_path_order,
371         paths,
372         original_path,
373     )
374     def bootstrap_search_path(path, order, paths, original_path):
375         if paths is None:
376             paths = original_path
377         if not path:
378             return paths
379         if order == "prepend":
380             return [path] + paths
381         return paths + [path]
383     return bootstrap_search_path
386 # The execution model of the configure sandbox doesn't allow for
387 # check_prog to use bootstrap_search_path directly because check_prog
388 # comes first, so we use a trick to allow it. No use of check_prog
389 # happening before here won't allow bootstrap.
390 @template
391 def check_prog(*args, **kwargs):
392     kwargs["bootstrap_search_path"] = bootstrap_search_path
393     return check_prog(*args, **kwargs)
396 @depends(target, host)
397 def want_wine(target, host):
398     return target.kernel == "WINNT" and host.kernel != "WINNT"
401 wine = check_prog(
402     "WINE",
403     ["wine64", "wine"],
404     allow_missing=True,
405     when=want_wine,
406     bootstrap="wine/bin",
408 check_prog("WGET", ("wget",), allow_missing=True)
411 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
413 include("build/moz.configure/pkg.configure")
414 # Make this assignment here rather than in pkg.configure to avoid
415 # requiring this file in unit tests.
416 add_old_configure_assignment("PKG_CONFIG", pkg_config)
418 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
419 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
420 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
421 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
422 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
423 # rust.configure is included by js/moz.configure.
425 option("--enable-valgrind", help="Enable Valgrind integration hooks")
427 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
430 @depends("--enable-valgrind", valgrind_h)
431 def check_valgrind(valgrind, valgrind_h):
432     if valgrind:
433         if not valgrind_h:
434             die("--enable-valgrind specified but Valgrind is not installed")
435         return True
438 set_define("MOZ_VALGRIND", check_valgrind)
439 set_config("MOZ_VALGRIND", check_valgrind)
442 @depends(target, host)
443 def is_openbsd(target, host):
444     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
447 option(
448     env="SO_VERSION",
449     nargs=1,
450     default="1.0",
451     when=is_openbsd,
452     help="Shared library version for OpenBSD systems",
456 @depends("SO_VERSION", when=is_openbsd)
457 def so_version(value):
458     return value
461 @template
462 def library_name_info_template(host_or_target):
463     assert host_or_target in {host, target}
464     compiler = {
465         host: host_c_compiler,
466         target: c_compiler,
467     }[host_or_target]
469     @depends(host_or_target, compiler, so_version)
470     def library_name_info_impl(host_or_target, compiler, so_version):
471         if host_or_target.kernel == "WINNT":
472             # There aren't artifacts for mingw builds, so it's OK that the
473             # results are inaccurate in that case.
474             if compiler and compiler.type != "clang-cl":
475                 return namespace(
476                     dll=namespace(prefix="", suffix=".dll"),
477                     lib=namespace(prefix="lib", suffix="a"),
478                     import_lib=namespace(prefix="lib", suffix="a"),
479                     obj=namespace(prefix="", suffix="o"),
480                 )
482             return namespace(
483                 dll=namespace(prefix="", suffix=".dll"),
484                 lib=namespace(prefix="", suffix="lib"),
485                 import_lib=namespace(prefix="", suffix="lib"),
486                 obj=namespace(prefix="", suffix="obj"),
487             )
489         elif host_or_target.kernel == "Darwin":
490             return namespace(
491                 dll=namespace(prefix="lib", suffix=".dylib"),
492                 lib=namespace(prefix="lib", suffix="a"),
493                 import_lib=namespace(prefix=None, suffix=""),
494                 obj=namespace(prefix="", suffix="o"),
495             )
496         elif so_version:
497             so = ".so.%s" % so_version
498         else:
499             so = ".so"
501         return namespace(
502             dll=namespace(prefix="lib", suffix=so),
503             lib=namespace(prefix="lib", suffix="a"),
504             import_lib=namespace(prefix=None, suffix=""),
505             obj=namespace(prefix="", suffix="o"),
506         )
508     return library_name_info_impl
511 host_library_name_info = library_name_info_template(host)
512 library_name_info = library_name_info_template(target)
514 set_config("DLL_PREFIX", library_name_info.dll.prefix)
515 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
516 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
517 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
518 set_config("LIB_PREFIX", library_name_info.lib.prefix)
519 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
520 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
521 # Lots of compilation tests depend on this variable being present.
522 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
523 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
524 set_define(
525     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
527 set_define(
528     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
530 set_config("WASM_OBJ_SUFFIX", "wasm")
532 # Make `profiling` available to this file even when js/moz.configure
533 # doesn't end up included.
534 profiling = dependable(False)
535 # Same for js_standalone
536 js_standalone = dependable(False)
537 # Same for fold_libs
538 fold_libs = dependable(False)
540 include(include_project_configure)
543 @depends("--help")
544 @imports(_from="mozbuild.backend", _import="backends")
545 def build_backends_choices(_):
546     return tuple(backends)
549 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
550 def build_backend(backends):
551     if backends:
552         return tuple("+%s" % b for b in backends)
555 imply_option("--build-backends", build_backend)
558 @depends(
559     "--enable-artifact-builds",
560     "--disable-compile-environment",
561     "--enable-build-backend",
562     "--enable-project",
563     "--enable-application",
564     "--help",
566 @imports("sys")
567 def build_backend_defaults(
568     artifact_builds, compile_environment, requested_backends, project, application, _
570     if application:
571         project = application[0]
572     elif project:
573         project = project[0]
575     if "Tup" in requested_backends:
576         # As a special case, if Tup was requested, do not combine it with any
577         # Make based backend by default.
578         all_backends = []
579     elif artifact_builds:
580         all_backends = ["FasterMake+RecursiveMake"]
581     else:
582         all_backends = ["RecursiveMake", "FasterMake"]
583     # Normally, we'd use target.os == 'WINNT', but a dependency on target
584     # would require target to depend on --help, as well as host and shell,
585     # and this is not a can of worms we can open at the moment.
586     if (
587         sys.platform == "win32"
588         and compile_environment
589         and project not in ("mobile/android", "memory", "tools/update-programs")
590     ):
591         all_backends.append("VisualStudio")
592     return tuple(all_backends) or None
595 option(
596     "--build-backends",
597     nargs="+",
598     default=build_backend_defaults,
599     choices=build_backends_choices,
600     help="Build backends to generate",
604 @depends("--build-backends")
605 def build_backends(backends):
606     return backends
609 set_config("BUILD_BACKENDS", build_backends)
612 @depends(check_build_environment, build_backends)
613 @imports("glob")
614 def check_objdir_backend_reuse(build_env, backends):
615     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
616     # intentionally vague for use with the substring match below.
617     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
618     for backend_file in glob.iglob(
619         os.path.join(build_env.topobjdir, "backend.*Backend")
620     ):
621         for prev, curr in incompatible_backends:
622             if prev in backend_file and any(curr in b for b in backends):
623                 die(
624                     "The active objdir, %s, was previously "
625                     "used to build with a %s based backend. "
626                     "Change objdirs (by setting MOZ_OBJDIR in "
627                     "your mozconfig) or clobber to continue.\n",
628                     build_env.topobjdir,
629                     prev,
630                 )
633 option(
634     "--disable-gtest-in-build",
635     help="Force disable building the gtest libxul during the build.",
636     when="--enable-compile-environment",
639 # Determine whether to build the gtest xul. This happens in automation
640 # on Android and Desktop platforms with the exception of:
641 #  - Windows PGO, where linking xul-gtest.dll takes too long;
642 #  - Android other than x86_64, where gtest is not required.
645 @depends(
646     "MOZ_PGO",
647     build_project,
648     target,
649     "MOZ_AUTOMATION",
650     "--disable-gtest-in-build",
651     enable_tests,
652     when="--enable-compile-environment",
654 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
655     if not enable_tests or not enabled:
656         return None
657     if (
658         automation
659         and build_project in ("browser", "comm/mail", "mobile/android")
660         and not (
661             (pgo and target.os == "WINNT")
662             or (target.os == "Android" and target.cpu != "x86_64")
663         )
664     ):
665         return True
668 set_config("LINK_GTEST_DURING_COMPILE", build_gtest)
670 # Localization
671 # ==============================================================
672 option(
673     "--enable-ui-locale",
674     default="en-US",
675     help="Select the user interface locale (default: en-US)",
678 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
680 # clang-plugin location
681 # ==============================================================
684 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
685 def clang_plugin_path(library_name_info, build_env):
686     topobjdir = build_env.topobjdir
687     if topobjdir.endswith("/js/src"):
688         topobjdir = topobjdir[:-7]
689     return os.path.abspath(
690         os.path.join(
691             topobjdir,
692             "build",
693             "clang-plugin",
694             "%sclang-plugin%s"
695             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
696         )
697     )
700 set_config("CLANG_PLUGIN", clang_plugin_path)
701 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
704 # Awk detection
705 # ==============================================================
706 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
708 # Until the AWK variable is not necessary in old-configure
711 @depends(awk)
712 def awk_for_old_configure(value):
713     return value
716 add_old_configure_assignment("AWK", awk_for_old_configure)
719 # Perl detection
720 # ==============================================================
721 perl = check_prog("PERL", ("perl5", "perl"))
723 # Until the PERL variable is not necessary in old-configure
726 @depends(perl)
727 def perl_for_old_configure(value):
728     return value
731 add_old_configure_assignment("PERL", perl_for_old_configure)
734 @template
735 def perl_version_check(min_version):
736     @depends(perl)
737     @checking("for minimum required perl version >= %s" % min_version)
738     def get_perl_version(perl):
739         return Version(
740             check_cmd_output(
741                 perl,
742                 "-e",
743                 "print $]",
744                 onerror=lambda: die("Failed to get perl version."),
745             )
746         )
748     @depends(get_perl_version)
749     def check_perl_version(version):
750         if version < min_version:
751             die("Perl %s or higher is required.", min_version)
753     @depends(perl)
754     @checking("for full perl installation")
755     @imports("subprocess")
756     def has_full_perl_installation(perl):
757         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
758         return ret == 0
760     @depends(has_full_perl_installation)
761     def require_full_perl_installation(has_full_perl_installation):
762         if not has_full_perl_installation:
763             die(
764                 "Cannot find Config.pm or $Config{archlib}. "
765                 "A full perl installation is required."
766             )
769 perl_version_check("5.006")
772 # GNU make detection
773 # ==============================================================
774 option(env="MAKE", nargs=1, help="Path to GNU make")
777 @depends("MAKE", host)
778 def possible_makes(make, host):
779     candidates = []
780     if host.kernel == "WINNT":
781         candidates.append("mingw32-make")
782     if make:
783         candidates.append(make[0])
784     if host.kernel == "WINNT":
785         candidates.extend(("mozmake", "make", "gmake"))
786     else:
787         candidates.extend(("gmake", "make"))
788     return candidates
791 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
793 # watchman detection
794 # ==============================================================
796 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
799 @depends(host, "WATCHMAN")
800 @checking("for watchman", callback=lambda w: w.path if w else "not found")
801 def watchman(host, prog):
802     # On Windows, `watchman` is only supported on 64-bit hosts.
803     if host.os == "WINNT" and host.cpu != "x86_64":
804         return
806     if not prog:
807         prog = find_program("watchman")
809     if not prog:
810         return
812     # `watchman version` will talk to the Watchman daemon service.
813     # This can hang due to permissions problems. e.g.
814     # https://github.com/facebook/watchman/issues/376. So use
815     # `watchman --version` to prevent a class of failures.
816     out = check_cmd_output(prog, "--version", onerror=lambda: None)
817     if out is None:
818         return
820     return namespace(path=prog, version=Version(out.strip()))
823 @depends_if(watchman)
824 @checking("for watchman version")
825 def watchman_version(w):
826     return w.version
829 set_config("WATCHMAN", watchman.path)
832 @depends_all(hg_version, hg_config, watchman)
833 @checking("for watchman Mercurial integration")
834 @imports("os")
835 def watchman_hg(hg_version, hg_config, watchman):
836     if hg_version < Version("3.8"):
837         return "no (Mercurial 3.8+ required)"
839     ext_enabled = False
840     mode_disabled = False
842     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
843         if k in hg_config and hg_config[k] != "!":
844             ext_enabled = True
846     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
848     if not ext_enabled:
849         return "no (fsmonitor extension not enabled)"
850     if mode_disabled:
851         return "no (fsmonitor.mode=off disables fsmonitor)"
853     return True
856 # Miscellaneous programs
857 # ==============================================================
858 check_prog("XARGS", ("xargs",))
861 @depends(target)
862 def extra_programs(target):
863     if target.kernel == "Darwin":
864         return namespace(
865             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
866             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
867             HFS_TOOL=("hfsplus",),
868         )
869     if target.os == "GNU" and target.kernel == "Linux":
870         return namespace(RPMBUILD=("rpmbuild",))
873 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
874 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
875 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
876 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
879 @depends(target)
880 @imports("os")
881 def makensis_progs(target):
882     if target.kernel != "WINNT":
883         return
885     candidates = [
886         "makensis-3.01",
887         "makensis-3.0b3",
888         "makensis-3.0b1",
889         "makensis",
890     ]
892     # Look for nsis installed by msys environment. But only the 32-bit version.
893     # We use an absolute path and insert as the first entry so it is preferred
894     # over a 64-bit exe that may be in PATH.
895     if "MSYSTEM_PREFIX" in os.environ:
896         prefix = os.path.dirname(os.environ["MSYSTEM_PREFIX"])
897         candidates.insert(0, os.path.join(prefix, "mingw32", "bin", "makensis.exe"))
899     return tuple(candidates)
902 nsis = check_prog("MAKENSISU", makensis_progs, allow_missing=True)
904 # Make sure the version of makensis is up to date.
907 @depends(nsis, wine)
908 @checking("for NSIS version")
909 @imports("re")
910 def nsis_version(nsis, wine):
911     if not nsis:
912         return None
913     nsis_min_version = "3.0b1"
915     def onerror():
916         return die("Failed to get nsis version.")
918     if wine and nsis.lower().endswith(".exe"):
919         out = check_cmd_output(wine, nsis, "-version", onerror=onerror)
920     else:
921         out = check_cmd_output(nsis, "-version", onerror=onerror)
923     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
925     if not m:
926         raise FatalCheckError("Unknown version of makensis")
927     ver = Version(m.group(0))
929     # Versions comparisons don't quite work well with beta versions, so ensure
930     # it works for the non-beta version.
931     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
932         raise FatalCheckError(
933             "To build the installer you must have NSIS"
934             " version %s or greater in your path" % nsis_min_version
935         )
937     return ver
940 # And that makensis is 32-bit (but only on Windows).
941 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
942 @checking("for 32-bit NSIS")
943 def nsis_binary_type(nsis):
944     bin_type = windows_binary_type(nsis)
945     if bin_type != "win32":
946         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
948     return "yes"
951 # And any flags we have to give to makensis
952 @depends(host)
953 def nsis_flags(host):
954     if host.kernel != "WINNT":
955         return "-nocd"
956     return ""
959 set_config("MAKENSISU_FLAGS", nsis_flags)
961 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
962 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
965 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
966 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
967     clang = None
968     for compiler in (host_c_compiler, c_compiler):
969         if compiler and compiler.type == "clang":
970             clang = compiler.compiler
971             break
972         elif compiler and compiler.type == "clang-cl":
973             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
974             break
976     if not clang and bindgen_config_paths:
977         clang = bindgen_config_paths.clang_path
978     llvm_objdump = "llvm-objdump"
979     if clang:
980         out = check_cmd_output(
981             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
982         )
983         if out:
984             llvm_objdump = out.rstrip()
985     return (llvm_objdump,)
988 llvm_objdump = check_prog(
989     "LLVM_OBJDUMP",
990     llvm_objdump,
991     what="llvm-objdump",
992     when="--enable-compile-environment",
993     paths=clang_search_path,
996 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
999 option("--enable-dtrace", help="Build with dtrace support")
1001 dtrace = check_header(
1002     "sys/sdt.h",
1003     when="--enable-dtrace",
1004     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
1007 set_config("HAVE_DTRACE", True, when=dtrace)
1008 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
1009 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
1012 option("--disable-icf", help="Disable Identical Code Folding")
1014 add_old_configure_assignment(
1015     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
1019 option(
1020     "--enable-strip",
1021     when=compile_environment,
1022     help="Enable stripping of libs & executables",
1025 # This should be handled as a `when` once bug 1617793 is fixed.
1028 @depends("--enable-strip", c_compiler, when=compile_environment)
1029 def enable_strip(strip, c_compiler):
1030     if strip and c_compiler.type != "clang-cl":
1031         return True
1034 set_config("ENABLE_STRIP", enable_strip)
1036 option(
1037     "--disable-install-strip",
1038     when=compile_environment,
1039     help="Enable stripping of libs & executables when packaging",
1042 # This should be handled as a `when` once bug 1617793 is fixed.
1045 @depends("--enable-install-strip", c_compiler, when=compile_environment)
1046 def enable_install_strip(strip, c_compiler):
1047     if strip and c_compiler.type != "clang-cl":
1048         return True
1051 set_config("PKG_STRIP", enable_install_strip)
1054 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1055 def strip(strip, install_strip):
1056     return strip or install_strip
1059 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1062 @depends("STRIP_FLAGS", profiling, target, when=strip)
1063 def strip_flags(flags, profiling, target):
1064     if flags:
1065         return flags[0].split()
1066     if profiling:
1067         # Only strip debug info and symbols when profiling is enabled, keeping
1068         # local symbols.
1069         if target.kernel == "Darwin":
1070             return ["-S"]
1071         elif target.os == "Android":
1072             # The tooling we use with Android supports detached symbols, and the
1073             # size increase caused by local symbols are too much for mobile. So,
1074             # don't restrict the amount of stripping with a flag.
1075             return
1076         else:
1077             return ["--strip-debug"]
1078     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1079     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1080     elif target.kernel == "Darwin":
1081         return ["-x", "-S"]
1084 set_config("STRIP_FLAGS", strip_flags)
1087 @depends(js_standalone, target)
1088 def system_zlib_default(js_standalone, target):
1089     return js_standalone and target.kernel != "WINNT"
1092 option(
1093     "--with-system-zlib",
1094     nargs="?",
1095     default=system_zlib_default,
1096     help="{Use|Do not use} system libz",
1100 @depends("--with-system-zlib")
1101 def deprecated_system_zlib_path(value):
1102     if len(value) == 1:
1103         die(
1104             "--with-system-zlib=PATH is not supported anymore. Please use "
1105             "--with-system-zlib and set any necessary pkg-config environment variable."
1106         )
1109 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1111 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1112 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1115 # Please do not add configure checks from here on.
1117 # Fallthrough to autoconf-based configure
1118 include("build/moz.configure/old.configure")
1120 # JS Subconfigure.
1121 include("js/sub.configure", when=compile_environment & toolkit)
1124 @depends(check_build_environment, build_project)
1125 @imports("__sandbox__")
1126 @imports("glob")
1127 @imports(_from="os.path", _import="exists")
1128 def config_status_deps(build_env, build_project):
1130     topsrcdir = build_env.topsrcdir
1131     topobjdir = build_env.topobjdir
1133     if not topobjdir.endswith("js/src"):
1134         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1135     else:
1136         # mozconfig changes may impact js configure.
1137         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1139     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1140     if exists(confvars):
1141         extra_deps.append(confvars)
1143     return (
1144         list(__sandbox__._all_paths)
1145         + extra_deps
1146         + [
1147             os.path.join(topsrcdir, "CLOBBER"),
1148             os.path.join(topsrcdir, "configure.in"),
1149             os.path.join(topsrcdir, "js", "src", "configure.in"),
1150             os.path.join(topsrcdir, "nsprpub", "configure"),
1151             os.path.join(topsrcdir, "config", "milestone.txt"),
1152             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1153             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1154             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1155             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1156             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1157             os.path.join(topsrcdir, "python", "mozbuild", "mozbuild", "virtualenv.py"),
1158             os.path.join(topsrcdir, "aclocal.m4"),
1159             os.path.join(topsrcdir, "old-configure.in"),
1160             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1161             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1162         ]
1163         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1164     )
1167 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1168 # Please do not add anything after setting config_dep_paths.