Bug 1720653 [wpt PR 29673] - [Sanitizer API] Move tests to WPT suite., a=testonly
[gecko.git] / moz.configure
blob677f51ee3b0224aba7e9c56ffeeff2d684a941cb
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                 return False
314             index_file = os.path.join(toolchains_base_dir, "indices", path_parts[0])
315             try:
316                 with open(index_file) as fh:
317                     index = fh.read().strip()
318             except Exception:
319                 index = None
320             if index == task_index and exists:
321                 return True
322             log.info(
323                 "%s bootstrapped toolchain in %s",
324                 "Updating" if exists else "Installing",
325                 os.path.join(toolchains_base_dir, path_parts[0]),
326             )
327             subprocess.run(
328                 [
329                     shell,
330                     os.path.join(build_env.topsrcdir, "mach"),
331                     "--log-no-times",
332                     "artifact",
333                     "toolchain",
334                     "--from-build",
335                     label,
336                 ],
337                 cwd=toolchains_base_dir,
338                 check=True,
339             )
340             ensureParentDir(index_file)
341             with open(index_file, "w") as fh:
342                 fh.write(task_index)
343             return True
345         path = os.path.join(toolchains_base_dir, *path_parts)
346         if bootstrap:
347             try:
348                 if not try_bootstrap(os.path.exists(path)):
349                     # If there aren't toolchain artifacts to use for this build,
350                     # don't return a path.
351                     return None
352             except Exception as e:
353                 log.error("%s", e)
354                 die("If you can't fix the above, retry with --disable-bootstrap.")
355         # We re-test whether the path exists because it may have been created by
356         # try_bootstrap. Automation will not have gone through the bootstrap
357         # process, but we want to return the path if it exists.
358         if os.path.exists(path):
359             return path
361     return bootstrap_path
364 @template
365 def bootstrap_search_path(path, paths=original_path, **kwargs):
366     @depends(
367         bootstrap_path(path, **kwargs),
368         bootstrap_search_path_order,
369         paths,
370         original_path,
371     )
372     def bootstrap_search_path(path, order, paths, original_path):
373         if paths is None:
374             paths = original_path
375         if not path:
376             return paths
377         if order == "prepend":
378             return [path] + paths
379         return paths + [path]
381     return bootstrap_search_path
384 # The execution model of the configure sandbox doesn't allow for
385 # check_prog to use bootstrap_search_path directly because check_prog
386 # comes first, so we use a trick to allow it. No use of check_prog
387 # happening before here won't allow bootstrap.
388 @template
389 def check_prog(*args, **kwargs):
390     kwargs["bootstrap_search_path"] = bootstrap_search_path
391     return check_prog(*args, **kwargs)
394 @depends(target, host)
395 def want_wine(target, host):
396     return target.kernel == "WINNT" and host.kernel != "WINNT"
399 wine = check_prog(
400     "WINE",
401     ["wine64", "wine"],
402     allow_missing=True,
403     when=want_wine,
404     bootstrap="wine/bin",
406 check_prog("WGET", ("wget",), allow_missing=True)
409 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
411 include("build/moz.configure/pkg.configure")
412 # Make this assignment here rather than in pkg.configure to avoid
413 # requiring this file in unit tests.
414 add_old_configure_assignment("PKG_CONFIG", pkg_config)
416 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
417 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
418 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
419 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
420 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
421 # rust.configure is included by js/moz.configure.
423 option("--enable-valgrind", help="Enable Valgrind integration hooks")
425 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
428 @depends("--enable-valgrind", valgrind_h)
429 def check_valgrind(valgrind, valgrind_h):
430     if valgrind:
431         if not valgrind_h:
432             die("--enable-valgrind specified but Valgrind is not installed")
433         return True
436 set_define("MOZ_VALGRIND", check_valgrind)
437 set_config("MOZ_VALGRIND", check_valgrind)
440 @depends(target, host)
441 def is_openbsd(target, host):
442     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
445 option(
446     env="SO_VERSION",
447     nargs=1,
448     default="1.0",
449     when=is_openbsd,
450     help="Shared library version for OpenBSD systems",
454 @depends("SO_VERSION", when=is_openbsd)
455 def so_version(value):
456     return value
459 @template
460 def library_name_info_template(host_or_target):
461     assert host_or_target in {host, target}
462     compiler = {
463         host: host_c_compiler,
464         target: c_compiler,
465     }[host_or_target]
467     @depends(host_or_target, compiler, so_version)
468     def library_name_info_impl(host_or_target, compiler, so_version):
469         if host_or_target.kernel == "WINNT":
470             # There aren't artifacts for mingw builds, so it's OK that the
471             # results are inaccurate in that case.
472             if compiler and compiler.type != "clang-cl":
473                 return namespace(
474                     dll=namespace(prefix="", suffix=".dll"),
475                     lib=namespace(prefix="lib", suffix="a"),
476                     import_lib=namespace(prefix="lib", suffix="a"),
477                     obj=namespace(prefix="", suffix="o"),
478                 )
480             return namespace(
481                 dll=namespace(prefix="", suffix=".dll"),
482                 lib=namespace(prefix="", suffix="lib"),
483                 import_lib=namespace(prefix="", suffix="lib"),
484                 obj=namespace(prefix="", suffix="obj"),
485             )
487         elif host_or_target.kernel == "Darwin":
488             return namespace(
489                 dll=namespace(prefix="lib", suffix=".dylib"),
490                 lib=namespace(prefix="lib", suffix="a"),
491                 import_lib=namespace(prefix=None, suffix=""),
492                 obj=namespace(prefix="", suffix="o"),
493             )
494         elif so_version:
495             so = ".so.%s" % so_version
496         else:
497             so = ".so"
499         return namespace(
500             dll=namespace(prefix="lib", suffix=so),
501             lib=namespace(prefix="lib", suffix="a"),
502             import_lib=namespace(prefix=None, suffix=""),
503             obj=namespace(prefix="", suffix="o"),
504         )
506     return library_name_info_impl
509 host_library_name_info = library_name_info_template(host)
510 library_name_info = library_name_info_template(target)
512 set_config("DLL_PREFIX", library_name_info.dll.prefix)
513 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
514 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
515 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
516 set_config("LIB_PREFIX", library_name_info.lib.prefix)
517 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
518 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
519 # Lots of compilation tests depend on this variable being present.
520 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
521 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
522 set_define(
523     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
525 set_define(
526     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
528 set_config("WASM_OBJ_SUFFIX", "wasm")
530 # Make `profiling` available to this file even when js/moz.configure
531 # doesn't end up included.
532 profiling = dependable(False)
533 # Same for js_standalone
534 js_standalone = dependable(False)
535 # Same for fold_libs
536 fold_libs = dependable(False)
538 include(include_project_configure)
541 @depends("--help")
542 @imports(_from="mozbuild.backend", _import="backends")
543 def build_backends_choices(_):
544     return tuple(backends)
547 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
548 def build_backend(backends):
549     if backends:
550         return tuple("+%s" % b for b in backends)
553 imply_option("--build-backends", build_backend)
556 @depends(
557     "--enable-artifact-builds",
558     "--disable-compile-environment",
559     "--enable-build-backend",
560     "--enable-project",
561     "--enable-application",
562     "--help",
564 @imports("sys")
565 def build_backend_defaults(
566     artifact_builds, compile_environment, requested_backends, project, application, _
568     if application:
569         project = application[0]
570     elif project:
571         project = project[0]
573     if "Tup" in requested_backends:
574         # As a special case, if Tup was requested, do not combine it with any
575         # Make based backend by default.
576         all_backends = []
577     elif artifact_builds:
578         all_backends = ["FasterMake+RecursiveMake"]
579     else:
580         all_backends = ["RecursiveMake", "FasterMake"]
581     # Normally, we'd use target.os == 'WINNT', but a dependency on target
582     # would require target to depend on --help, as well as host and shell,
583     # and this is not a can of worms we can open at the moment.
584     if (
585         sys.platform == "win32"
586         and compile_environment
587         and project not in ("mobile/android", "memory", "tools/update-programs")
588     ):
589         all_backends.append("VisualStudio")
590     return tuple(all_backends) or None
593 option(
594     "--build-backends",
595     nargs="+",
596     default=build_backend_defaults,
597     choices=build_backends_choices,
598     help="Build backends to generate",
602 @depends("--build-backends")
603 def build_backends(backends):
604     return backends
607 set_config("BUILD_BACKENDS", build_backends)
610 @depends(check_build_environment, build_backends)
611 @imports("glob")
612 def check_objdir_backend_reuse(build_env, backends):
613     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
614     # intentionally vague for use with the substring match below.
615     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
616     for backend_file in glob.iglob(
617         os.path.join(build_env.topobjdir, "backend.*Backend")
618     ):
619         for prev, curr in incompatible_backends:
620             if prev in backend_file and any(curr in b for b in backends):
621                 die(
622                     "The active objdir, %s, was previously "
623                     "used to build with a %s based backend. "
624                     "Change objdirs (by setting MOZ_OBJDIR in "
625                     "your mozconfig) or clobber to continue.\n",
626                     build_env.topobjdir,
627                     prev,
628                 )
631 option(
632     "--disable-gtest-in-build",
633     help="Force disable building the gtest libxul during the build.",
634     when="--enable-compile-environment",
637 # Determine whether to build the gtest xul. This happens in automation
638 # on Android and Desktop platforms with the exception of:
639 #  - Windows PGO, where linking xul-gtest.dll takes too long;
640 #  - Android other than x86_64, where gtest is not required.
643 @depends(
644     "MOZ_PGO",
645     build_project,
646     target,
647     "MOZ_AUTOMATION",
648     "--disable-gtest-in-build",
649     enable_tests,
650     when="--enable-compile-environment",
652 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
653     if not enable_tests or not enabled:
654         return None
655     if (
656         automation
657         and build_project in ("browser", "comm/mail", "mobile/android")
658         and not (
659             (pgo and target.os == "WINNT")
660             or (target.os == "Android" and target.cpu != "x86_64")
661         )
662     ):
663         return True
666 set_config("LINK_GTEST_DURING_COMPILE", build_gtest)
668 # Localization
669 # ==============================================================
670 option(
671     "--enable-ui-locale",
672     default="en-US",
673     help="Select the user interface locale (default: en-US)",
676 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
678 # clang-plugin location
679 # ==============================================================
682 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
683 def clang_plugin_path(library_name_info, build_env):
684     topobjdir = build_env.topobjdir
685     if topobjdir.endswith("/js/src"):
686         topobjdir = topobjdir[:-7]
687     return os.path.abspath(
688         os.path.join(
689             topobjdir,
690             "build",
691             "clang-plugin",
692             "%sclang-plugin%s"
693             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
694         )
695     )
698 set_config("CLANG_PLUGIN", clang_plugin_path)
699 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
702 # Awk detection
703 # ==============================================================
704 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
706 # Until the AWK variable is not necessary in old-configure
709 @depends(awk)
710 def awk_for_old_configure(value):
711     return value
714 add_old_configure_assignment("AWK", awk_for_old_configure)
717 # Perl detection
718 # ==============================================================
719 perl = check_prog("PERL", ("perl5", "perl"))
721 # Until the PERL variable is not necessary in old-configure
724 @depends(perl)
725 def perl_for_old_configure(value):
726     return value
729 add_old_configure_assignment("PERL", perl_for_old_configure)
732 @template
733 def perl_version_check(min_version):
734     @depends(perl)
735     @checking("for minimum required perl version >= %s" % min_version)
736     def get_perl_version(perl):
737         return Version(
738             check_cmd_output(
739                 perl,
740                 "-e",
741                 "print $]",
742                 onerror=lambda: die("Failed to get perl version."),
743             )
744         )
746     @depends(get_perl_version)
747     def check_perl_version(version):
748         if version < min_version:
749             die("Perl %s or higher is required.", min_version)
751     @depends(perl)
752     @checking("for full perl installation")
753     @imports("subprocess")
754     def has_full_perl_installation(perl):
755         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
756         return ret == 0
758     @depends(has_full_perl_installation)
759     def require_full_perl_installation(has_full_perl_installation):
760         if not has_full_perl_installation:
761             die(
762                 "Cannot find Config.pm or $Config{archlib}. "
763                 "A full perl installation is required."
764             )
767 perl_version_check("5.006")
770 # GNU make detection
771 # ==============================================================
772 option(env="MAKE", nargs=1, help="Path to GNU make")
775 @depends("MAKE", host)
776 def possible_makes(make, host):
777     candidates = []
778     if host.kernel == "WINNT":
779         candidates.append("mingw32-make")
780     if make:
781         candidates.append(make[0])
782     if host.kernel == "WINNT":
783         candidates.extend(("mozmake", "make", "gmake"))
784     else:
785         candidates.extend(("gmake", "make"))
786     return candidates
789 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
791 # watchman detection
792 # ==============================================================
794 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
797 @depends(host, "WATCHMAN")
798 @checking("for watchman", callback=lambda w: w.path if w else "not found")
799 def watchman(host, prog):
800     # On Windows, `watchman` is only supported on 64-bit hosts.
801     if host.os == "WINNT" and host.cpu != "x86_64":
802         return
804     if not prog:
805         prog = find_program("watchman")
807     if not prog:
808         return
810     # `watchman version` will talk to the Watchman daemon service.
811     # This can hang due to permissions problems. e.g.
812     # https://github.com/facebook/watchman/issues/376. So use
813     # `watchman --version` to prevent a class of failures.
814     out = check_cmd_output(prog, "--version", onerror=lambda: None)
815     if out is None:
816         return
818     return namespace(path=prog, version=Version(out.strip()))
821 @depends_if(watchman)
822 @checking("for watchman version")
823 def watchman_version(w):
824     return w.version
827 set_config("WATCHMAN", watchman.path)
830 @depends_all(hg_version, hg_config, watchman)
831 @checking("for watchman Mercurial integration")
832 @imports("os")
833 def watchman_hg(hg_version, hg_config, watchman):
834     if hg_version < Version("3.8"):
835         return "no (Mercurial 3.8+ required)"
837     ext_enabled = False
838     mode_disabled = False
840     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
841         if k in hg_config and hg_config[k] != "!":
842             ext_enabled = True
844     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
846     if not ext_enabled:
847         return "no (fsmonitor extension not enabled)"
848     if mode_disabled:
849         return "no (fsmonitor.mode=off disables fsmonitor)"
851     return True
854 # Miscellaneous programs
855 # ==============================================================
856 check_prog("XARGS", ("xargs",))
859 @depends(target)
860 def extra_programs(target):
861     if target.kernel == "Darwin":
862         return namespace(
863             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
864             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
865             HFS_TOOL=("hfsplus",),
866         )
867     if target.os == "GNU" and target.kernel == "Linux":
868         return namespace(RPMBUILD=("rpmbuild",))
871 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
872 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
873 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
874 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
877 @depends(target)
878 @imports("os")
879 def makensis_progs(target):
880     if target.kernel != "WINNT":
881         return
883     candidates = [
884         "makensis-3.01",
885         "makensis-3.0b3",
886         "makensis-3.0b1",
887         "makensis",
888     ]
890     # Look for nsis installed by msys environment. But only the 32-bit version.
891     # We use an absolute path and insert as the first entry so it is preferred
892     # over a 64-bit exe that may be in PATH.
893     if "MSYSTEM_PREFIX" in os.environ:
894         prefix = os.path.dirname(os.environ["MSYSTEM_PREFIX"])
895         candidates.insert(0, os.path.join(prefix, "mingw32", "bin", "makensis.exe"))
897     return tuple(candidates)
900 nsis = check_prog("MAKENSISU", makensis_progs, allow_missing=True)
902 # Make sure the version of makensis is up to date.
905 @depends(nsis, wine)
906 @checking("for NSIS version")
907 @imports("re")
908 def nsis_version(nsis, wine):
909     if not nsis:
910         return None
911     nsis_min_version = "3.0b1"
913     def onerror():
914         return die("Failed to get nsis version.")
916     if wine and nsis.lower().endswith(".exe"):
917         out = check_cmd_output(wine, nsis, "-version", onerror=onerror)
918     else:
919         out = check_cmd_output(nsis, "-version", onerror=onerror)
921     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
923     if not m:
924         raise FatalCheckError("Unknown version of makensis")
925     ver = Version(m.group(0))
927     # Versions comparisons don't quite work well with beta versions, so ensure
928     # it works for the non-beta version.
929     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
930         raise FatalCheckError(
931             "To build the installer you must have NSIS"
932             " version %s or greater in your path" % nsis_min_version
933         )
935     return ver
938 # And that makensis is 32-bit (but only on Windows).
939 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
940 @checking("for 32-bit NSIS")
941 def nsis_binary_type(nsis):
942     bin_type = windows_binary_type(nsis)
943     if bin_type != "win32":
944         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
946     return "yes"
949 # And any flags we have to give to makensis
950 @depends(host)
951 def nsis_flags(host):
952     if host.kernel != "WINNT":
953         return "-nocd"
954     return ""
957 set_config("MAKENSISU_FLAGS", nsis_flags)
959 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
960 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
963 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
964 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
965     clang = None
966     for compiler in (host_c_compiler, c_compiler):
967         if compiler and compiler.type == "clang":
968             clang = compiler.compiler
969             break
970         elif compiler and compiler.type == "clang-cl":
971             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
972             break
974     if not clang and bindgen_config_paths:
975         clang = bindgen_config_paths.clang_path
976     llvm_objdump = "llvm-objdump"
977     if clang:
978         out = check_cmd_output(
979             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
980         )
981         if out:
982             llvm_objdump = out.rstrip()
983     return (llvm_objdump,)
986 llvm_objdump = check_prog(
987     "LLVM_OBJDUMP",
988     llvm_objdump,
989     what="llvm-objdump",
990     when="--enable-compile-environment",
991     paths=clang_search_path,
994 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
997 option("--enable-dtrace", help="Build with dtrace support")
999 dtrace = check_header(
1000     "sys/sdt.h",
1001     when="--enable-dtrace",
1002     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
1005 set_config("HAVE_DTRACE", True, when=dtrace)
1006 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
1007 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
1010 option("--disable-icf", help="Disable Identical Code Folding")
1012 add_old_configure_assignment(
1013     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
1017 option(
1018     "--enable-strip",
1019     when=compile_environment,
1020     help="Enable stripping of libs & executables",
1023 # This should be handled as a `when` once bug 1617793 is fixed.
1026 @depends("--enable-strip", c_compiler, when=compile_environment)
1027 def enable_strip(strip, c_compiler):
1028     if strip and c_compiler.type != "clang-cl":
1029         return True
1032 set_config("ENABLE_STRIP", enable_strip)
1034 option(
1035     "--disable-install-strip",
1036     when=compile_environment,
1037     help="Enable stripping of libs & executables when packaging",
1040 # This should be handled as a `when` once bug 1617793 is fixed.
1043 @depends("--enable-install-strip", c_compiler, when=compile_environment)
1044 def enable_install_strip(strip, c_compiler):
1045     if strip and c_compiler.type != "clang-cl":
1046         return True
1049 set_config("PKG_STRIP", enable_install_strip)
1052 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1053 def strip(strip, install_strip):
1054     return strip or install_strip
1057 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1060 @depends("STRIP_FLAGS", profiling, target, when=strip)
1061 def strip_flags(flags, profiling, target):
1062     if flags:
1063         return flags[0].split()
1064     if profiling:
1065         # Only strip debug info and symbols when profiling is enabled, keeping
1066         # local symbols.
1067         if target.kernel == "Darwin":
1068             return ["-S"]
1069         elif target.os == "Android":
1070             # The tooling we use with Android supports detached symbols, and the
1071             # size increase caused by local symbols are too much for mobile. So,
1072             # don't restrict the amount of stripping with a flag.
1073             return
1074         else:
1075             return ["--strip-debug"]
1076     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1077     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1078     elif target.kernel == "Darwin":
1079         return ["-x", "-S"]
1082 set_config("STRIP_FLAGS", strip_flags)
1085 @depends(js_standalone, target)
1086 def system_zlib_default(js_standalone, target):
1087     return js_standalone and target.kernel != "WINNT"
1090 option(
1091     "--with-system-zlib",
1092     nargs="?",
1093     default=system_zlib_default,
1094     help="{Use|Do not use} system libz",
1098 @depends("--with-system-zlib")
1099 def deprecated_system_zlib_path(value):
1100     if len(value) == 1:
1101         die(
1102             "--with-system-zlib=PATH is not supported anymore. Please use "
1103             "--with-system-zlib and set any necessary pkg-config environment variable."
1104         )
1107 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1109 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1110 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1113 # Please do not add configure checks from here on.
1115 # Fallthrough to autoconf-based configure
1116 include("build/moz.configure/old.configure")
1118 # JS Subconfigure.
1119 include("js/sub.configure", when=compile_environment & toolkit)
1122 @depends(check_build_environment, build_project)
1123 @imports("__sandbox__")
1124 @imports("glob")
1125 @imports(_from="os.path", _import="exists")
1126 def config_status_deps(build_env, build_project):
1128     topsrcdir = build_env.topsrcdir
1129     topobjdir = build_env.topobjdir
1131     if not topobjdir.endswith("js/src"):
1132         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1133     else:
1134         # mozconfig changes may impact js configure.
1135         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1137     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1138     if exists(confvars):
1139         extra_deps.append(confvars)
1141     return (
1142         list(__sandbox__._all_paths)
1143         + extra_deps
1144         + [
1145             os.path.join(topsrcdir, "CLOBBER"),
1146             os.path.join(topsrcdir, "configure.in"),
1147             os.path.join(topsrcdir, "js", "src", "configure.in"),
1148             os.path.join(topsrcdir, "nsprpub", "configure"),
1149             os.path.join(topsrcdir, "config", "milestone.txt"),
1150             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1151             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1152             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1153             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1154             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1155             os.path.join(topsrcdir, "python", "mozbuild", "mozbuild", "virtualenv.py"),
1156             os.path.join(topsrcdir, "aclocal.m4"),
1157             os.path.join(topsrcdir, "old-configure.in"),
1158             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1159             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1160         ]
1161         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1162     )
1165 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1166 # Please do not add anything after setting config_dep_paths.