Bug 1738926 Part 1: Check if sublayers need to be rebuilt. r=mstange
[gecko.git] / moz.configure
blob5a103d844cc1506c47377c19ed5a0cbe47c017db
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 # hybrid build handling
183 # ==============================================================
185 option(
186     "--disable-unified-build",
187     help="Enable building modules that are not marked with `REQUIRES_UNIFIED_BUILD` in non unified context",
190 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
193 option(
194     env="MOZ_FETCHES_DIR",
195     nargs=1,
196     when="MOZ_AUTOMATION",
197     help="Directory containing fetched artifacts",
201 @depends("MOZ_FETCHES_DIR", when="MOZ_AUTOMATION")
202 def moz_fetches_dir(value):
203     if value:
204         return value[0]
207 @depends(vcs_checkout_type, milestone.is_nightly, "MOZ_AUTOMATION")
208 def bootstrap_default(vcs_checkout_type, is_nightly, automation):
209     if automation:
210         return False
211     # We only enable if building off a VCS checkout of central.
212     if is_nightly and vcs_checkout_type:
213         return True
216 option(
217     "--enable-bootstrap",
218     default=bootstrap_default,
219     help="{Automatically bootstrap or update some toolchains|Disable bootstrap or update of toolchains}",
223 @depends(developer_options, "--enable-bootstrap", moz_fetches_dir)
224 def bootstrap_search_path_order(developer_options, bootstrap, moz_fetches_dir):
225     if moz_fetches_dir:
226         log.debug("Prioritizing MOZ_FETCHES_DIR in toolchain path.")
227         return "prepend"
229     if bootstrap:
230         log.debug(
231             "Prioritizing mozbuild state dir in toolchain paths because "
232             "bootstrap mode is enabled."
233         )
234         return "prepend"
236     if developer_options:
237         log.debug(
238             "Prioritizing mozbuild state dir in toolchain paths because "
239             "you are not building in release mode."
240         )
241         return "prepend"
243     log.debug(
244         "Prioritizing system over mozbuild state dir in "
245         "toolchain paths because you are building in "
246         "release mode."
247     )
248     return "append"
251 toolchains_base_dir = moz_fetches_dir | mozbuild_state_path
254 @dependable
255 @imports("os")
256 @imports(_from="os", _import="environ")
257 def original_path():
258     return environ["PATH"].split(os.pathsep)
261 @depends(host, when="--enable-bootstrap")
262 @imports("os")
263 @imports("traceback")
264 @imports(_from="mozbuild.toolchains", _import="toolchain_task_definitions")
265 @imports(_from="__builtin__", _import="Exception")
266 def bootstrap_toolchain_tasks(host):
267     prefix = {
268         ("x86_64", "GNU", "Linux"): "linux64",
269         ("x86_64", "OSX", "Darwin"): "macosx64",
270         ("aarch64", "OSX", "Darwin"): "macosx64-aarch64",
271         ("x86_64", "WINNT", "WINNT"): "win64",
272     }.get((host.cpu, host.os, host.kernel))
273     try:
274         return namespace(prefix=prefix, tasks=toolchain_task_definitions())
275     except Exception as e:
276         message = traceback.format_exc()
277         log.warning(str(e))
278         log.debug(message)
279         return None
282 @template
283 def bootstrap_path(path, **kwargs):
284     when = kwargs.pop("when", None)
285     if kwargs:
286         configure_error("bootstrap_path only takes `when` as a keyword argument")
288     @depends(
289         "--enable-bootstrap",
290         toolchains_base_dir,
291         bootstrap_toolchain_tasks,
292         shell,
293         check_build_environment,
294         dependable(path),
295         when=when,
296     )
297     @imports("os")
298     @imports("subprocess")
299     @imports(_from="mozbuild.util", _import="ensureParentDir")
300     @imports(_from="__builtin__", _import="open")
301     @imports(_from="__builtin__", _import="Exception")
302     def bootstrap_path(bootstrap, toolchains_base_dir, tasks, shell, build_env, path):
303         path_parts = path.split("/")
305         def try_bootstrap(exists):
306             if not tasks:
307                 return False
308             prefixes = [""]
309             if tasks.prefix:
310                 prefixes.insert(0, "{}-".format(tasks.prefix))
311             for prefix in prefixes:
312                 label = "toolchain-{}{}".format(prefix, path_parts[0])
313                 task = tasks.tasks.get(label)
314                 if task:
315                     break
316             log.debug("Trying to bootstrap %s", label)
317             if not task:
318                 return False
319             task_index = task.optimization.get("index-search")
320             if not task_index:
321                 return False
322             log.debug("Resolved %s to %s", label, task_index[0])
323             task_index = task_index[0].split(".")[-1]
324             artifact = task.attributes["toolchain-artifact"]
325             # `mach artifact toolchain` doesn't support authentication for
326             # private artifacts.
327             if not artifact.startswith("public/"):
328                 log.debug("Cannot bootstrap %s: not a public artifact", label)
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                 log.debug("%s is up-to-date", label)
338                 return True
339             log.info(
340                 "%s bootstrapped toolchain in %s",
341                 "Updating" if exists else "Installing",
342                 os.path.join(toolchains_base_dir, path_parts[0]),
343             )
344             subprocess.run(
345                 [
346                     shell,
347                     os.path.join(build_env.topsrcdir, "mach"),
348                     "--log-no-times",
349                     "artifact",
350                     "toolchain",
351                     "--from-build",
352                     label,
353                 ],
354                 cwd=toolchains_base_dir,
355                 check=True,
356             )
357             ensureParentDir(index_file)
358             with open(index_file, "w") as fh:
359                 fh.write(task_index)
360             return True
362         path = os.path.join(toolchains_base_dir, *path_parts)
363         if bootstrap:
364             try:
365                 if not try_bootstrap(os.path.exists(path)):
366                     # If there aren't toolchain artifacts to use for this build,
367                     # don't return a path.
368                     return None
369             except Exception as e:
370                 log.error("%s", e)
371                 die("If you can't fix the above, retry with --disable-bootstrap.")
372         # We re-test whether the path exists because it may have been created by
373         # try_bootstrap. Automation will not have gone through the bootstrap
374         # process, but we want to return the path if it exists.
375         if os.path.exists(path):
376             return path
378     return bootstrap_path
381 @template
382 def bootstrap_search_path(path, paths=original_path, **kwargs):
383     @depends(
384         bootstrap_path(path, **kwargs),
385         bootstrap_search_path_order,
386         paths,
387         original_path,
388     )
389     def bootstrap_search_path(path, order, paths, original_path):
390         if paths is None:
391             paths = original_path
392         if not path:
393             return paths
394         if order == "prepend":
395             return [path] + paths
396         return paths + [path]
398     return bootstrap_search_path
401 # The execution model of the configure sandbox doesn't allow for
402 # check_prog to use bootstrap_search_path directly because check_prog
403 # comes first, so we use a trick to allow it. Uses of check_prog
404 # happening before here won't allow bootstrap.
405 @template
406 def check_prog(*args, **kwargs):
407     kwargs["bootstrap_search_path"] = bootstrap_search_path
408     return check_prog(*args, **kwargs)
411 check_prog("WGET", ("wget",), allow_missing=True)
414 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
416 include("build/moz.configure/pkg.configure")
417 # Make this assignment here rather than in pkg.configure to avoid
418 # requiring this file in unit tests.
419 add_old_configure_assignment("PKG_CONFIG", pkg_config)
421 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
422 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
423 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
424 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
425 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
426 # rust.configure is included by js/moz.configure.
428 option("--enable-valgrind", help="Enable Valgrind integration hooks")
430 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
433 @depends("--enable-valgrind", valgrind_h)
434 def check_valgrind(valgrind, valgrind_h):
435     if valgrind:
436         if not valgrind_h:
437             die("--enable-valgrind specified but Valgrind is not installed")
438         return True
441 set_define("MOZ_VALGRIND", check_valgrind)
442 set_config("MOZ_VALGRIND", check_valgrind)
445 @depends(target, host)
446 def is_openbsd(target, host):
447     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
450 option(
451     env="SO_VERSION",
452     nargs=1,
453     default="1.0",
454     when=is_openbsd,
455     help="Shared library version for OpenBSD systems",
459 @depends("SO_VERSION", when=is_openbsd)
460 def so_version(value):
461     return value
464 @template
465 def library_name_info_template(host_or_target):
466     assert host_or_target in {host, target}
467     compiler = {
468         host: host_c_compiler,
469         target: c_compiler,
470     }[host_or_target]
472     @depends(host_or_target, compiler, so_version)
473     def library_name_info_impl(host_or_target, compiler, so_version):
474         if host_or_target.kernel == "WINNT":
475             # There aren't artifacts for mingw builds, so it's OK that the
476             # results are inaccurate in that case.
477             if compiler and compiler.type != "clang-cl":
478                 return namespace(
479                     dll=namespace(prefix="", suffix=".dll"),
480                     lib=namespace(prefix="lib", suffix="a"),
481                     import_lib=namespace(prefix="lib", suffix="a"),
482                     obj=namespace(prefix="", suffix="o"),
483                 )
485             return namespace(
486                 dll=namespace(prefix="", suffix=".dll"),
487                 lib=namespace(prefix="", suffix="lib"),
488                 import_lib=namespace(prefix="", suffix="lib"),
489                 obj=namespace(prefix="", suffix="obj"),
490             )
492         elif host_or_target.kernel == "Darwin":
493             return namespace(
494                 dll=namespace(prefix="lib", suffix=".dylib"),
495                 lib=namespace(prefix="lib", suffix="a"),
496                 import_lib=namespace(prefix=None, suffix=""),
497                 obj=namespace(prefix="", suffix="o"),
498             )
499         elif so_version:
500             so = ".so.%s" % so_version
501         else:
502             so = ".so"
504         return namespace(
505             dll=namespace(prefix="lib", suffix=so),
506             lib=namespace(prefix="lib", suffix="a"),
507             import_lib=namespace(prefix=None, suffix=""),
508             obj=namespace(prefix="", suffix="o"),
509         )
511     return library_name_info_impl
514 host_library_name_info = library_name_info_template(host)
515 library_name_info = library_name_info_template(target)
517 set_config("DLL_PREFIX", library_name_info.dll.prefix)
518 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
519 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
520 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
521 set_config("LIB_PREFIX", library_name_info.lib.prefix)
522 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
523 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
524 # Lots of compilation tests depend on this variable being present.
525 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
526 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
527 set_define(
528     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
530 set_define(
531     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
533 set_config("WASM_OBJ_SUFFIX", "wasm")
535 # Make `profiling` available to this file even when js/moz.configure
536 # doesn't end up included.
537 profiling = dependable(False)
538 # Same for js_standalone
539 js_standalone = dependable(False)
540 # Same for fold_libs
541 fold_libs = dependable(False)
543 include(include_project_configure)
546 @depends("--help")
547 @imports(_from="mozbuild.backend", _import="backends")
548 def build_backends_choices(_):
549     return tuple(backends)
552 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
553 def build_backend(backends):
554     if backends:
555         return tuple("+%s" % b for b in backends)
558 imply_option("--build-backends", build_backend)
561 @depends(
562     "--enable-artifact-builds",
563     "--disable-compile-environment",
564     "--enable-build-backend",
565     "--enable-project",
566     "--enable-application",
567     "--help",
569 @imports("sys")
570 def build_backend_defaults(
571     artifact_builds, compile_environment, requested_backends, project, application, _
573     if application:
574         project = application[0]
575     elif project:
576         project = project[0]
578     if "Tup" in requested_backends:
579         # As a special case, if Tup was requested, do not combine it with any
580         # Make based backend by default.
581         all_backends = []
582     elif artifact_builds:
583         all_backends = ["FasterMake+RecursiveMake"]
584     else:
585         all_backends = ["RecursiveMake", "FasterMake"]
586     # Normally, we'd use target.os == 'WINNT', but a dependency on target
587     # would require target to depend on --help, as well as host and shell,
588     # and this is not a can of worms we can open at the moment.
589     if (
590         sys.platform == "win32"
591         and compile_environment
592         and project not in ("mobile/android", "memory", "tools/update-programs")
593     ):
594         all_backends.append("VisualStudio")
595     return tuple(all_backends) or None
598 option(
599     "--build-backends",
600     nargs="+",
601     default=build_backend_defaults,
602     choices=build_backends_choices,
603     help="Build backends to generate",
607 @depends("--build-backends")
608 def build_backends(backends):
609     return backends
612 set_config("BUILD_BACKENDS", build_backends)
615 @depends(check_build_environment, build_backends)
616 @imports("glob")
617 def check_objdir_backend_reuse(build_env, backends):
618     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
619     # intentionally vague for use with the substring match below.
620     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
621     for backend_file in glob.iglob(
622         os.path.join(build_env.topobjdir, "backend.*Backend")
623     ):
624         for prev, curr in incompatible_backends:
625             if prev in backend_file and any(curr in b for b in backends):
626                 die(
627                     "The active objdir, %s, was previously "
628                     "used to build with a %s based backend. "
629                     "Change objdirs (by setting MOZ_OBJDIR in "
630                     "your mozconfig) or clobber to continue.\n",
631                     build_env.topobjdir,
632                     prev,
633                 )
636 # Determine whether to build the gtest xul. This happens in automation
637 # on Android and Desktop platforms with the exception of:
638 #  - Windows PGO, where linking xul-gtest.dll takes too long;
639 #  - Android other than x86_64, where gtest is not required.
640 @depends(
641     "MOZ_PGO",
642     build_project,
643     target,
644     "MOZ_AUTOMATION",
645     enable_tests,
646     when="--enable-compile-environment",
648 def build_gtest(pgo, build_project, target, automation, enable_tests):
649     return bool(
650         enable_tests
651         and automation
652         and build_project in ("browser", "comm/mail", "mobile/android")
653         and not (
654             (pgo and target.os == "WINNT")
655             or (target.os == "Android" and target.cpu != "x86_64")
656         )
657     )
660 option(
661     "--enable-gtest-in-build",
662     default=build_gtest,
663     help="{Enable|Force disable} building the gtest libxul during the build.",
664     when="--enable-compile-environment",
667 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
669 # Localization
670 # ==============================================================
671 option(
672     "--enable-ui-locale",
673     default="en-US",
674     help="Select the user interface locale (default: en-US)",
677 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
679 option(
680     "--enable-icu4x",
681     help="An experiment to use ICU4X instead of ICU4C. See intl/ICU4X.md",
684 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
686 # clang-plugin location
687 # ==============================================================
690 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
691 def clang_plugin_path(library_name_info, build_env):
692     topobjdir = build_env.topobjdir
693     if topobjdir.endswith("/js/src"):
694         topobjdir = topobjdir[:-7]
695     return os.path.abspath(
696         os.path.join(
697             topobjdir,
698             "build",
699             "clang-plugin",
700             "%sclang-plugin%s"
701             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
702         )
703     )
706 set_config("CLANG_PLUGIN", clang_plugin_path)
707 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
710 # Awk detection
711 # ==============================================================
712 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
714 # Until the AWK variable is not necessary in old-configure
717 @depends(awk)
718 def awk_for_old_configure(value):
719     return value
722 add_old_configure_assignment("AWK", awk_for_old_configure)
725 # Perl detection
726 # ==============================================================
727 perl = check_prog("PERL", ("perl5", "perl"))
729 # Until the PERL variable is not necessary in old-configure
732 @depends(perl)
733 def perl_for_old_configure(value):
734     return value
737 add_old_configure_assignment("PERL", perl_for_old_configure)
740 @template
741 def perl_version_check(min_version):
742     @depends(perl)
743     @checking("for minimum required perl version >= %s" % min_version)
744     def get_perl_version(perl):
745         return Version(
746             check_cmd_output(
747                 perl,
748                 "-e",
749                 "print $]",
750                 onerror=lambda: die("Failed to get perl version."),
751             )
752         )
754     @depends(get_perl_version)
755     def check_perl_version(version):
756         if version < min_version:
757             die("Perl %s or higher is required.", min_version)
759     @depends(perl)
760     @checking("for full perl installation")
761     @imports("subprocess")
762     def has_full_perl_installation(perl):
763         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
764         return ret == 0
766     @depends(has_full_perl_installation)
767     def require_full_perl_installation(has_full_perl_installation):
768         if not has_full_perl_installation:
769             die(
770                 "Cannot find Config.pm or $Config{archlib}. "
771                 "A full perl installation is required."
772             )
775 perl_version_check("5.006")
778 # GNU make detection
779 # ==============================================================
780 option(env="MAKE", nargs=1, help="Path to GNU make")
783 @depends("MAKE", host)
784 def possible_makes(make, host):
785     candidates = []
786     if host.kernel == "WINNT":
787         candidates.append("mingw32-make")
788     if make:
789         candidates.append(make[0])
790     if host.kernel == "WINNT":
791         candidates.extend(("mozmake", "make", "gmake"))
792     else:
793         candidates.extend(("gmake", "make"))
794     return candidates
797 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
799 # watchman detection
800 # ==============================================================
802 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
805 @depends(host, "WATCHMAN")
806 @checking("for watchman", callback=lambda w: w.path if w else "not found")
807 def watchman(host, prog):
808     # On Windows, `watchman` is only supported on 64-bit hosts.
809     if host.os == "WINNT" and host.cpu != "x86_64":
810         return
812     if not prog:
813         prog = find_program("watchman")
815     if not prog:
816         return
818     # `watchman version` will talk to the Watchman daemon service.
819     # This can hang due to permissions problems. e.g.
820     # https://github.com/facebook/watchman/issues/376. So use
821     # `watchman --version` to prevent a class of failures.
822     out = check_cmd_output(prog, "--version", onerror=lambda: None)
823     if out is None:
824         return
826     return namespace(path=prog, version=Version(out.strip()))
829 @depends_if(watchman)
830 @checking("for watchman version")
831 def watchman_version(w):
832     return w.version
835 set_config("WATCHMAN", watchman.path)
838 @depends_all(hg_version, hg_config, watchman)
839 @checking("for watchman Mercurial integration")
840 @imports("os")
841 def watchman_hg(hg_version, hg_config, watchman):
842     if hg_version < Version("3.8"):
843         return "no (Mercurial 3.8+ required)"
845     ext_enabled = False
846     mode_disabled = False
848     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
849         if k in hg_config and hg_config[k] != "!":
850             ext_enabled = True
852     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
854     if not ext_enabled:
855         return "no (fsmonitor extension not enabled)"
856     if mode_disabled:
857         return "no (fsmonitor.mode=off disables fsmonitor)"
859     return True
862 # Miscellaneous programs
863 # ==============================================================
864 check_prog("XARGS", ("xargs",))
867 @depends(target)
868 def extra_programs(target):
869     if target.kernel == "Darwin":
870         return namespace(
871             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
872             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
873             HFS_TOOL=("hfsplus",),
874         )
875     if target.os == "GNU" and target.kernel == "Linux":
876         return namespace(RPMBUILD=("rpmbuild",))
879 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
880 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
881 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
882 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
885 nsis = check_prog(
886     "MAKENSISU",
887     ("makensis",),
888     bootstrap="nsis/bin",
889     allow_missing=True,
890     when=target_is_windows,
893 # Make sure the version of makensis is up to date.
896 @depends_if(nsis)
897 @checking("for NSIS version")
898 @imports("re")
899 def nsis_version(nsis):
900     nsis_min_version = "3.0b1"
902     def onerror():
903         return die("Failed to get nsis version.")
905     out = check_cmd_output(nsis, "-version", onerror=onerror)
907     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
909     if not m:
910         raise FatalCheckError("Unknown version of makensis")
911     ver = Version(m.group(0))
913     # Versions comparisons don't quite work well with beta versions, so ensure
914     # it works for the non-beta version.
915     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
916         raise FatalCheckError(
917             "To build the installer you must have NSIS"
918             " version %s or greater in your path" % nsis_min_version
919         )
921     return ver
924 # And that makensis is 32-bit (but only on Windows).
925 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
926 @checking("for 32-bit NSIS")
927 def nsis_binary_type(nsis):
928     bin_type = windows_binary_type(nsis)
929     if bin_type != "win32":
930         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
932     return "yes"
935 # And any flags we have to give to makensis
936 @depends(host)
937 def nsis_flags(host):
938     if host.kernel != "WINNT":
939         return "-nocd"
940     return ""
943 set_config("MAKENSISU_FLAGS", nsis_flags)
945 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
946 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
949 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
950 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
951     clang = None
952     for compiler in (host_c_compiler, c_compiler):
953         if compiler and compiler.type == "clang":
954             clang = compiler.compiler
955             break
956         elif compiler and compiler.type == "clang-cl":
957             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
958             break
960     if not clang and bindgen_config_paths:
961         clang = bindgen_config_paths.clang_path
962     llvm_objdump = "llvm-objdump"
963     if clang:
964         out = check_cmd_output(
965             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
966         )
967         if out:
968             llvm_objdump = out.rstrip()
969     return (llvm_objdump,)
972 llvm_objdump = check_prog(
973     "LLVM_OBJDUMP",
974     llvm_objdump,
975     what="llvm-objdump",
976     when="--enable-compile-environment",
977     paths=clang_search_path,
980 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
983 option("--enable-dtrace", help="Build with dtrace support")
985 dtrace = check_header(
986     "sys/sdt.h",
987     when="--enable-dtrace",
988     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
991 set_config("HAVE_DTRACE", True, when=dtrace)
992 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
993 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
996 option("--disable-icf", help="Disable Identical Code Folding")
998 add_old_configure_assignment(
999     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
1003 option(
1004     "--enable-strip",
1005     when=compile_environment,
1006     help="Enable stripping of libs & executables",
1009 # This should be handled as a `when` once bug 1617793 is fixed.
1012 @depends("--enable-strip", c_compiler, when=compile_environment)
1013 def enable_strip(strip, c_compiler):
1014     if strip and c_compiler.type != "clang-cl":
1015         return True
1018 set_config("ENABLE_STRIP", enable_strip)
1020 option(
1021     "--disable-install-strip",
1022     when=compile_environment,
1023     help="Enable stripping of libs & executables when packaging",
1026 # This should be handled as a `when` once bug 1617793 is fixed.
1029 @depends("--enable-install-strip", c_compiler, when=compile_environment)
1030 def enable_install_strip(strip, c_compiler):
1031     if strip and c_compiler.type != "clang-cl":
1032         return True
1035 set_config("PKG_STRIP", enable_install_strip)
1038 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1039 def strip(strip, install_strip):
1040     return strip or install_strip
1043 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1046 @depends("STRIP_FLAGS", profiling, target, when=strip)
1047 def strip_flags(flags, profiling, target):
1048     if flags:
1049         return flags[0].split()
1050     if profiling:
1051         # Only strip debug info and symbols when profiling is enabled, keeping
1052         # local symbols.
1053         if target.kernel == "Darwin":
1054             return ["-S"]
1055         elif target.os == "Android":
1056             # The tooling we use with Android supports detached symbols, and the
1057             # size increase caused by local symbols are too much for mobile. So,
1058             # don't restrict the amount of stripping with a flag.
1059             return
1060         else:
1061             return ["--strip-debug"]
1062     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1063     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1064     elif target.kernel == "Darwin":
1065         return ["-x", "-S"]
1068 set_config("STRIP_FLAGS", strip_flags)
1071 @depends(js_standalone, target)
1072 def system_zlib_default(js_standalone, target):
1073     return js_standalone and target.kernel not in ("WINNT", "Darwin")
1076 option(
1077     "--with-system-zlib",
1078     nargs="?",
1079     default=system_zlib_default,
1080     help="{Use|Do not use} system libz",
1084 @depends("--with-system-zlib")
1085 def deprecated_system_zlib_path(value):
1086     if len(value) == 1:
1087         die(
1088             "--with-system-zlib=PATH is not supported anymore. Please use "
1089             "--with-system-zlib and set any necessary pkg-config environment variable."
1090         )
1093 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1095 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1096 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1099 # Please do not add configure checks from here on.
1101 # Fallthrough to autoconf-based configure
1102 include("build/moz.configure/old.configure")
1104 # JS Subconfigure.
1105 include("js/sub.configure", when=compile_environment & toolkit)
1108 @depends(check_build_environment, build_project)
1109 @imports("__sandbox__")
1110 @imports("glob")
1111 @imports(_from="os.path", _import="exists")
1112 def config_status_deps(build_env, build_project):
1114     topsrcdir = build_env.topsrcdir
1115     topobjdir = build_env.topobjdir
1117     if not topobjdir.endswith("js/src"):
1118         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1119     else:
1120         # mozconfig changes may impact js configure.
1121         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1123     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1124     if exists(confvars):
1125         extra_deps.append(confvars)
1127     return (
1128         list(__sandbox__._all_paths)
1129         + extra_deps
1130         + [
1131             os.path.join(topsrcdir, "CLOBBER"),
1132             os.path.join(topsrcdir, "configure.in"),
1133             os.path.join(topsrcdir, "js", "src", "configure.in"),
1134             os.path.join(topsrcdir, "nsprpub", "configure"),
1135             os.path.join(topsrcdir, "config", "milestone.txt"),
1136             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1137             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1138             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1139             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1140             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1141             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
1142             os.path.join(topsrcdir, "aclocal.m4"),
1143             os.path.join(topsrcdir, "old-configure.in"),
1144             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1145             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1146         ]
1147         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1148     )
1151 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1152 # Please do not add anything after setting config_dep_paths.