Source code
Revision control
Copy as Markdown
Other Tools
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
project_flag(
"MOZ_ANDROID_EXCLUDE_FONTS",
help="Whether to exclude font files from the build",
default=True,
)
project_flag(
"MOZ_ANDROID_HLS_SUPPORT",
help="Enable HLS (HTTP Live Streaming) support (currently using the ExoPlayer library)",
default=True,
)
option(
"--num-content-services",
default="40",
help="The number of content process services to generate in the GeckoView manifest",
)
@depends("--num-content-services")
def num_content_services(value):
strValue = value[0]
intValue = int(strValue)
acceptableRange = range(1, 41)
if intValue not in acceptableRange:
die(
"Unacceptable value, must be within range [%d,%d)"
% (acceptableRange.start, acceptableRange.stop)
)
return strValue
set_config("MOZ_ANDROID_CONTENT_SERVICE_COUNT", num_content_services)
set_define("MOZ_ANDROID_CONTENT_SERVICE_COUNT", num_content_services)
option(
"--enable-isolated-zygote-process",
env="MOZ_ANDROID_CONTENT_SERVICE_ISOLATED_WITH_ZYGOTE",
help="Enable generating content process services with app Zygote preloading and isolated processes",
)
isIsolatedAppZygoteProcessEnabled = depends_if(
"MOZ_ANDROID_CONTENT_SERVICE_ISOLATED_WITH_ZYGOTE"
)(lambda _: True)
set_config(
"MOZ_ANDROID_CONTENT_SERVICE_ISOLATED_WITH_ZYGOTE",
isIsolatedAppZygoteProcessEnabled,
)
set_define(
"MOZ_ANDROID_CONTENT_SERVICE_ISOLATED_WITH_ZYGOTE",
isIsolatedAppZygoteProcessEnabled,
)
option(
"--enable-isolated-process",
env="MOZ_ANDROID_CONTENT_SERVICE_ISOLATED_PROCESS",
help="Enable generating content process services with isolatedProcess=true",
)
isIsolatedProcessEnabled = depends_if("MOZ_ANDROID_CONTENT_SERVICE_ISOLATED_PROCESS")(
lambda _: True
)
set_config(
"MOZ_ANDROID_CONTENT_SERVICE_ISOLATED_PROCESS",
isIsolatedProcessEnabled,
)
set_define(
"MOZ_ANDROID_CONTENT_SERVICE_ISOLATED_PROCESS",
isIsolatedProcessEnabled,
)
option(
"--enable-geckoview-lite",
help="Build GeckoView in Lite mode. Lite mode removes all unnecessary dependencies like Glean",
)
set_config("MOZ_ANDROID_GECKOVIEW_LITE", True, when="--enable-geckoview-lite")
option(
"--enable-android-subproject",
choices=(
"fenix",
"focus",
"geckoview_example",
),
nargs="?",
help="Build a subproject of android. Possible options: fenix/focus/geckoview_example",
)
@depends("--enable-android-subproject")
def android_subproject(value):
if value:
return value[0]
set_config("MOZ_ANDROID_SUBPROJECT", android_subproject)
# The android:debuggable flag controls if a debugger can be attached on to the
# running app. Default this setting to follow `--enable-debug`. Use this flag to
# allow attaching debugging to app compiled in an optimized / release
# configuration.
#
# NOTE: There are numerous performance implications for a package marked as
# android:debuggable versus a similar one that isn't. Particularly around
# AOT compilation heuristics and caches.
option(
"--enable-android-debuggable",
default=moz_debug,
help="{Enable|Disable} the android:debuggable flag in AndroidManifest.xml",
)
@depends("--enable-android-debuggable")
def android_debuggable(value):
if value:
return True
set_config("MOZ_ANDROID_DEBUGGABLE", android_debuggable)
imply_option("MOZ_NORMANDY", False)
imply_option("MOZ_SERVICES_HEALTHREPORT", True)
imply_option("MOZ_GECKOVIEW_HISTORY", True)
imply_option("MOZ_APP_UA_NAME", "Firefox")
imply_option("MOZ_APP_VENDOR", "Mozilla")
imply_option("MOZ_APP_ID", "{aa3c5121-dab2-40e2-81ca-7ea25febc110}")
imply_option("BROWSER_CHROME_URL", "chrome://geckoview/content/geckoview.xhtml")
@depends(target)
def check_target(target):
if target.os != "Android":
log.error(
"You must specify --target=arm-linux-androideabi (or some "
"other valid Android target) when building mobile/android."
)
die(
"Build_Instructions/Simple_Firefox_for_Android_build "
"for more information about the necessary options."
)
include("../shared/moz.configure")
include("../../toolkit/moz.configure")
include("../../build/moz.configure/android-sdk.configure")
include("../../build/moz.configure/java.configure")
include("gradle.configure")
# Automation will set this via the TC environment.
option(
env="MOZ_ANDROID_FAT_AAR_ARCHITECTURES",
nargs="*",
choices=("armeabi-v7a", "arm64-v8a", "x86_64"),
help='Comma-separated list of Android CPU architectures like "armeabi-v7a,arm64-v8a,x86_64"',
)
set_config(
"MOZ_ANDROID_FAT_AAR_ARCHITECTURES",
depends("MOZ_ANDROID_FAT_AAR_ARCHITECTURES")(lambda x: x),
)
# Template to check for a build-time host/bin program that is either produced as
# part of the build or is fetched from a toolchain artifact. Also allows
# `--without-{prog}` to disable checking.
#
# Such compiled programs are "part of the build" but need special accommodations
# to distribute to artifact builds: they are distributed as toolchain builds
# rather than extracted from a package or a test package. In addition, these
# compiled programs may not be needed for very unusual jobs, in particular
# `android-gradle-dependencies` jobs, so they can be disabled entirely.
#
# - `var` is the name of the variable that will be set with `set_config` when
# the program is found, like "A_PROG".
# - `prog` is the name of the program, like "a-prog".
# - `toolchain` is the name of the toolchain (defaults to `prog`).
@template
def check_host_bin_prog(var, prog, toolchain=None):
option(f"--without-{prog}", help="Disable building with {prog}")
with only_when(f"--with-{prog}"):
with only_when(compile_environment):
# Produced at build-time. Look in `$DIST/host/bin`.
set_config(
var,
depends(build_environment.dist, bin_suffix(host))(
lambda dist, bin_suffix: f"{dist}/host/bin/{prog}{bin_suffix}"
),
)
with only_when(~compile_environment):
# Fetched at configure-time. Look in `~/.mozbuild` locally or
# `$MOZ_FETCH_DIR` in automation.
check_prog(
var,
[prog],
what=prog,
bootstrap=toolchain or prog,
)
check_host_bin_prog("EMBEDDED_UNIFFI_BINDGEN", "embedded-uniffi-bindgen")
check_host_bin_prog("NIMBUS_FML", "nimbus-fml")
@depends(
moz_app_name,
android_cpu_arch,
moz_child_process_name,
moz_debug,
"MOZ_ANDROID_EXCLUDE_FONTS",
"--enable-pref-extensions",
artifact_builds,
"MOZ_ANDROID_FAT_AAR_ARCHITECTURES",
mac_bundle_name,
moz_pkg_binpath,
clang_rt_asan_lib_path,
enable_appservices_in_tree,
)
@imports(_from="mozbuild.packaging", _import="quote_defines")
@imports(_from="os.path", _import="basename")
def package_manifest_defines(
app_name,
android_cpu_arch,
child_process_name,
moz_debug,
exclude_fonts,
pref_extensions,
artifact_builds,
fat_aar_architectures,
mac_bundle_name,
binpath,
clang_rt_asan_lib_path,
appservices_in_tree,
):
defines = [
f"-DMOZ_APP_NAME={app_name}",
"-DPREF_DIR=defaults/pref",
"-DJAREXT=",
f"-DMOZ_CHILD_PROCESS_NAME={child_process_name or ''}",
f"-DANDROID_CPU_ARCH={android_cpu_arch or ''}",
f"-DBINPATH={binpath}",
]
if moz_debug:
defines.append("-DMOZ_DEBUG=1")
if exclude_fonts:
defines.append("-DMOZ_ANDROID_EXCLUDE_FONTS=1")
if pref_extensions:
defines.append("-DMOZ_PREF_EXTENSIONS=1")
if artifact_builds:
defines.append("-DMOZ_ARTIFACT_BUILDS=1")
if fat_aar_architectures:
defines.append("-DMOZ_ANDROID_FAT_AAR_ARCHITECTURES=1")
if mac_bundle_name:
defines.append(f"-DAPPNAME={mac_bundle_name}")
if clang_rt_asan_lib_path:
defines.append(f"-DMOZ_CLANG_RT_ASAN_LIB={basename(clang_rt_asan_lib_path)}")
if appservices_in_tree:
defines.append("-DMOZ_APPSERVICES_IN_TREE=1")
return quote_defines(defines)
set_config("PACKAGE_MANIFEST_DEFINES", package_manifest_defines)
@depends(build_environment.topsrcdir)
@imports(_import="mozpack.path", _as="mozpath")
def package_inputs(topsrcdir):
installer = mozpath.join(topsrcdir, "mobile", "android", "installer")
return namespace(
manifest=mozpath.join(installer, "package-manifest.in"),
removals=mozpath.join(installer, "removed-files.in"),
allowed_dupes=[mozpath.join(installer, "allowed-dupes.mn")],
)
set_config("MOZ_PKG_MANIFEST", package_inputs.manifest)
set_config("MOZ_PKG_REMOVALS", package_inputs.removals)
set_config("MOZ_PKG_ALLOWED_DUPES", package_inputs.allowed_dupes)
# When packaging an artifact build not all xpt files expected by the packager
# will be present. Toolchain gradle-dependencies tasks use
# --disable-compile-environment and bin/lib*.so files are missing.
set_config(
"MOZ_PKG_FATAL_WARNINGS", True, when=~artifact_builds & compile_environment
)
set_config("MOZ_CHROME_LOCALE_ENTRIES", ["@BINPATH@/chrome/"])