Bug 1718992 [wpt PR 29569] - URLPattern: Remove WPT test with poor interop and other...
[gecko.git] / moz.configure
blob62873546daf09a6ba6aad47b347395395a9713e0
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 @template
251 def bootstrap_toolchain_tasks(host_or_target):
252     @depends(host_or_target, when="--enable-bootstrap")
253     @imports("os")
254     @imports(_from="mozbuild.toolchains", _import="toolchain_task_definitions")
255     @imports(_from="__builtin__", _import="Exception")
256     def bootstrap_toolchain_tasks(host_or_target):
257         prefix = {
258             ("x86", "GNU", "Linux"): "linux32",
259             ("x86_64", "GNU", "Linux"): "linux64",
260             ("aarch64", "GNU", "Linux"): "linux64-aarch64",
261             ("x86_64", "OSX", "Darwin"): "macosx64",
262             ("aarch64", "OSX", "Darwin"): "macosx64-aarch64",
263             ("x86_64", "WINNT", "WINNT"): "win64",
264         }.get((host_or_target.cpu, host_or_target.os, host_or_target.kernel))
265         if prefix:
266             try:
267                 return namespace(prefix=prefix, tasks=toolchain_task_definitions())
268             except Exception:
269                 return None
271     return bootstrap_toolchain_tasks
274 host_bootstrap_toolchain_tasks = bootstrap_toolchain_tasks(host)
275 target_bootstrap_toolchain_tasks = bootstrap_toolchain_tasks(target)
278 @template
279 def bootstrap_path(path, **kwargs):
280     when = kwargs.pop("when", None)
281     context = kwargs.pop("context", host)
282     if kwargs:
283         configure_error(
284             "bootstrap_path only takes `when` or `context` as keyword arguments"
285         )
287     bootstrap_toolchain_tasks = {
288         host: host_bootstrap_toolchain_tasks,
289         target: target_bootstrap_toolchain_tasks,
290     }[context]
292     @depends(
293         "--enable-bootstrap",
294         toolchains_base_dir,
295         bootstrap_toolchain_tasks,
296         shell,
297         check_build_environment,
298         dependable(path),
299         when=when,
300     )
301     @imports("os")
302     @imports("subprocess")
303     @imports(_from="mozbuild.util", _import="ensureParentDir")
304     @imports(_from="__builtin__", _import="open")
305     @imports(_from="__builtin__", _import="Exception")
306     def bootstrap_path(bootstrap, toolchains_base_dir, tasks, shell, build_env, path):
307         path_parts = path.split("/")
309         def try_bootstrap(exists):
310             if not tasks:
311                 return False
312             for prefix in ("{}-".format(tasks.prefix), ""):
313                 label = "toolchain-{}{}".format(prefix, path_parts[0])
314                 task = tasks.tasks.get(label)
315                 if task:
316                     break
317             log.debug("Trying to bootstrap %s", label)
318             if not task:
319                 return False
320             task_index = task.optimization.get("index-search")
321             if not task_index:
322                 return False
323             log.debug("Resolved %s to %s", label, task_index[0])
324             task_index = task_index[0].split(".")[-1]
325             artifact = task.attributes["toolchain-artifact"]
326             # `mach artifact toolchain` doesn't support authentication for
327             # private artifacts.
328             if not artifact.startswith("public/"):
329                 return False
330             index_file = os.path.join(toolchains_base_dir, "indices", path_parts[0])
331             try:
332                 with open(index_file) as fh:
333                     index = fh.read().strip()
334             except Exception:
335                 index = None
336             if index == task_index and exists:
337                 return True
338             log.info(
339                 "%s bootstrapped toolchain in %s",
340                 "Updating" if exists else "Installing",
341                 os.path.join(toolchains_base_dir, path_parts[0]),
342             )
343             subprocess.run(
344                 [
345                     shell,
346                     os.path.join(build_env.topsrcdir, "mach"),
347                     "--log-no-times",
348                     "artifact",
349                     "toolchain",
350                     "--from-build",
351                     label,
352                 ],
353                 cwd=toolchains_base_dir,
354                 check=True,
355             )
356             ensureParentDir(index_file)
357             with open(index_file, "w") as fh:
358                 fh.write(task_index)
359             return True
361         path = os.path.join(toolchains_base_dir, *path_parts)
362         if bootstrap:
363             try:
364                 if not try_bootstrap(os.path.exists(path)):
365                     # If there aren't toolchain artifacts to use for this build,
366                     # don't return a path.
367                     return None
368             except Exception as e:
369                 log.error("%s", e)
370                 die("If you can't fix the above, retry with --disable-bootstrap.")
371         # We re-test whether the path exists because it may have been created by
372         # try_bootstrap. Automation will not have gone through the bootstrap
373         # process, but we want to return the path if it exists.
374         if os.path.exists(path):
375             return path
377     return bootstrap_path
380 @template
381 def bootstrap_search_path(path, paths=original_path, **kwargs):
382     @depends(
383         bootstrap_path(path, **kwargs),
384         bootstrap_search_path_order,
385         paths,
386         original_path,
387     )
388     def bootstrap_search_path(path, order, paths, original_path):
389         if paths is None:
390             paths = original_path
391         if not path:
392             return paths
393         if order == "prepend":
394             return [path] + paths
395         return paths + [path]
397     return bootstrap_search_path
400 # The execution model of the configure sandbox doesn't allow for
401 # check_prog to use bootstrap_search_path directly because check_prog
402 # comes first, so we use a trick to allow it. No use of check_prog
403 # happening before here won't allow bootstrap.
404 @template
405 def check_prog(*args, **kwargs):
406     kwargs["bootstrap_search_path"] = bootstrap_search_path
407     return check_prog(*args, **kwargs)
410 @depends(target, host)
411 def want_wine(target, host):
412     return target.kernel == "WINNT" and host.kernel != "WINNT"
415 wine = check_prog(
416     "WINE",
417     ["wine64", "wine"],
418     allow_missing=True,
419     when=want_wine,
420     bootstrap="wine/bin",
422 check_prog("WGET", ("wget",), allow_missing=True)
425 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
427 include("build/moz.configure/pkg.configure")
428 # Make this assignment here rather than in pkg.configure to avoid
429 # requiring this file in unit tests.
430 add_old_configure_assignment("PKG_CONFIG", pkg_config)
432 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
433 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
434 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
435 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
436 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
437 # rust.configure is included by js/moz.configure.
439 option("--enable-valgrind", help="Enable Valgrind integration hooks")
441 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
444 @depends("--enable-valgrind", valgrind_h)
445 def check_valgrind(valgrind, valgrind_h):
446     if valgrind:
447         if not valgrind_h:
448             die("--enable-valgrind specified but Valgrind is not installed")
449         return True
452 set_define("MOZ_VALGRIND", check_valgrind)
453 set_config("MOZ_VALGRIND", check_valgrind)
456 @depends(target, host)
457 def is_openbsd(target, host):
458     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
461 option(
462     env="SO_VERSION",
463     nargs=1,
464     default="1.0",
465     when=is_openbsd,
466     help="Shared library version for OpenBSD systems",
470 @depends("SO_VERSION", when=is_openbsd)
471 def so_version(value):
472     return value
475 @template
476 def library_name_info_template(host_or_target):
477     assert host_or_target in {host, target}
478     compiler = {
479         host: host_c_compiler,
480         target: c_compiler,
481     }[host_or_target]
483     @depends(host_or_target, compiler, so_version)
484     def library_name_info_impl(host_or_target, compiler, so_version):
485         if host_or_target.kernel == "WINNT":
486             # There aren't artifacts for mingw builds, so it's OK that the
487             # results are inaccurate in that case.
488             if compiler and compiler.type != "clang-cl":
489                 return namespace(
490                     dll=namespace(prefix="", suffix=".dll"),
491                     lib=namespace(prefix="lib", suffix="a"),
492                     import_lib=namespace(prefix="lib", suffix="a"),
493                     obj=namespace(prefix="", suffix="o"),
494                 )
496             return namespace(
497                 dll=namespace(prefix="", suffix=".dll"),
498                 lib=namespace(prefix="", suffix="lib"),
499                 import_lib=namespace(prefix="", suffix="lib"),
500                 obj=namespace(prefix="", suffix="obj"),
501             )
503         elif host_or_target.kernel == "Darwin":
504             return namespace(
505                 dll=namespace(prefix="lib", suffix=".dylib"),
506                 lib=namespace(prefix="lib", suffix="a"),
507                 import_lib=namespace(prefix=None, suffix=""),
508                 obj=namespace(prefix="", suffix="o"),
509             )
510         elif so_version:
511             so = ".so.%s" % so_version
512         else:
513             so = ".so"
515         return namespace(
516             dll=namespace(prefix="lib", suffix=so),
517             lib=namespace(prefix="lib", suffix="a"),
518             import_lib=namespace(prefix=None, suffix=""),
519             obj=namespace(prefix="", suffix="o"),
520         )
522     return library_name_info_impl
525 host_library_name_info = library_name_info_template(host)
526 library_name_info = library_name_info_template(target)
528 set_config("DLL_PREFIX", library_name_info.dll.prefix)
529 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
530 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
531 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
532 set_config("LIB_PREFIX", library_name_info.lib.prefix)
533 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
534 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
535 # Lots of compilation tests depend on this variable being present.
536 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
537 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
538 set_define(
539     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
541 set_define(
542     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
544 set_config("WASM_OBJ_SUFFIX", "wasm")
546 # Make `profiling` available to this file even when js/moz.configure
547 # doesn't end up included.
548 profiling = dependable(False)
549 # Same for js_standalone
550 js_standalone = dependable(False)
551 # Same for fold_libs
552 fold_libs = dependable(False)
554 include(include_project_configure)
557 @depends("--help")
558 @imports(_from="mozbuild.backend", _import="backends")
559 def build_backends_choices(_):
560     return tuple(backends)
563 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
564 def build_backend(backends):
565     if backends:
566         return tuple("+%s" % b for b in backends)
569 imply_option("--build-backends", build_backend)
572 @depends(
573     "--enable-artifact-builds",
574     "--disable-compile-environment",
575     "--enable-build-backend",
576     "--enable-project",
577     "--enable-application",
578     "--help",
580 @imports("sys")
581 def build_backend_defaults(
582     artifact_builds, compile_environment, requested_backends, project, application, _
584     if application:
585         project = application[0]
586     elif project:
587         project = project[0]
589     if "Tup" in requested_backends:
590         # As a special case, if Tup was requested, do not combine it with any
591         # Make based backend by default.
592         all_backends = []
593     elif artifact_builds:
594         all_backends = ["FasterMake+RecursiveMake"]
595     else:
596         all_backends = ["RecursiveMake", "FasterMake"]
597     # Normally, we'd use target.os == 'WINNT', but a dependency on target
598     # would require target to depend on --help, as well as host and shell,
599     # and this is not a can of worms we can open at the moment.
600     if (
601         sys.platform == "win32"
602         and compile_environment
603         and project not in ("mobile/android", "memory", "tools/update-programs")
604     ):
605         all_backends.append("VisualStudio")
606     return tuple(all_backends) or None
609 option(
610     "--build-backends",
611     nargs="+",
612     default=build_backend_defaults,
613     choices=build_backends_choices,
614     help="Build backends to generate",
618 @depends("--build-backends")
619 def build_backends(backends):
620     return backends
623 set_config("BUILD_BACKENDS", build_backends)
626 @depends(check_build_environment, build_backends)
627 @imports("glob")
628 def check_objdir_backend_reuse(build_env, backends):
629     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
630     # intentionally vague for use with the substring match below.
631     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
632     for backend_file in glob.iglob(
633         os.path.join(build_env.topobjdir, "backend.*Backend")
634     ):
635         for prev, curr in incompatible_backends:
636             if prev in backend_file and any(curr in b for b in backends):
637                 die(
638                     "The active objdir, %s, was previously "
639                     "used to build with a %s based backend. "
640                     "Change objdirs (by setting MOZ_OBJDIR in "
641                     "your mozconfig) or clobber to continue.\n",
642                     build_env.topobjdir,
643                     prev,
644                 )
647 option(
648     "--disable-gtest-in-build",
649     help="Force disable building the gtest libxul during the build.",
650     when="--enable-compile-environment",
653 # Determine whether to build the gtest xul. This happens in automation
654 # on Android and Desktop platforms with the exception of:
655 #  - Windows PGO, where linking xul-gtest.dll takes too long;
656 #  - Android other than x86_64, where gtest is not required.
659 @depends(
660     "MOZ_PGO",
661     build_project,
662     target,
663     "MOZ_AUTOMATION",
664     "--disable-gtest-in-build",
665     enable_tests,
666     when="--enable-compile-environment",
668 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
669     if not enable_tests or not enabled:
670         return None
671     if (
672         automation
673         and build_project in ("browser", "comm/mail", "mobile/android")
674         and not (
675             (pgo and target.os == "WINNT")
676             or (target.os == "Android" and target.cpu != "x86_64")
677         )
678     ):
679         return True
682 set_config("LINK_GTEST_DURING_COMPILE", build_gtest)
684 # Localization
685 # ==============================================================
686 option(
687     "--enable-ui-locale",
688     default="en-US",
689     help="Select the user interface locale (default: en-US)",
692 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
694 # clang-plugin location
695 # ==============================================================
698 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
699 def clang_plugin_path(library_name_info, build_env):
700     topobjdir = build_env.topobjdir
701     if topobjdir.endswith("/js/src"):
702         topobjdir = topobjdir[:-7]
703     return os.path.abspath(
704         os.path.join(
705             topobjdir,
706             "build",
707             "clang-plugin",
708             "%sclang-plugin%s"
709             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
710         )
711     )
714 set_config("CLANG_PLUGIN", clang_plugin_path)
715 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
718 # Awk detection
719 # ==============================================================
720 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
722 # Until the AWK variable is not necessary in old-configure
725 @depends(awk)
726 def awk_for_old_configure(value):
727     return value
730 add_old_configure_assignment("AWK", awk_for_old_configure)
733 # Perl detection
734 # ==============================================================
735 perl = check_prog("PERL", ("perl5", "perl"))
737 # Until the PERL variable is not necessary in old-configure
740 @depends(perl)
741 def perl_for_old_configure(value):
742     return value
745 add_old_configure_assignment("PERL", perl_for_old_configure)
748 @template
749 def perl_version_check(min_version):
750     @depends(perl)
751     @checking("for minimum required perl version >= %s" % min_version)
752     def get_perl_version(perl):
753         return Version(
754             check_cmd_output(
755                 perl,
756                 "-e",
757                 "print $]",
758                 onerror=lambda: die("Failed to get perl version."),
759             )
760         )
762     @depends(get_perl_version)
763     def check_perl_version(version):
764         if version < min_version:
765             die("Perl %s or higher is required.", min_version)
767     @depends(perl)
768     @checking("for full perl installation")
769     @imports("subprocess")
770     def has_full_perl_installation(perl):
771         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
772         return ret == 0
774     @depends(has_full_perl_installation)
775     def require_full_perl_installation(has_full_perl_installation):
776         if not has_full_perl_installation:
777             die(
778                 "Cannot find Config.pm or $Config{archlib}. "
779                 "A full perl installation is required."
780             )
783 perl_version_check("5.006")
786 # GNU make detection
787 # ==============================================================
788 option(env="MAKE", nargs=1, help="Path to GNU make")
791 @depends("MAKE", host)
792 def possible_makes(make, host):
793     candidates = []
794     if host.kernel == "WINNT":
795         candidates.append("mingw32-make")
796     if make:
797         candidates.append(make[0])
798     if host.kernel == "WINNT":
799         candidates.extend(("mozmake", "make", "gmake"))
800     else:
801         candidates.extend(("gmake", "make"))
802     return candidates
805 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
807 # watchman detection
808 # ==============================================================
810 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
813 @depends(host, "WATCHMAN")
814 @checking("for watchman", callback=lambda w: w.path if w else "not found")
815 def watchman(host, prog):
816     # On Windows, `watchman` is only supported on 64-bit hosts.
817     if host.os == "WINNT" and host.cpu != "x86_64":
818         return
820     if not prog:
821         prog = find_program("watchman")
823     if not prog:
824         return
826     # `watchman version` will talk to the Watchman daemon service.
827     # This can hang due to permissions problems. e.g.
828     # https://github.com/facebook/watchman/issues/376. So use
829     # `watchman --version` to prevent a class of failures.
830     out = check_cmd_output(prog, "--version", onerror=lambda: None)
831     if out is None:
832         return
834     return namespace(path=prog, version=Version(out.strip()))
837 @depends_if(watchman)
838 @checking("for watchman version")
839 def watchman_version(w):
840     return w.version
843 set_config("WATCHMAN", watchman.path)
846 @depends_all(hg_version, hg_config, watchman)
847 @checking("for watchman Mercurial integration")
848 @imports("os")
849 def watchman_hg(hg_version, hg_config, watchman):
850     if hg_version < Version("3.8"):
851         return "no (Mercurial 3.8+ required)"
853     ext_enabled = False
854     mode_disabled = False
856     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
857         if k in hg_config and hg_config[k] != "!":
858             ext_enabled = True
860     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
862     if not ext_enabled:
863         return "no (fsmonitor extension not enabled)"
864     if mode_disabled:
865         return "no (fsmonitor.mode=off disables fsmonitor)"
867     return True
870 # Miscellaneous programs
871 # ==============================================================
872 check_prog("XARGS", ("xargs",))
875 @depends(target)
876 def extra_programs(target):
877     if target.kernel == "Darwin":
878         return namespace(
879             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
880             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
881             HFS_TOOL=("hfsplus",),
882         )
883     if target.os == "GNU" and target.kernel == "Linux":
884         return namespace(RPMBUILD=("rpmbuild",))
887 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
888 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
889 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
890 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
893 @depends(target)
894 @imports("os")
895 def makensis_progs(target):
896     if target.kernel != "WINNT":
897         return
899     candidates = [
900         "makensis-3.01",
901         "makensis-3.0b3",
902         "makensis-3.0b1",
903         "makensis",
904     ]
906     # Look for nsis installed by msys environment. But only the 32-bit version.
907     # We use an absolute path and insert as the first entry so it is preferred
908     # over a 64-bit exe that may be in PATH.
909     if "MSYSTEM_PREFIX" in os.environ:
910         prefix = os.path.dirname(os.environ["MSYSTEM_PREFIX"])
911         candidates.insert(0, os.path.join(prefix, "mingw32", "bin", "makensis.exe"))
913     return tuple(candidates)
916 nsis = check_prog("MAKENSISU", makensis_progs, allow_missing=True)
918 # Make sure the version of makensis is up to date.
921 @depends(nsis, wine)
922 @checking("for NSIS version")
923 @imports("re")
924 def nsis_version(nsis, wine):
925     if not nsis:
926         return None
927     nsis_min_version = "3.0b1"
929     def onerror():
930         return die("Failed to get nsis version.")
932     if wine and nsis.lower().endswith(".exe"):
933         out = check_cmd_output(wine, nsis, "-version", onerror=onerror)
934     else:
935         out = check_cmd_output(nsis, "-version", onerror=onerror)
937     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
939     if not m:
940         raise FatalCheckError("Unknown version of makensis")
941     ver = Version(m.group(0))
943     # Versions comparisons don't quite work well with beta versions, so ensure
944     # it works for the non-beta version.
945     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
946         raise FatalCheckError(
947             "To build the installer you must have NSIS"
948             " version %s or greater in your path" % nsis_min_version
949         )
951     return ver
954 # And that makensis is 32-bit (but only on Windows).
955 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
956 @checking("for 32-bit NSIS")
957 def nsis_binary_type(nsis):
958     bin_type = windows_binary_type(nsis)
959     if bin_type != "win32":
960         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
962     return "yes"
965 # And any flags we have to give to makensis
966 @depends(host)
967 def nsis_flags(host):
968     if host.kernel != "WINNT":
969         return "-nocd"
970     return ""
973 set_config("MAKENSISU_FLAGS", nsis_flags)
975 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
976 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
979 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
980 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
981     clang = None
982     for compiler in (host_c_compiler, c_compiler):
983         if compiler and compiler.type == "clang":
984             clang = compiler.compiler
985             break
986         elif compiler and compiler.type == "clang-cl":
987             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
988             break
990     if not clang and bindgen_config_paths:
991         clang = bindgen_config_paths.clang_path
992     llvm_objdump = "llvm-objdump"
993     if clang:
994         out = check_cmd_output(
995             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
996         )
997         if out:
998             llvm_objdump = out.rstrip()
999     return (llvm_objdump,)
1002 llvm_objdump = check_prog(
1003     "LLVM_OBJDUMP",
1004     llvm_objdump,
1005     what="llvm-objdump",
1006     when="--enable-compile-environment",
1007     paths=clang_search_path,
1010 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
1013 option("--enable-dtrace", help="Build with dtrace support")
1015 dtrace = check_header(
1016     "sys/sdt.h",
1017     when="--enable-dtrace",
1018     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
1021 set_config("HAVE_DTRACE", True, when=dtrace)
1022 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
1023 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
1026 option("--disable-icf", help="Disable Identical Code Folding")
1028 add_old_configure_assignment(
1029     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
1033 option(
1034     "--enable-strip",
1035     when=compile_environment,
1036     help="Enable stripping of libs & executables",
1039 # This should be handled as a `when` once bug 1617793 is fixed.
1042 @depends("--enable-strip", c_compiler, when=compile_environment)
1043 def enable_strip(strip, c_compiler):
1044     if strip and c_compiler.type != "clang-cl":
1045         return True
1048 set_config("ENABLE_STRIP", enable_strip)
1050 option(
1051     "--disable-install-strip",
1052     when=compile_environment,
1053     help="Enable stripping of libs & executables when packaging",
1056 # This should be handled as a `when` once bug 1617793 is fixed.
1059 @depends("--enable-install-strip", c_compiler, when=compile_environment)
1060 def enable_install_strip(strip, c_compiler):
1061     if strip and c_compiler.type != "clang-cl":
1062         return True
1065 set_config("PKG_STRIP", enable_install_strip)
1068 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1069 def strip(strip, install_strip):
1070     return strip or install_strip
1073 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1076 @depends("STRIP_FLAGS", profiling, target, when=strip)
1077 def strip_flags(flags, profiling, target):
1078     if flags:
1079         return flags[0].split()
1080     if profiling:
1081         # Only strip debug info and symbols when profiling is enabled, keeping
1082         # local symbols.
1083         if target.kernel == "Darwin":
1084             return ["-S"]
1085         elif target.os == "Android":
1086             # The tooling we use with Android supports detached symbols, and the
1087             # size increase caused by local symbols are too much for mobile. So,
1088             # don't restrict the amount of stripping with a flag.
1089             return
1090         else:
1091             return ["--strip-debug"]
1092     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1093     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1094     elif target.kernel == "Darwin":
1095         return ["-x", "-S"]
1098 set_config("STRIP_FLAGS", strip_flags)
1101 @depends(js_standalone, target)
1102 def system_zlib_default(js_standalone, target):
1103     return js_standalone and target.kernel != "WINNT"
1106 option(
1107     "--with-system-zlib",
1108     nargs="?",
1109     default=system_zlib_default,
1110     help="{Use|Do not use} system libz",
1114 @depends("--with-system-zlib")
1115 def deprecated_system_zlib_path(value):
1116     if len(value) == 1:
1117         die(
1118             "--with-system-zlib=PATH is not supported anymore. Please use "
1119             "--with-system-zlib and set any necessary pkg-config environment variable."
1120         )
1123 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1125 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1126 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1129 # Please do not add configure checks from here on.
1131 # Fallthrough to autoconf-based configure
1132 include("build/moz.configure/old.configure")
1134 # JS Subconfigure.
1135 include("js/sub.configure", when=compile_environment & toolkit)
1138 @depends(check_build_environment, build_project)
1139 @imports("__sandbox__")
1140 @imports("glob")
1141 @imports(_from="os.path", _import="exists")
1142 def config_status_deps(build_env, build_project):
1144     topsrcdir = build_env.topsrcdir
1145     topobjdir = build_env.topobjdir
1147     if not topobjdir.endswith("js/src"):
1148         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1149     else:
1150         # mozconfig changes may impact js configure.
1151         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1153     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1154     if exists(confvars):
1155         extra_deps.append(confvars)
1157     return (
1158         list(__sandbox__._all_paths)
1159         + extra_deps
1160         + [
1161             os.path.join(topsrcdir, "CLOBBER"),
1162             os.path.join(topsrcdir, "configure.in"),
1163             os.path.join(topsrcdir, "js", "src", "configure.in"),
1164             os.path.join(topsrcdir, "nsprpub", "configure"),
1165             os.path.join(topsrcdir, "config", "milestone.txt"),
1166             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1167             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1168             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1169             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1170             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1171             os.path.join(topsrcdir, "python", "mozbuild", "mozbuild", "virtualenv.py"),
1172             os.path.join(topsrcdir, "aclocal.m4"),
1173             os.path.join(topsrcdir, "old-configure.in"),
1174             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1175             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1176         ]
1177         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1178     )
1181 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1182 # Please do not add anything after setting config_dep_paths.