Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCons: Improve debug symbol logic & cleanup #91669

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ env.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix
env.__class__.add_shared_library = methods.add_shared_library
env.__class__.add_library = methods.add_library
env.__class__.add_program = methods.add_program
env.__class__.arrange_program_clean = methods.arrange_program_clean
env.__class__.CommandNoCache = methods.CommandNoCache
env.__class__.Run = methods.Run
env.__class__.disable_warnings = methods.disable_warnings
Expand Down
14 changes: 14 additions & 0 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,20 @@ def Run(env, function):
return Action(function, "$GENCOMSTR")


def arrange_program_clean(env, prog):
"""
Given an SCons program, arrange for output files SCons doesn't know about
to be cleaned when SCons is called with --clean
"""
EXTENSIONS_TO_CLEAN = [".ilk", ".exp", ".pdb", ".lib", ".debugsymbols", ".dSym"]
for program in prog:
path = "#" + Path(str(program)).relative_to(base_folder_path).as_posix()
if path.endswith(".exe"):
path = path[:-4]
extra_files_to_clean = [f"{path}{extension}" for extension in EXTENSIONS_TO_CLEAN]
env.Clean(prog, extra_files_to_clean)


def detect_darwin_sdk_path(platform, env):
sdk_name = ""
if platform == "macos":
Expand Down
15 changes: 13 additions & 2 deletions platform/linuxbsd/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Import("env")

import platform_linuxbsd_builders
import os

common_linuxbsd = [
"crash_handler_linuxbsd.cpp",
Expand Down Expand Up @@ -39,6 +39,17 @@ if env["dbus"]:
common_linuxbsd.append("dbus-so_wrap.c")

prog = env.add_program("#bin/godot", ["godot_linuxbsd.cpp"] + common_linuxbsd)
env.arrange_program_clean(prog)


def make_debug_linuxbsd(target, source, env):
src = str(target[0])
dst = f"{src}.debugsymbols"

os.system(f"objcopy --only-keep-debug {src} {dst}")
os.system(f"strip --strip-debug --strip-unneeded {src}")
os.system(f"objcopy --add-gnu-debuglink={dst} {src}")


if env["debug_symbols"] and env["separate_debug_symbols"]:
env.AddPostAction(prog, env.Run(platform_linuxbsd_builders.make_debug_linuxbsd))
env.AddPostAction(prog, env.Run(make_debug_linuxbsd))
10 changes: 0 additions & 10 deletions platform/linuxbsd/platform_linuxbsd_builders.py

This file was deleted.

18 changes: 16 additions & 2 deletions platform/macos/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Import("env")

import os, json
from platform_methods import architectures, lipo, get_build_version
import platform_macos_builders
import subprocess
import shutil

Expand Down Expand Up @@ -123,9 +122,24 @@ files = [
]

prog = env.add_program("#bin/godot", files)
env.arrange_program_clean(prog)


def make_debug_macos(target, source, env):
src = str(target[0])
dst = f"{src}.dSYM"

if env["macports_clang"] != "no":
mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")
mpclangver = env["macports_clang"]
os.system(f"{mpprefix}/libexec/llvm-{mpclangver}/bin/llvm-dsymutil {src} -o {dst}")
else:
os.system(f"dsymutil {src} -o {dst}")
os.system(f"strip -u -r {src}")


if env["debug_symbols"] and env["separate_debug_symbols"]:
env.AddPostAction(prog, env.Run(platform_macos_builders.make_debug_macos))
env.AddPostAction(prog, env.Run(make_debug_macos))

if env["generate_bundle"]:
generate_bundle_command = env.Command("generate_bundle", [], generate_bundle)
Expand Down
14 changes: 0 additions & 14 deletions platform/macos/platform_macos_builders.py

This file was deleted.

36 changes: 18 additions & 18 deletions platform/windows/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Import("env")

import os
from pathlib import Path
import platform_windows_builders

sources = []

Expand Down Expand Up @@ -34,18 +32,6 @@ common_win_wrap = [
]


def arrange_program_clean(prog):
"""
Given an SCons program, arrange for output files SCons doesn't know about
to be cleaned when SCons is called with --clean
"""
extensions_to_clean = [".ilk", ".exp", ".pdb", ".lib"]
for program in prog:
executable_stem = Path(program.name).stem
extra_files_to_clean = [f"#bin/{executable_stem}{extension}" for extension in extensions_to_clean]
Clean(prog, extra_files_to_clean)


res_file = "godot_res.rc"
res_target = "godot_res" + env["OBJSUFFIX"]
res_obj = env.RES(res_target, res_file)
Expand All @@ -54,7 +40,7 @@ env.add_source_files(sources, common_win)
sources += res_obj

prog = env.add_program("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"])
arrange_program_clean(prog)
env.arrange_program_clean(prog)

# Build console wrapper app.
if env["windows_subsystem"] == "gui":
Expand All @@ -71,7 +57,7 @@ if env["windows_subsystem"] == "gui":
env_wrap.Append(LIBS=["version"])

prog_wrap = env_wrap.add_program("#bin/godot", common_win_wrap + res_wrap_obj, PROGSUFFIX=env["PROGSUFFIX_WRAP"])
arrange_program_clean(prog_wrap)
env.arrange_program_clean(prog_wrap)
env_wrap.Depends(prog_wrap, prog)
sources += common_win_wrap + res_wrap_obj

Expand Down Expand Up @@ -138,10 +124,24 @@ if env["d3d12"]:
Copy("$TARGET", "$SOURCE"),
)


def make_debug_mingw(target, source, env):
src = str(target[0])
dst = f"{src[:-4]}.debugsymbols"
objcopy = env["OBJCOPY"]
strip = env["STRIP"]

# Force separate debug symbols if executable size is larger than 1.9 GB.
if env["separate_debug_symbols"] or os.stat(src).st_size >= 2040109465:
os.system(f"{objcopy} --only-keep-debug {src} {dst}")
os.system(f"{strip} --strip-debug --strip-unneeded {src}")
os.system(f"{objcopy} --add-gnu-debuglink={dst} {src}")


if not os.getenv("VCINSTALLDIR"):
if env["debug_symbols"]:
env.AddPostAction(prog, env.Run(platform_windows_builders.make_debug_mingw))
env.AddPostAction(prog, env.Run(make_debug_mingw))
if env["windows_subsystem"] == "gui":
env.AddPostAction(prog_wrap, env.Run(platform_windows_builders.make_debug_mingw))
env.AddPostAction(prog_wrap, env.Run(make_debug_mingw))

env.platform_sources += sources
Loading
Loading