Bug 1713152 [wpt PR 29140] - Invalidate local attachment content-box background with...
[gecko.git] / moz.configure
blob0a7f6bd0a47aa1ece06dfe8310b31060a8404df0
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(host, milestone.is_nightly, "MOZ_AUTOMATION")
197 def bootstrap_default(host, is_nightly, automation):
198     if automation:
199         return False
200     if host.cpu == "aarch64" and host.os == "OSX" and is_nightly:
201         return True
204 option(
205     "--enable-bootstrap",
206     default=bootstrap_default,
207     help="{Automatically bootstrap or update some toolchains|Disable bootstrap or update of toolchains}",
211 @depends(developer_options, "--enable-bootstrap", moz_fetches_dir)
212 def bootstrap_search_path_order(developer_options, bootstrap, moz_fetches_dir):
213     if moz_fetches_dir:
214         log.debug("Prioritizing MOZ_FETCHES_DIR in toolchain path.")
215         return "prepend"
217     if bootstrap:
218         log.debug(
219             "Prioritizing mozbuild state dir in toolchain paths because "
220             "bootstrap mode is enabled."
221         )
222         return "prepend"
224     if developer_options:
225         log.debug(
226             "Prioritizing mozbuild state dir in toolchain paths because "
227             "you are not building in release mode."
228         )
229         return "prepend"
231     log.debug(
232         "Prioritizing system over mozbuild state dir in "
233         "toolchain paths because you are building in "
234         "release mode."
235     )
236     return "append"
239 toolchains_base_dir = moz_fetches_dir | mozbuild_state_path
242 @dependable
243 @imports("os")
244 @imports(_from="os", _import="environ")
245 def original_path():
246     return environ["PATH"].split(os.pathsep)
249 @template
250 def bootstrap_toolchain_tasks(host_or_target):
251     @depends(host_or_target, when="--enable-bootstrap")
252     @imports("os")
253     @imports(_from="mozbuild.toolchains", _import="toolchain_task_definitions")
254     @imports(_from="__builtin__", _import="Exception")
255     def bootstrap_toolchain_tasks(host_or_target):
256         prefix = {
257             ("x86", "GNU", "Linux"): "linux32",
258             ("x86_64", "GNU", "Linux"): "linux64",
259             ("aarch64", "GNU", "Linux"): "linux64-aarch64",
260             ("x86_64", "OSX", "Darwin"): "macosx64",
261             ("aarch64", "OSX", "Darwin"): "macosx64-aarch64",
262             ("x86_64", "WINNT", "WINNT"): "win64",
263         }.get((host_or_target.cpu, host_or_target.os, host_or_target.kernel))
264         if prefix:
265             try:
266                 return namespace(prefix=prefix, tasks=toolchain_task_definitions())
267             except Exception:
268                 return None
270     return bootstrap_toolchain_tasks
273 host_bootstrap_toolchain_tasks = bootstrap_toolchain_tasks(host)
274 target_bootstrap_toolchain_tasks = bootstrap_toolchain_tasks(target)
277 @template
278 def bootstrap_path(path, **kwargs):
279     when = kwargs.pop("when", None)
280     context = kwargs.pop("context", host)
281     if kwargs:
282         configure_error(
283             "bootstrap_path only takes `when` or `context` as keyword arguments"
284         )
286     path_parts = path.split("/")
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         when=when,
299     )
300     @imports("os")
301     @imports("subprocess")
302     @imports(_from="mozbuild.util", _import="ensureParentDir")
303     @imports(_from="__builtin__", _import="open")
304     @imports(_from="__builtin__", _import="Exception")
305     def bootstrap_path(bootstrap, toolchains_base_dir, tasks, shell, build_env):
306         def try_bootstrap(exists):
307             if not tasks:
308                 return False
309             label = "toolchain-{}-{}".format(
310                 tasks.prefix, path_parts[0].replace("_", "-")
311             )
312             task = tasks.tasks.get(label)
313             if not task:
314                 return False
315             task_index = task.optimization.get("index-search")
316             if not task_index:
317                 return False
318             task_index = task_index[0].split(".")[-1]
319             artifact = task.attributes["toolchain-artifact"]
320             # `mach artifact toolchain` doesn't support authentication for
321             # private artifacts.
322             if not artifact.startswith("public/"):
323                 return False
324             index_file = os.path.join(toolchains_base_dir, "indices", path_parts[0])
325             try:
326                 with open(index_file) as fh:
327                     index = fh.read().strip()
328             except Exception:
329                 index = None
330             if index == task_index and exists:
331                 return True
332             log.info(
333                 "%s bootstrapped toolchain in %s",
334                 "Updating" if exists else "Installing",
335                 os.path.join(toolchains_base_dir, path_parts[0]),
336             )
337             subprocess.run(
338                 [
339                     shell,
340                     os.path.join(build_env.topsrcdir, "mach"),
341                     "--log-no-times",
342                     "artifact",
343                     "toolchain",
344                     "--from-build",
345                     label,
346                 ],
347                 cwd=toolchains_base_dir,
348                 check=True,
349             )
350             ensureParentDir(index_file)
351             with open(index_file, "w") as fh:
352                 fh.write(task_index)
353             return True
355         path = os.path.join(toolchains_base_dir, *path_parts)
356         if bootstrap:
357             try:
358                 if not try_bootstrap(os.path.exists(path)):
359                     # If there aren't toolchain artifacts to use for this build,
360                     # don't return a path.
361                     return None
362             except Exception as e:
363                 log.error("%s", e)
364                 die("If you can't fix the above, retry with --disable-bootstrap.")
365         # We re-test whether the path exists because it may have been created by
366         # try_bootstrap. Automation will not have gone through the bootstrap
367         # process, but we want to return the path if it exists.
368         if os.path.exists(path):
369             return path
371     return bootstrap_path
374 @template
375 def bootstrap_search_path(path, paths=original_path, **kwargs):
376     @depends(
377         bootstrap_path(path, **kwargs),
378         bootstrap_search_path_order,
379         paths,
380         original_path,
381     )
382     def bootstrap_search_path(path, order, paths, original_path):
383         if paths is None:
384             paths = original_path
385         if not path:
386             return paths
387         if order == "prepend":
388             return [path] + paths
389         return paths + [path]
391     return bootstrap_search_path
394 # The execution model of the configure sandbox doesn't allow for
395 # check_prog to use bootstrap_search_path directly because check_prog
396 # comes first, so we use a trick to allow it. No use of check_prog
397 # happening before here won't allow bootstrap.
398 @template
399 def check_prog(*args, **kwargs):
400     kwargs["bootstrap_search_path"] = bootstrap_search_path
401     return check_prog(*args, **kwargs)
404 @depends(target, host)
405 def want_wine(target, host):
406     return target.kernel == "WINNT" and host.kernel != "WINNT"
409 wine = check_prog(
410     "WINE",
411     ["wine64", "wine"],
412     allow_missing=True,
413     when=want_wine,
414     bootstrap="wine/bin",
416 check_prog("WGET", ("wget",), allow_missing=True)
419 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
421 include("build/moz.configure/pkg.configure")
422 # Make this assignment here rather than in pkg.configure to avoid
423 # requiring this file in unit tests.
424 add_old_configure_assignment("PKG_CONFIG", pkg_config)
426 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
427 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
428 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
429 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
430 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
431 # rust.configure is included by js/moz.configure.
433 option("--enable-valgrind", help="Enable Valgrind integration hooks")
435 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
438 @depends("--enable-valgrind", valgrind_h)
439 def check_valgrind(valgrind, valgrind_h):
440     if valgrind:
441         if not valgrind_h:
442             die("--enable-valgrind specified but Valgrind is not installed")
443         return True
446 set_define("MOZ_VALGRIND", check_valgrind)
447 set_config("MOZ_VALGRIND", check_valgrind)
450 @depends(target, host)
451 def is_openbsd(target, host):
452     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
455 option(
456     env="SO_VERSION",
457     nargs=1,
458     default="1.0",
459     when=is_openbsd,
460     help="Shared library version for OpenBSD systems",
464 @depends("SO_VERSION", when=is_openbsd)
465 def so_version(value):
466     return value
469 @template
470 def library_name_info_template(host_or_target):
471     assert host_or_target in {host, target}
472     compiler = {
473         host: host_c_compiler,
474         target: c_compiler,
475     }[host_or_target]
477     @depends(host_or_target, compiler, so_version)
478     def library_name_info_impl(host_or_target, compiler, so_version):
479         if host_or_target.kernel == "WINNT":
480             # There aren't artifacts for mingw builds, so it's OK that the
481             # results are inaccurate in that case.
482             if compiler and compiler.type != "clang-cl":
483                 return namespace(
484                     dll=namespace(prefix="", suffix=".dll"),
485                     lib=namespace(prefix="lib", suffix="a"),
486                     import_lib=namespace(prefix="lib", suffix="a"),
487                     obj=namespace(prefix="", suffix="o"),
488                 )
490             return namespace(
491                 dll=namespace(prefix="", suffix=".dll"),
492                 lib=namespace(prefix="", suffix="lib"),
493                 import_lib=namespace(prefix="", suffix="lib"),
494                 obj=namespace(prefix="", suffix="obj"),
495             )
497         elif host_or_target.kernel == "Darwin":
498             return namespace(
499                 dll=namespace(prefix="lib", suffix=".dylib"),
500                 lib=namespace(prefix="lib", suffix="a"),
501                 import_lib=namespace(prefix=None, suffix=""),
502                 obj=namespace(prefix="", suffix="o"),
503             )
504         elif so_version:
505             so = ".so.%s" % so_version
506         else:
507             so = ".so"
509         return namespace(
510             dll=namespace(prefix="lib", suffix=so),
511             lib=namespace(prefix="lib", suffix="a"),
512             import_lib=namespace(prefix=None, suffix=""),
513             obj=namespace(prefix="", suffix="o"),
514         )
516     return library_name_info_impl
519 host_library_name_info = library_name_info_template(host)
520 library_name_info = library_name_info_template(target)
522 set_config("DLL_PREFIX", library_name_info.dll.prefix)
523 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
524 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
525 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
526 set_config("LIB_PREFIX", library_name_info.lib.prefix)
527 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
528 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
529 # Lots of compilation tests depend on this variable being present.
530 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
531 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
532 set_define(
533     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
535 set_define(
536     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
538 set_config("WASM_OBJ_SUFFIX", "wasm")
540 # Make `profiling` available to this file even when js/moz.configure
541 # doesn't end up included.
542 profiling = dependable(False)
543 # Same for js_standalone
544 js_standalone = dependable(False)
545 # Same for fold_libs
546 fold_libs = dependable(False)
548 include(include_project_configure)
551 @depends("--help")
552 @imports(_from="mozbuild.backend", _import="backends")
553 def build_backends_choices(_):
554     return tuple(backends)
557 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
558 def build_backend(backends):
559     if backends:
560         return tuple("+%s" % b for b in backends)
563 imply_option("--build-backends", build_backend)
566 @depends(
567     "--enable-artifact-builds",
568     "--disable-compile-environment",
569     "--enable-build-backend",
570     "--enable-project",
571     "--enable-application",
572     "--help",
574 @imports("sys")
575 def build_backend_defaults(
576     artifact_builds, compile_environment, requested_backends, project, application, _
578     if application:
579         project = application[0]
580     elif project:
581         project = project[0]
583     if "Tup" in requested_backends:
584         # As a special case, if Tup was requested, do not combine it with any
585         # Make based backend by default.
586         all_backends = []
587     elif artifact_builds:
588         all_backends = ["FasterMake+RecursiveMake"]
589     else:
590         all_backends = ["RecursiveMake", "FasterMake"]
591     # Normally, we'd use target.os == 'WINNT', but a dependency on target
592     # would require target to depend on --help, as well as host and shell,
593     # and this is not a can of worms we can open at the moment.
594     if (
595         sys.platform == "win32"
596         and compile_environment
597         and project not in ("mobile/android", "memory", "tools/update-programs")
598     ):
599         all_backends.append("VisualStudio")
600     return tuple(all_backends) or None
603 option(
604     "--build-backends",
605     nargs="+",
606     default=build_backend_defaults,
607     choices=build_backends_choices,
608     help="Build backends to generate",
612 @depends("--build-backends")
613 def build_backends(backends):
614     return backends
617 set_config("BUILD_BACKENDS", build_backends)
620 @depends(check_build_environment, build_backends)
621 @imports("glob")
622 def check_objdir_backend_reuse(build_env, backends):
623     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
624     # intentionally vague for use with the substring match below.
625     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
626     for backend_file in glob.iglob(
627         os.path.join(build_env.topobjdir, "backend.*Backend")
628     ):
629         for prev, curr in incompatible_backends:
630             if prev in backend_file and any(curr in b for b in backends):
631                 die(
632                     "The active objdir, %s, was previously "
633                     "used to build with a %s based backend. "
634                     "Change objdirs (by setting MOZ_OBJDIR in "
635                     "your mozconfig) or clobber to continue.\n",
636                     build_env.topobjdir,
637                     prev,
638                 )
641 option(
642     "--disable-gtest-in-build",
643     help="Force disable building the gtest libxul during the build.",
644     when="--enable-compile-environment",
647 # Determine whether to build the gtest xul. This happens in automation
648 # on Android and Desktop platforms with the exception of:
649 #  - Windows PGO, where linking xul-gtest.dll takes too long;
650 #  - Android other than x86_64, where gtest is not required.
653 @depends(
654     "MOZ_PGO",
655     build_project,
656     target,
657     "MOZ_AUTOMATION",
658     "--disable-gtest-in-build",
659     enable_tests,
660     when="--enable-compile-environment",
662 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
663     if not enable_tests or not enabled:
664         return None
665     if (
666         automation
667         and build_project in ("browser", "comm/mail", "mobile/android")
668         and not (
669             (pgo and target.os == "WINNT")
670             or (target.os == "Android" and target.cpu != "x86_64")
671         )
672     ):
673         return True
676 set_config("LINK_GTEST_DURING_COMPILE", build_gtest)
678 # Localization
679 # ==============================================================
680 option(
681     "--enable-ui-locale",
682     default="en-US",
683     help="Select the user interface locale (default: en-US)",
686 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
688 # clang-plugin location
689 # ==============================================================
692 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
693 def clang_plugin_path(library_name_info, build_env):
694     topobjdir = build_env.topobjdir
695     if topobjdir.endswith("/js/src"):
696         topobjdir = topobjdir[:-7]
697     return os.path.abspath(
698         os.path.join(
699             topobjdir,
700             "build",
701             "clang-plugin",
702             "%sclang-plugin%s"
703             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
704         )
705     )
708 set_config("CLANG_PLUGIN", clang_plugin_path)
709 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
712 # Awk detection
713 # ==============================================================
714 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
716 # Until the AWK variable is not necessary in old-configure
719 @depends(awk)
720 def awk_for_old_configure(value):
721     return value
724 add_old_configure_assignment("AWK", awk_for_old_configure)
727 # Perl detection
728 # ==============================================================
729 perl = check_prog("PERL", ("perl5", "perl"))
731 # Until the PERL variable is not necessary in old-configure
734 @depends(perl)
735 def perl_for_old_configure(value):
736     return value
739 add_old_configure_assignment("PERL", perl_for_old_configure)
742 @template
743 def perl_version_check(min_version):
744     @depends(perl)
745     @checking("for minimum required perl version >= %s" % min_version)
746     def get_perl_version(perl):
747         return Version(
748             check_cmd_output(
749                 perl,
750                 "-e",
751                 "print $]",
752                 onerror=lambda: die("Failed to get perl version."),
753             )
754         )
756     @depends(get_perl_version)
757     def check_perl_version(version):
758         if version < min_version:
759             die("Perl %s or higher is required.", min_version)
761     @depends(perl)
762     @checking("for full perl installation")
763     @imports("subprocess")
764     def has_full_perl_installation(perl):
765         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
766         return ret == 0
768     @depends(has_full_perl_installation)
769     def require_full_perl_installation(has_full_perl_installation):
770         if not has_full_perl_installation:
771             die(
772                 "Cannot find Config.pm or $Config{archlib}. "
773                 "A full perl installation is required."
774             )
777 perl_version_check("5.006")
780 # GNU make detection
781 # ==============================================================
782 option(env="MAKE", nargs=1, help="Path to GNU make")
785 @depends("MAKE", host)
786 def possible_makes(make, host):
787     candidates = []
788     if host.kernel == "WINNT":
789         candidates.append("mingw32-make")
790     if make:
791         candidates.append(make[0])
792     if host.kernel == "WINNT":
793         candidates.extend(("mozmake", "make", "gmake"))
794     else:
795         candidates.extend(("gmake", "make"))
796     return candidates
799 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
801 # watchman detection
802 # ==============================================================
804 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
807 @depends(host, "WATCHMAN")
808 @checking("for watchman", callback=lambda w: w.path if w else "not found")
809 def watchman(host, prog):
810     # On Windows, `watchman` is only supported on 64-bit hosts.
811     if host.os == "WINNT" and host.cpu != "x86_64":
812         return
814     if not prog:
815         prog = find_program("watchman")
817     if not prog:
818         return
820     # `watchman version` will talk to the Watchman daemon service.
821     # This can hang due to permissions problems. e.g.
822     # https://github.com/facebook/watchman/issues/376. So use
823     # `watchman --version` to prevent a class of failures.
824     out = check_cmd_output(prog, "--version", onerror=lambda: None)
825     if out is None:
826         return
828     return namespace(path=prog, version=Version(out.strip()))
831 @depends_if(watchman)
832 @checking("for watchman version")
833 def watchman_version(w):
834     return w.version
837 set_config("WATCHMAN", watchman.path)
840 @depends_all(hg_version, hg_config, watchman)
841 @checking("for watchman Mercurial integration")
842 @imports("os")
843 def watchman_hg(hg_version, hg_config, watchman):
844     if hg_version < Version("3.8"):
845         return "no (Mercurial 3.8+ required)"
847     ext_enabled = False
848     mode_disabled = False
850     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
851         if k in hg_config and hg_config[k] != "!":
852             ext_enabled = True
854     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
856     if not ext_enabled:
857         return "no (fsmonitor extension not enabled)"
858     if mode_disabled:
859         return "no (fsmonitor.mode=off disables fsmonitor)"
861     return True
864 # Miscellaneous programs
865 # ==============================================================
866 check_prog("XARGS", ("xargs",))
869 @depends(target)
870 def extra_programs(target):
871     if target.kernel == "Darwin":
872         return namespace(
873             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
874             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
875             HFS_TOOL=("hfsplus",),
876         )
877     if target.os == "GNU" and target.kernel == "Linux":
878         return namespace(RPMBUILD=("rpmbuild",))
881 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
882 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
883 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
884 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
887 @depends(target)
888 @imports("os")
889 def makensis_progs(target):
890     if target.kernel != "WINNT":
891         return
893     candidates = [
894         "makensis-3.01",
895         "makensis-3.0b3",
896         "makensis-3.0b1",
897         "makensis",
898     ]
900     # Look for nsis installed by msys environment. But only the 32-bit version.
901     # We use an absolute path and insert as the first entry so it is preferred
902     # over a 64-bit exe that may be in PATH.
903     if "MSYSTEM_PREFIX" in os.environ:
904         prefix = os.path.dirname(os.environ["MSYSTEM_PREFIX"])
905         candidates.insert(0, os.path.join(prefix, "mingw32", "bin", "makensis.exe"))
907     return tuple(candidates)
910 nsis = check_prog("MAKENSISU", makensis_progs, allow_missing=True)
912 # Make sure the version of makensis is up to date.
915 @depends(nsis, wine)
916 @checking("for NSIS version")
917 @imports("re")
918 def nsis_version(nsis, wine):
919     if not nsis:
920         return None
921     nsis_min_version = "3.0b1"
923     def onerror():
924         return die("Failed to get nsis version.")
926     if wine and nsis.lower().endswith(".exe"):
927         out = check_cmd_output(wine, nsis, "-version", onerror=onerror)
928     else:
929         out = check_cmd_output(nsis, "-version", onerror=onerror)
931     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
933     if not m:
934         raise FatalCheckError("Unknown version of makensis")
935     ver = Version(m.group(0))
937     # Versions comparisons don't quite work well with beta versions, so ensure
938     # it works for the non-beta version.
939     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
940         raise FatalCheckError(
941             "To build the installer you must have NSIS"
942             " version %s or greater in your path" % nsis_min_version
943         )
945     return ver
948 # And that makensis is 32-bit (but only on Windows).
949 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
950 @checking("for 32-bit NSIS")
951 def nsis_binary_type(nsis):
952     bin_type = windows_binary_type(nsis)
953     if bin_type != "win32":
954         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
956     return "yes"
959 # And any flags we have to give to makensis
960 @depends(host)
961 def nsis_flags(host):
962     if host.kernel != "WINNT":
963         return "-nocd"
964     return ""
967 set_config("MAKENSISU_FLAGS", nsis_flags)
969 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
970 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
973 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
974 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
975     clang = None
976     for compiler in (host_c_compiler, c_compiler):
977         if compiler and compiler.type == "clang":
978             clang = compiler.compiler
979             break
980         elif compiler and compiler.type == "clang-cl":
981             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
982             break
984     if not clang and bindgen_config_paths:
985         clang = bindgen_config_paths.clang_path
986     llvm_objdump = "llvm-objdump"
987     if clang:
988         out = check_cmd_output(
989             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
990         )
991         if out:
992             llvm_objdump = out.rstrip()
993     return (llvm_objdump,)
996 llvm_objdump = check_prog(
997     "LLVM_OBJDUMP",
998     llvm_objdump,
999     what="llvm-objdump",
1000     when="--enable-compile-environment",
1001     paths=clang_search_path,
1004 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
1007 option("--enable-dtrace", help="Build with dtrace support")
1009 dtrace = check_header(
1010     "sys/sdt.h",
1011     when="--enable-dtrace",
1012     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
1015 set_config("HAVE_DTRACE", True, when=dtrace)
1016 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
1017 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
1020 option("--disable-icf", help="Disable Identical Code Folding")
1022 add_old_configure_assignment(
1023     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
1027 option(
1028     "--enable-strip",
1029     when=compile_environment,
1030     help="Enable stripping of libs & executables",
1033 # This should be handled as a `when` once bug 1617793 is fixed.
1036 @depends("--enable-strip", c_compiler, when=compile_environment)
1037 def enable_strip(strip, c_compiler):
1038     if strip and c_compiler.type != "clang-cl":
1039         return True
1042 set_config("ENABLE_STRIP", enable_strip)
1044 option(
1045     "--disable-install-strip",
1046     when=compile_environment,
1047     help="Enable stripping of libs & executables when packaging",
1050 # This should be handled as a `when` once bug 1617793 is fixed.
1053 @depends("--enable-install-strip", c_compiler, when=compile_environment)
1054 def enable_install_strip(strip, c_compiler):
1055     if strip and c_compiler.type != "clang-cl":
1056         return True
1059 set_config("PKG_STRIP", enable_install_strip)
1062 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1063 def strip(strip, install_strip):
1064     return strip or install_strip
1067 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1070 @depends("STRIP_FLAGS", profiling, target, when=strip)
1071 def strip_flags(flags, profiling, target):
1072     if flags:
1073         return flags[0].split()
1074     if profiling:
1075         # Only strip debug info and symbols when profiling is enabled, keeping
1076         # local symbols.
1077         if target.kernel == "Darwin":
1078             return ["-S"]
1079         elif target.os == "Android":
1080             # The tooling we use with Android supports detached symbols, and the
1081             # size increase caused by local symbols are too much for mobile. So,
1082             # don't restrict the amount of stripping with a flag.
1083             return
1084         else:
1085             return ["--strip-debug"]
1086     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1087     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1088     elif target.kernel == "Darwin":
1089         return ["-x", "-S"]
1092 set_config("STRIP_FLAGS", strip_flags)
1095 @depends(js_standalone, target)
1096 def system_zlib_default(js_standalone, target):
1097     return js_standalone and target.kernel != "WINNT"
1100 option(
1101     "--with-system-zlib",
1102     nargs="?",
1103     default=system_zlib_default,
1104     help="{Use|Do not use} system libz",
1108 @depends("--with-system-zlib")
1109 def deprecated_system_zlib_path(value):
1110     if len(value) == 1:
1111         die(
1112             "--with-system-zlib=PATH is not supported anymore. Please use "
1113             "--with-system-zlib and set any necessary pkg-config environment variable."
1114         )
1117 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1119 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1120 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1123 # Please do not add configure checks from here on.
1125 # Fallthrough to autoconf-based configure
1126 include("build/moz.configure/old.configure")
1128 # JS Subconfigure.
1129 include("js/sub.configure", when=compile_environment & toolkit)
1132 @depends(check_build_environment, build_project)
1133 @imports("__sandbox__")
1134 @imports("glob")
1135 @imports(_from="os.path", _import="exists")
1136 def config_status_deps(build_env, build_project):
1138     topsrcdir = build_env.topsrcdir
1139     topobjdir = build_env.topobjdir
1141     if not topobjdir.endswith("js/src"):
1142         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1143     else:
1144         # mozconfig changes may impact js configure.
1145         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1147     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1148     if exists(confvars):
1149         extra_deps.append(confvars)
1151     return (
1152         list(__sandbox__._all_paths)
1153         + extra_deps
1154         + [
1155             os.path.join(topsrcdir, "CLOBBER"),
1156             os.path.join(topsrcdir, "configure.in"),
1157             os.path.join(topsrcdir, "js", "src", "configure.in"),
1158             os.path.join(topsrcdir, "nsprpub", "configure"),
1159             os.path.join(topsrcdir, "config", "milestone.txt"),
1160             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1161             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1162             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1163             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1164             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1165             os.path.join(topsrcdir, "python", "mozbuild", "mozbuild", "virtualenv.py"),
1166             os.path.join(topsrcdir, "testing", "mozbase", "packages.txt"),
1167             os.path.join(topsrcdir, "aclocal.m4"),
1168             os.path.join(topsrcdir, "old-configure.in"),
1169             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1170             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1171         ]
1172         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1173     )
1176 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1177 # Please do not add anything after setting config_dep_paths.