From aa0fcc67b3b1a6f2febec9c0fba8b334832566ed Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 29 May 2025 13:12:59 -0400 Subject: [PATCH] Meta: Tentatively support BSD distributions in ladybird.py Support was unknowingly dropped when porting ladybird.sh to ladybird.py. This tentatively restores this support, but is untested on a BSD system. --- Meta/find_compiler.py | 13 +++++-------- Meta/host_platform.py | 20 ++++++++++++++++++++ Meta/ladybird.py | 17 +++-------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Meta/find_compiler.py b/Meta/find_compiler.py index 73b5e61d42b..f4f0bca9548 100755 --- a/Meta/find_compiler.py +++ b/Meta/find_compiler.py @@ -123,6 +123,9 @@ def pick_host_compiler(platform: Platform, cc: str, cxx: str) -> tuple[str, str] "gcc-14", ] + if platform.host_system == HostSystem.BSD: + gcc_candidates.append("egcc") + if platform.host_system == HostSystem.macOS: clang_homebrew_path = Path("/opt/homebrew/opt/llvm/bin") homebrew_path = Path("/opt/homebrew/bin") @@ -131,7 +134,7 @@ def pick_host_compiler(platform: Platform, cc: str, cxx: str) -> tuple[str, str] clang_candidates.extend([str(homebrew_path.joinpath(c)) for c in clang_candidates]) gcc_candidates.extend([str(homebrew_path.joinpath(c)) for c in gcc_candidates]) - elif platform.host_system == HostSystem.Linux: + elif platform.host_system in (HostSystem.Linux, HostSystem.BSD): local_path = Path("/usr/local/bin") clang_candidates.extend([str(local_path.joinpath(c)) for c in clang_candidates]) @@ -166,15 +169,9 @@ def pick_host_compiler(platform: Platform, cc: str, cxx: str) -> tuple[str, str] sys.exit(1) -def default_host_compiler(platform: Platform) -> tuple[str, str]: - if platform.host_system == HostSystem.Windows: - return ("clang-cl", "clang-cl") - return ("cc", "c++") - - def main(): platform = Platform() - (default_cc, default_cxx) = default_host_compiler(platform) + (default_cc, default_cxx) = platform.default_compiler() parser = argparse.ArgumentParser(description="Find valid compilers") diff --git a/Meta/host_platform.py b/Meta/host_platform.py index eff2d69a784..98582334d2b 100644 --- a/Meta/host_platform.py +++ b/Meta/host_platform.py @@ -17,6 +17,7 @@ class HostSystem(enum.IntEnum): Linux = enum.auto() macOS = enum.auto() Windows = enum.auto() + BSD = enum.auto() class Platform: @@ -28,6 +29,8 @@ class Platform: self.host_system = HostSystem.macOS elif self.system == "Linux": self.host_system = HostSystem.Linux + elif self.system in ("FreeBSD", "OpenBSD", "NetBSD", "DragonFly"): + self.host_system = HostSystem.BSD else: print(f"Unsupported host system {self.system}", file=sys.stderr) sys.exit(1) @@ -40,3 +43,20 @@ class Platform: else: print(f"Unsupported host architecture {self.architecture}", file=sys.stderr) sys.exit(1) + + def default_compiler(self) -> tuple[str, str]: + if self.host_system == HostSystem.Windows: + return ("clang-cl", "clang-cl") + return ("cc", "c++") + + def default_debugger(self) -> str: + if self.host_system in (HostSystem.Linux, HostSystem.BSD): + return "gdb" + return "lldb" + + def default_symbolizer(self) -> str: + if self.host_system == HostSystem.Windows: + return "llvm-symbolizer" + if self.host_system == HostSystem.macOS: + return "atos" + return "addr2line" diff --git a/Meta/ladybird.py b/Meta/ladybird.py index 84e349c6e65..dbc07a90717 100755 --- a/Meta/ladybird.py +++ b/Meta/ladybird.py @@ -18,7 +18,6 @@ from typing import Optional sys.path.append(str(Path(__file__).resolve().parent.parent)) -from Meta.find_compiler import default_host_compiler from Meta.find_compiler import pick_host_compiler from Meta.host_platform import HostArchitecture from Meta.host_platform import HostSystem @@ -29,7 +28,7 @@ from Toolchain.BuildVcpkg import build_vcpkg def main(): platform = Platform() - (default_cc, default_cxx) = default_host_compiler(platform) + (default_cc, default_cxx) = platform.default_compiler() parser = argparse.ArgumentParser(description="Ladybird") subparsers = parser.add_subparsers(dest="command") @@ -76,9 +75,7 @@ def main(): help="Launches the application on the build host in a gdb or lldb session", parents=[preset_parser, target_parser], ) - debug_parser.add_argument( - "--debugger", required=False, default="gdb" if platform.host_system == HostSystem.Linux else "lldb" - ) + debug_parser.add_argument("--debugger", required=False, default=platform.default_debugger()) debug_parser.add_argument( "-cmd", action="append", required=False, default=[], help="Additional commands passed through to the debugger" ) @@ -107,15 +104,7 @@ def main(): help="Resolves the addresses in the target binary to a file:line", parents=[preset_parser, compiler_parser, target_parser], ) - addr2line_parser.add_argument( - "--program", - required=False, - default=( - "llvm-symbolizer" - if platform.host_system == HostSystem.Windows - else "addr2line" if platform.host_system == HostSystem.Linux else "atos" - ), - ) + addr2line_parser.add_argument("--program", required=False, default=platform.default_symbolizer()) addr2line_parser.add_argument("addresses", nargs=argparse.REMAINDER) args = parser.parse_args()