Bug 1669840 Part 3: Update test expectations. r=jrmuizel
[gecko.git] / moz.configure
blobdb58978598d45abb046d510d6b4576af0b85d5d8
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(
157     "--enable-rust-debug",
158     default=depends(when="--enable-debug")(lambda: True),
159     help="{Build|Do not build} Rust code with debug assertions turned " "on.",
163 @depends(when="--enable-rust-debug")
164 def debug_rust():
165     return True
168 set_config("MOZ_DEBUG_RUST", debug_rust)
169 set_define("MOZ_DEBUG_RUST", debug_rust)
171 option(env="MOZ_PGO", help="Build with profile guided optimizations")
173 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
176 imply_option("--enable-release", mozilla_official)
177 imply_option("--enable-release", depends_if("MOZ_AUTOMATION")(lambda x: True))
179 option(
180     "--enable-release",
181     default=milestone.is_release_or_beta,
182     help="{Build|Do not build} with more conservative, release "
183     "engineering-oriented options.{ This may slow down builds.|}",
187 @depends("--enable-release")
188 def developer_options(value):
189     if not value:
190         return True
193 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
194 set_config("DEVELOPER_OPTIONS", developer_options)
197 option(
198     env="MOZ_FETCHES_DIR",
199     nargs=1,
200     when="MOZ_AUTOMATION",
201     help="Directory containing fetched artifacts",
205 @depends("MOZ_FETCHES_DIR", when="MOZ_AUTOMATION")
206 def moz_fetches_dir(value):
207     if value:
208         return value[0]
211 @depends(developer_options, moz_fetches_dir)
212 def bootstrap_search_path_order(developer_options, moz_fetches_dir):
213     if moz_fetches_dir:
214         log.debug("Prioritizing MOZ_FETCHES_DIR in toolchain path.")
215         return "prepend"
217     if developer_options:
218         log.debug(
219             "Prioritizing mozbuild state dir in toolchain paths because "
220             "you are not building in release mode."
221         )
222         return "prepend"
224     log.debug(
225         "Prioritizing system over mozbuild state dir in "
226         "toolchain paths because you are building in "
227         "release mode."
228     )
229     return "append"
232 toolchains_base_dir = moz_fetches_dir | mozbuild_state_path
235 @dependable
236 @imports("os")
237 @imports(_from="os", _import="environ")
238 def original_path():
239     return environ["PATH"].split(os.pathsep)
242 option(
243     "--enable-bootstrap",
244     nargs="?",
245     choices=("install", "update"),
246     when=developer_options,
247     help="Automatically update/bootstrap some toolchains when they are present but out of date",
251 @depends("--enable-bootstrap", when=developer_options)
252 def bootstrap(value):
253     if value:
254         # value here is either an empty tuple, or a tuple containing either
255         # 'install' or 'update'. All values but 'install' mean 'update'.
256         if len(value) and value[0] == "install":
257             return "install"
258         return True
261 @depends(host, when=bootstrap)
262 @imports("os")
263 @imports(_from="mozbuild.toolchains", _import="toolchain_task_definitions")
264 @imports(_from="__builtin__", _import="Exception")
265 def bootstrap_toolchain_tasks(host):
266     prefix = {
267         ("x86_64", "GNU", "Linux"): "linux64",
268         ("x86_64", "OSX", "Darwin"): "macosx64",
269         ("x86_64", "WINNT", "WINNT"): "win64",
270     }.get((host.cpu, host.os, host.kernel))
271     if prefix:
272         try:
273             return namespace(prefix=prefix, tasks=toolchain_task_definitions())
274         except Exception:
275             return None
278 @template
279 def bootstrap_search_path(*path_parts, **kwargs):
280     when = kwargs.pop("when", None)
281     if kwargs:
282         configure_error("bootstrap_search_path only takes `when` as keyword argument")
284     @depends(
285         bootstrap,
286         bootstrap_search_path_order,
287         original_path,
288         toolchains_base_dir,
289         bootstrap_toolchain_tasks,
290         shell,
291         check_build_environment,
292         when=when,
293     )
294     @imports("os")
295     @imports("subprocess")
296     @imports(_from="mozbuild.util", _import="ensureParentDir")
297     @imports(_from="__builtin__", _import="open")
298     @imports(_from="__builtin__", _import="Exception")
299     def bootstrap_search_path(
300         bootstrap, order, original_path, toolchains_base_dir, tasks, shell, build_env
301     ):
302         def try_bootstrap(exists):
303             label = "toolchain-{}-{}".format(
304                 tasks.prefix, path_parts[0].replace("_", "-")
305             )
306             task = tasks.tasks.get(label)
307             if not task:
308                 return
309             task_index = task.optimization.get("index-search")
310             if not task_index:
311                 return
312             task_index = task_index[0].split(".")[-1]
313             artifact = task.attributes["toolchain-artifact"]
314             # `mach artifact toolchain` doesn't support authentication for
315             # private artifacts.
316             if not artifact.startswith("public/"):
317                 return
318             index_file = os.path.join(toolchains_base_dir, "indices", path_parts[0])
319             try:
320                 with open(index_file) as fh:
321                     index = fh.read().strip()
322             except Exception:
323                 index = None
324             if index == task_index and exists:
325                 return
326             log.info(
327                 "%s bootstrapped toolchain in %s",
328                 "Updating" if exists else "Installing",
329                 os.path.join(toolchains_base_dir, path_parts[0]),
330             )
331             subprocess.run(
332                 [
333                     shell,
334                     os.path.join(build_env.topsrcdir, "mach"),
335                     "--log-no-times",
336                     "artifact",
337                     "toolchain",
338                     "--from-build",
339                     label,
340                 ],
341                 cwd=toolchains_base_dir,
342                 check=True,
343             )
344             ensureParentDir(index_file)
345             with open(index_file, "w") as fh:
346                 fh.write(task_index)
348         path = os.path.join(toolchains_base_dir, *path_parts)
349         exists = os.path.exists(path)
350         if bootstrap and tasks and (exists or bootstrap == "install"):
351             try:
352                 try_bootstrap(exists)
353             except Exception as e:
354                 log.error("%s", e)
355                 die("If you can't fix the above, retry with --disable-bootstrap.")
356         if order == "prepend":
357             return [path] + original_path
358         return original_path + [path]
360     return bootstrap_search_path
363 @depends(target, host)
364 def want_wine(target, host):
365     return target.kernel == "WINNT" and host.kernel != "WINNT"
368 wine = check_prog(
369     "WINE",
370     ["wine64", "wine"],
371     allow_missing=True,
372     when=want_wine,
373     paths=bootstrap_search_path("wine", "bin", when=want_wine),
375 check_prog("WGET", ("wget",), allow_missing=True)
378 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
380 include("build/moz.configure/pkg.configure")
381 # Make this assignment here rather than in pkg.configure to avoid
382 # requiring this file in unit tests.
383 add_old_configure_assignment("PKG_CONFIG", pkg_config)
385 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
386 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
387 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
388 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
389 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
390 # rust.configure is included by js/moz.configure.
392 option("--enable-valgrind", help="Enable Valgrind integration hooks")
394 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
397 @depends("--enable-valgrind", valgrind_h)
398 def check_valgrind(valgrind, valgrind_h):
399     if valgrind:
400         if not valgrind_h:
401             die("--enable-valgrind specified but Valgrind is not installed")
402         return True
405 set_define("MOZ_VALGRIND", check_valgrind)
406 set_config("MOZ_VALGRIND", check_valgrind)
409 @depends(target, host)
410 def is_openbsd(target, host):
411     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
414 option(
415     env="SO_VERSION",
416     nargs=1,
417     default="1.0",
418     when=is_openbsd,
419     help="Shared library version for OpenBSD systems",
423 @depends("SO_VERSION", when=is_openbsd)
424 def so_version(value):
425     return value
428 @template
429 def library_name_info_template(host_or_target):
430     assert host_or_target in {host, target}
431     compiler = {
432         host: host_c_compiler,
433         target: c_compiler,
434     }[host_or_target]
436     @depends(host_or_target, compiler, so_version)
437     def library_name_info_impl(host_or_target, compiler, so_version):
438         if host_or_target.kernel == "WINNT":
439             # There aren't artifacts for mingw builds, so it's OK that the
440             # results are inaccurate in that case.
441             if compiler and compiler.type != "clang-cl":
442                 return namespace(
443                     dll=namespace(prefix="", suffix=".dll"),
444                     lib=namespace(prefix="lib", suffix="a"),
445                     import_lib=namespace(prefix="lib", suffix="a"),
446                     obj=namespace(prefix="", suffix="o"),
447                 )
449             return namespace(
450                 dll=namespace(prefix="", suffix=".dll"),
451                 lib=namespace(prefix="", suffix="lib"),
452                 import_lib=namespace(prefix="", suffix="lib"),
453                 obj=namespace(prefix="", suffix="obj"),
454             )
456         elif host_or_target.kernel == "Darwin":
457             return namespace(
458                 dll=namespace(prefix="lib", suffix=".dylib"),
459                 lib=namespace(prefix="lib", suffix="a"),
460                 import_lib=namespace(prefix=None, suffix=""),
461                 obj=namespace(prefix="", suffix="o"),
462             )
463         elif so_version:
464             so = ".so.%s" % so_version
465         else:
466             so = ".so"
468         return namespace(
469             dll=namespace(prefix="lib", suffix=so),
470             lib=namespace(prefix="lib", suffix="a"),
471             import_lib=namespace(prefix=None, suffix=""),
472             obj=namespace(prefix="", suffix="o"),
473         )
475     return library_name_info_impl
478 host_library_name_info = library_name_info_template(host)
479 library_name_info = library_name_info_template(target)
481 set_config("DLL_PREFIX", library_name_info.dll.prefix)
482 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
483 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
484 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
485 set_config("LIB_PREFIX", library_name_info.lib.prefix)
486 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
487 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
488 # Lots of compilation tests depend on this variable being present.
489 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
490 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
491 set_define(
492     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
494 set_define(
495     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
497 set_config("WASM_OBJ_SUFFIX", "wasm")
499 # Make `profiling` available to this file even when js/moz.configure
500 # doesn't end up included.
501 profiling = dependable(False)
502 # Same for js_standalone
503 js_standalone = dependable(False)
504 # Same for fold_libs
505 fold_libs = dependable(False)
507 include(include_project_configure)
510 @depends("--help")
511 @imports(_from="mozbuild.backend", _import="backends")
512 def build_backends_choices(_):
513     return tuple(backends)
516 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
517 def build_backend(backends):
518     if backends:
519         return tuple("+%s" % b for b in backends)
522 imply_option("--build-backends", build_backend)
525 @depends(
526     "--enable-artifact-builds",
527     "--disable-compile-environment",
528     "--enable-build-backend",
529     "--enable-project",
530     "--enable-application",
531     "--help",
533 @imports("sys")
534 def build_backend_defaults(
535     artifact_builds, compile_environment, requested_backends, project, application, _
537     if application:
538         project = application[0]
539     elif project:
540         project = project[0]
542     if "Tup" in requested_backends:
543         # As a special case, if Tup was requested, do not combine it with any
544         # Make based backend by default.
545         all_backends = []
546     elif artifact_builds:
547         all_backends = ["FasterMake+RecursiveMake"]
548     else:
549         all_backends = ["RecursiveMake", "FasterMake"]
550     # Normally, we'd use target.os == 'WINNT', but a dependency on target
551     # would require target to depend on --help, as well as host and shell,
552     # and this is not a can of worms we can open at the moment.
553     if sys.platform == "win32" and compile_environment and project != "mobile/android":
554         all_backends.append("VisualStudio")
555     return tuple(all_backends) or None
558 option(
559     "--build-backends",
560     nargs="+",
561     default=build_backend_defaults,
562     choices=build_backends_choices,
563     help="Build backends to generate",
567 @depends("--build-backends")
568 def build_backends(backends):
569     return backends
572 set_config("BUILD_BACKENDS", build_backends)
575 @depends(check_build_environment, build_backends)
576 @imports("glob")
577 def check_objdir_backend_reuse(build_env, backends):
578     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
579     # intentionally vague for use with the substring match below.
580     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
581     for backend_file in glob.iglob(
582         os.path.join(build_env.topobjdir, "backend.*Backend")
583     ):
584         for prev, curr in incompatible_backends:
585             if prev in backend_file and any(curr in b for b in backends):
586                 die(
587                     "The active objdir, %s, was previously "
588                     "used to build with a %s based backend. "
589                     "Change objdirs (by setting MOZ_OBJDIR in "
590                     "your mozconfig) or clobber to continue.\n",
591                     build_env.topobjdir,
592                     prev,
593                 )
596 option(
597     "--disable-gtest-in-build",
598     help="Force disable building the gtest libxul during the build.",
599     when="--enable-compile-environment",
602 # Determine whether to build the gtest xul. This happens in automation
603 # on Android and Desktop platforms with the exception of:
604 #  - Windows PGO, where linking xul-gtest.dll takes too long;
605 #  - Android other than x86_64, where gtest is not required.
606 @depends(
607     "MOZ_PGO",
608     build_project,
609     target,
610     "MOZ_AUTOMATION",
611     "--disable-gtest-in-build",
612     enable_tests,
613     when="--enable-compile-environment",
615 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
616     if not enable_tests or not enabled:
617         return None
618     if (
619         automation
620         and build_project in ("browser", "comm/mail", "mobile/android")
621         and not (
622             (pgo and target.os == "WINNT")
623             or (target.os == "Android" and target.cpu != "x86_64")
624         )
625     ):
626         return True
629 set_config("LINK_GTEST_DURING_COMPILE", build_gtest)
631 # Localization
632 # ==============================================================
633 option(
634     "--enable-ui-locale",
635     default="en-US",
636     help="Select the user interface locale (default: en-US)",
639 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
641 # clang-plugin location
642 # ==============================================================
643 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
644 def clang_plugin_path(library_name_info, build_env):
645     topobjdir = build_env.topobjdir
646     if topobjdir.endswith("/js/src"):
647         topobjdir = topobjdir[:-7]
648     return os.path.abspath(
649         os.path.join(
650             topobjdir,
651             "build",
652             "clang-plugin",
653             "%sclang-plugin%s"
654             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
655         )
656     )
659 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
662 # Awk detection
663 # ==============================================================
664 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
666 # Until the AWK variable is not necessary in old-configure
667 @depends(awk)
668 def awk_for_old_configure(value):
669     return value
672 add_old_configure_assignment("AWK", awk_for_old_configure)
675 # Perl detection
676 # ==============================================================
677 perl = check_prog("PERL", ("perl5", "perl"))
679 # Until the PERL variable is not necessary in old-configure
680 @depends(perl)
681 def perl_for_old_configure(value):
682     return value
685 add_old_configure_assignment("PERL", perl_for_old_configure)
688 @template
689 def perl_version_check(min_version):
690     @depends(perl)
691     @checking("for minimum required perl version >= %s" % min_version)
692     def get_perl_version(perl):
693         return Version(
694             check_cmd_output(
695                 perl,
696                 "-e",
697                 "print $]",
698                 onerror=lambda: die("Failed to get perl version."),
699             )
700         )
702     @depends(get_perl_version)
703     def check_perl_version(version):
704         if version < min_version:
705             die("Perl %s or higher is required.", min_version)
707     @depends(perl)
708     @checking("for full perl installation")
709     @imports("subprocess")
710     def has_full_perl_installation(perl):
711         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
712         return ret == 0
714     @depends(has_full_perl_installation)
715     def require_full_perl_installation(has_full_perl_installation):
716         if not has_full_perl_installation:
717             die(
718                 "Cannot find Config.pm or $Config{archlib}. "
719                 "A full perl installation is required."
720             )
723 perl_version_check("5.006")
726 # GNU make detection
727 # ==============================================================
728 option(env="MAKE", nargs=1, help="Path to GNU make")
731 @depends("MAKE", host)
732 def possible_makes(make, host):
733     candidates = []
734     if host.kernel == "WINNT":
735         candidates.append("mingw32-make")
736     if make:
737         candidates.append(make[0])
738     if host.kernel == "WINNT":
739         candidates.extend(("make", "gmake"))
740     else:
741         candidates.extend(("gmake", "make"))
742     return candidates
745 check_prog("GMAKE", possible_makes)
747 # watchman detection
748 # ==============================================================
750 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
753 @depends(host, "WATCHMAN")
754 @checking("for watchman", callback=lambda w: w.path if w else "not found")
755 def watchman(host, prog):
756     # On Windows, `watchman` is only supported on 64-bit hosts.
757     if host.os == "WINNT" and host.cpu != "x86_64":
758         return
760     if not prog:
761         prog = find_program("watchman")
763     if not prog:
764         return
766     # `watchman version` will talk to the Watchman daemon service.
767     # This can hang due to permissions problems. e.g.
768     # https://github.com/facebook/watchman/issues/376. So use
769     # `watchman --version` to prevent a class of failures.
770     out = check_cmd_output(prog, "--version", onerror=lambda: None)
771     if out is None:
772         return
774     return namespace(path=prog, version=Version(out.strip()))
777 @depends_if(watchman)
778 @checking("for watchman version")
779 def watchman_version(w):
780     return w.version
783 set_config("WATCHMAN", watchman.path)
786 @depends_all(hg_version, hg_config, watchman)
787 @checking("for watchman Mercurial integration")
788 @imports("os")
789 def watchman_hg(hg_version, hg_config, watchman):
790     if hg_version < Version("3.8"):
791         return "no (Mercurial 3.8+ required)"
793     ext_enabled = False
794     mode_disabled = False
796     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
797         if k in hg_config and hg_config[k] != "!":
798             ext_enabled = True
800     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
802     if not ext_enabled:
803         return "no (fsmonitor extension not enabled)"
804     if mode_disabled:
805         return "no (fsmonitor.mode=off disables fsmonitor)"
807     return True
810 # Miscellaneous programs
811 # ==============================================================
812 check_prog("XARGS", ("xargs",))
815 @depends(target)
816 def extra_programs(target):
817     if target.kernel == "Darwin":
818         return namespace(
819             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
820             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
821             HFS_TOOL=("hfsplus",),
822         )
823     if target.os == "GNU" and target.kernel == "Linux":
824         return namespace(RPMBUILD=("rpmbuild",))
827 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
828 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
829 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
830 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
833 @depends(target)
834 @imports("os")
835 def makensis_progs(target):
836     if target.kernel != "WINNT":
837         return
839     candidates = [
840         "makensis-3.01",
841         "makensis-3.0b3",
842         "makensis-3.0b1",
843         "makensis",
844     ]
846     # Look for nsis installed by msys environment. But only the 32-bit version.
847     # We use an absolute path and insert as the first entry so it is preferred
848     # over a 64-bit exe that may be in PATH.
849     if "MSYSTEM_PREFIX" in os.environ:
850         prefix = os.path.dirname(os.environ["MSYSTEM_PREFIX"])
851         candidates.insert(0, os.path.join(prefix, "mingw32", "bin", "makensis.exe"))
853     return tuple(candidates)
856 nsis = check_prog("MAKENSISU", makensis_progs, allow_missing=True)
858 # Make sure the version of makensis is up to date.
859 @depends(nsis, wine)
860 @checking("for NSIS version")
861 @imports("re")
862 def nsis_version(nsis, wine):
863     if not nsis:
864         return None
865     nsis_min_version = "3.0b1"
866     onerror = lambda: die("Failed to get nsis version.")
867     if wine and nsis.lower().endswith(".exe"):
868         out = check_cmd_output(wine, nsis, "-version", onerror=onerror)
869     else:
870         out = check_cmd_output(nsis, "-version", onerror=onerror)
872     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
874     if not m:
875         raise FatalCheckError("Unknown version of makensis")
876     ver = Version(m.group(0))
878     # Versions comparisons don't quite work well with beta versions, so ensure
879     # it works for the non-beta version.
880     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
881         raise FatalCheckError(
882             "To build the installer you must have NSIS"
883             " version %s or greater in your path" % nsis_min_version
884         )
886     return ver
889 # And that makensis is 32-bit (but only on Windows).
890 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
891 @checking("for 32-bit NSIS")
892 def nsis_binary_type(nsis):
893     bin_type = windows_binary_type(nsis)
894     if bin_type != "win32":
895         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
897     return "yes"
900 # And any flags we have to give to makensis
901 @depends(host)
902 def nsis_flags(host):
903     if host.kernel != "WINNT":
904         return "-nocd"
905     return ""
908 set_config("MAKENSISU_FLAGS", nsis_flags)
910 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
911 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
914 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
915 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
916     clang = None
917     for compiler in (host_c_compiler, c_compiler):
918         if compiler and compiler.type == "clang":
919             clang = compiler.compiler
920             break
921         elif compiler and compiler.type == "clang-cl":
922             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
923             break
925     if not clang and bindgen_config_paths:
926         clang = bindgen_config_paths.clang_path
927     llvm_objdump = "llvm-objdump"
928     if clang:
929         out = check_cmd_output(
930             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
931         )
932         if out:
933             llvm_objdump = out.rstrip()
934     return (llvm_objdump,)
937 llvm_objdump = check_prog(
938     "LLVM_OBJDUMP",
939     llvm_objdump,
940     what="llvm-objdump",
941     when="--enable-compile-environment",
942     paths=clang_search_path,
945 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
948 option("--enable-dtrace", help="Build with dtrace support")
950 dtrace = check_header(
951     "sys/sdt.h",
952     when="--enable-dtrace",
953     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
956 set_config("HAVE_DTRACE", True, when=dtrace)
957 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
958 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
961 option("--disable-icf", help="Disable Identical Code Folding")
963 add_old_configure_assignment(
964     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
968 option(
969     "--enable-strip",
970     when=compile_environment,
971     help="Enable stripping of libs & executables",
974 # This should be handled as a `when` once bug 1617793 is fixed.
975 @depends("--enable-strip", c_compiler, when=compile_environment)
976 def enable_strip(strip, c_compiler):
977     if strip and c_compiler.type != "clang-cl":
978         return True
981 set_config("ENABLE_STRIP", enable_strip)
983 option(
984     "--disable-install-strip",
985     when=compile_environment,
986     help="Enable stripping of libs & executables when packaging",
989 # This should be handled as a `when` once bug 1617793 is fixed.
990 @depends("--enable-install-strip", c_compiler, when=compile_environment)
991 def enable_install_strip(strip, c_compiler):
992     if strip and c_compiler.type != "clang-cl":
993         return True
996 set_config("PKG_STRIP", enable_install_strip)
999 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1000 def strip(strip, install_strip):
1001     return strip or install_strip
1004 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1007 @depends("STRIP_FLAGS", profiling, target, when=strip)
1008 def strip_flags(flags, profiling, target):
1009     if flags:
1010         return flags[0].split()
1011     if profiling:
1012         # Only strip debug info and symbols when profiling is enabled, keeping
1013         # local symbols.
1014         if target.kernel == "Darwin":
1015             return ["-S"]
1016         elif target.os == "Android":
1017             # The tooling we use with Android supports detached symbols, and the
1018             # size increase caused by local symbols are too much for mobile. So,
1019             # don't restrict the amount of stripping with a flag.
1020             return
1021         else:
1022             return ["--strip-debug"]
1023     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1024     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1025     elif target.kernel == "Darwin":
1026         return ["-x", "-S"]
1029 set_config("STRIP_FLAGS", strip_flags)
1032 @depends(js_standalone, target)
1033 def system_zlib_default(js_standalone, target):
1034     return js_standalone and target.kernel != "WINNT"
1037 option(
1038     "--with-system-zlib",
1039     nargs="?",
1040     default=system_zlib_default,
1041     help="{Use|Do not use} system libz",
1045 @depends("--with-system-zlib")
1046 def deprecated_system_zlib_path(value):
1047     if len(value) == 1:
1048         die(
1049             "--with-system-zlib=PATH is not supported anymore. Please use "
1050             "--with-system-zlib and set any necessary pkg-config environment variable."
1051         )
1054 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1056 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1057 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1060 # Please do not add configure checks from here on.
1062 # Fallthrough to autoconf-based configure
1063 include("build/moz.configure/old.configure")
1065 # JS Subconfigure.
1066 include("js/sub.configure", when=compile_environment & toolkit)
1069 @depends(check_build_environment, build_project)
1070 @imports("__sandbox__")
1071 @imports("glob")
1072 @imports(_from="os.path", _import="exists")
1073 def config_status_deps(build_env, build_project):
1075     topsrcdir = build_env.topsrcdir
1076     topobjdir = build_env.topobjdir
1078     if not topobjdir.endswith("js/src"):
1079         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1080     else:
1081         # mozconfig changes may impact js configure.
1082         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1084     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1085     if exists(confvars):
1086         extra_deps.append(confvars)
1088     return (
1089         list(__sandbox__._all_paths)
1090         + extra_deps
1091         + [
1092             os.path.join(topsrcdir, "CLOBBER"),
1093             os.path.join(topsrcdir, "configure.in"),
1094             os.path.join(topsrcdir, "js", "src", "configure.in"),
1095             os.path.join(topsrcdir, "nsprpub", "configure"),
1096             os.path.join(topsrcdir, "config", "milestone.txt"),
1097             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1098             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1099             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1100             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1101             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1102             os.path.join(topsrcdir, "python", "mozbuild", "mozbuild", "virtualenv.py"),
1103             os.path.join(topsrcdir, "testing", "mozbase", "packages.txt"),
1104             os.path.join(topsrcdir, "aclocal.m4"),
1105             os.path.join(topsrcdir, "old-configure.in"),
1106             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1107             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1108         ]
1109         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1110     )
1113 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1114 # Please do not add anything after setting config_dep_paths.