Files
tubestation/build/rust/mozbuild/generate_buildconfig.py
Gabriele Svelto 08a8136801 Bug 1620998 - Out-of-process crash generation for child processes r=afranchuk,geckoview-reviewers,glandium,browser-installer-reviewers,nalexander,owlish
This implements the crash helper service used to move child process crash
report generation out of the main process and into its own process. This is
implemented as a separate executable that is launched on startup by the main
process on the desktop platforms and as a service hosted by a separate process
on Android.

The crash helper process is started when the first exception handler is set
on desktop platforms and before loading libxul on Android. In both cases
starting this process happens asynchronously so that neither the main process
nor child processes have to wait for it to come up. If a crash happens before
the crash helper has started, the crashed process will wait for it to fully
come up and then proceed with regular crash generation.

IPC with the crash helper is implemented using Unix sockets on Linux and macOS
with the former using sequential packets and the latter using stream sockets.
On Windows we use named pipes. In all cases the choice of IPC was dictated both
by the requirement to eventually talk directly to child processes from within
the sandbox, and to external processes in case of Windows as the Windows
Error Reporting exception handler must be able to reach out to the helper from
within a restricted context. These particular requirements are not used yet but
will be as we move more logic out of the main process logic.

Differential Revision: https://phabricator.services.mozilla.com/D231083
2025-04-18 16:37:06 +00:00

132 lines
4.5 KiB
Python

# 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
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import string
import textwrap
import buildconfig
def generate_bool(name):
value = buildconfig.substs.get(name)
return f"pub const {name}: bool = {'true' if value else 'false'};\n"
def generate_string_array(name):
value = buildconfig.substs.get(name) or []
return (
f"pub const {name}: [&str; {len(value)}] = ["
+ ",".join(map(escape_rust_string, value))
+ "];\n"
)
def generate_string(name):
value = buildconfig.substs.get(name) or ""
return f"pub const {name}: &str = {escape_rust_string(value)};\n"
def escape_rust_string(value):
"""escape the string into a Rust literal"""
# This could be more generous, but we're only escaping paths with it.
unescaped = string.ascii_letters + string.digits + "/$+-_~ "
result = ""
for ch in str(value):
if ch in unescaped:
result += ch
elif ch == "\r":
result += "\\r"
elif ch == "\n":
result += "\\n"
elif ch == "\\":
result += "\\\\"
elif ch == '"':
result += '\\"'
else:
result += "\\u{%x}" % ord(ch)
return '"%s"' % result
def generate(output):
# Write out a macro which can be used within `include!`-like methods to
# reference the topobjdir.
output.write(
textwrap.dedent(
f"""
/// Macro used to name a path in the objdir for use with macros like `include!`
#[macro_export]
macro_rules! objdir_path {{
($path:literal) => {{
concat!({escape_rust_string(buildconfig.topobjdir + "/")}, $path)
}}
}}
/// Macro used to name a path in the srcdir for use with macros like `include!`
#[macro_export]
macro_rules! srcdir_path {{
($path:literal) => {{
concat!({escape_rust_string(buildconfig.topsrcdir + "/")}, $path)
}}
}}
/// The objdir path for use in build scripts
pub const TOPOBJDIR: &str = {escape_rust_string(buildconfig.topobjdir)};
/// The srcdir path for use in build scripts
pub const TOPSRCDIR: &str = {escape_rust_string(buildconfig.topsrcdir)};
"""
)
)
windows_rs_dir = buildconfig.substs.get("MOZ_WINDOWS_RS_DIR")
if windows_rs_dir:
output.write(
textwrap.dedent(
f"""
/// Macro used to name a path in the srcdir for use with macros like `include!`
#[macro_export]
macro_rules! windows_rs_path {{
($path:literal) => {{
concat!({escape_rust_string(windows_rs_dir + "/")}, $path)
}}
}}
/// Macro used to re-export windows-rs's public items
#[macro_export]
macro_rules! windows_rs_lib {{
() => {{
#[path = {escape_rust_string(windows_rs_dir + "/src/lib.rs")}]
mod lib;
pub use lib::*;
}}
}}
"""
)
)
# Write out some useful strings from the buildconfig.
output.write(generate_string("MOZ_MACBUNDLE_ID"))
output.write(generate_string("MOZ_APP_BASENAME"))
output.write(generate_string("MOZ_APP_NAME"))
output.write(generate_string("MOZ_APP_VENDOR"))
# Write out some useful booleans from the buildconfig.
output.write(generate_bool("MOZ_FOLD_LIBS"))
output.write(generate_bool("NIGHTLY_BUILD"))
output.write(generate_bool("RELEASE_OR_BETA"))
output.write(generate_bool("EARLY_BETA_OR_EARLIER"))
output.write(generate_bool("MOZ_DEV_EDITION"))
output.write(generate_bool("MOZ_ESR"))
output.write(generate_bool("MOZ_DIAGNOSTIC_ASSERT_ENABLED"))
# Used by toolkit/crashreporter/client
output.write(generate_bool("MOZ_CRASHREPORTER_MOCK"))
output.write(generate_string_array("BINDGEN_SYSTEM_FLAGS"))
output.write(generate_string_array("MOZ_GTK3_CFLAGS"))
output.write(generate_string_array("MOZ_GTK3_LIBS"))
output.write(generate_string_array("NSPR_CFLAGS"))
output.write(generate_string_array("NSS_CFLAGS"))
output.write(generate_string_array("MOZ_PIXMAN_CFLAGS"))
output.write(generate_string_array("MOZ_ICU_CFLAGS"))