Implement "get_mingw_tool" to fix mingw prefixes

• Replaces "try_cmd" entirely and removes need for "get_mingw_bin_prefix" in isolation
This commit is contained in:
Thaddeus Crews
2023-11-17 11:31:50 -06:00
parent 7cdad33311
commit ecebe0b40d
2 changed files with 54 additions and 80 deletions

View File

@ -1,24 +1,17 @@
"""Functions used to generate source files during build time"""
import os
from detect import get_mingw_bin_prefix
from detect import try_cmd
from detect import get_mingw_tool
def make_debug_mingw(target, source, env):
dst = str(target[0])
# Force separate debug symbols if executable size is larger than 1.9 GB.
if env["separate_debug_symbols"] or os.stat(dst).st_size >= 2040109465:
mingw_bin_prefix = get_mingw_bin_prefix(env["mingw_prefix"], env["arch"])
if try_cmd("objcopy --version", env["mingw_prefix"], env["arch"]):
os.system(mingw_bin_prefix + "objcopy --only-keep-debug {0} {0}.debugsymbols".format(dst))
else:
os.system("objcopy --only-keep-debug {0} {0}.debugsymbols".format(dst))
if try_cmd("strip --version", env["mingw_prefix"], env["arch"]):
os.system(mingw_bin_prefix + "strip --strip-debug --strip-unneeded {0}".format(dst))
else:
os.system("strip --strip-debug --strip-unneeded {0}".format(dst))
if try_cmd("objcopy --version", env["mingw_prefix"], env["arch"]):
os.system(mingw_bin_prefix + "objcopy --add-gnu-debuglink={0}.debugsymbols {0}".format(dst))
else:
os.system("objcopy --add-gnu-debuglink={0}.debugsymbols {0}".format(dst))
objcopy = get_mingw_tool("objcopy", env["mingw_prefix"], env["arch"])
strip = get_mingw_tool("strip", env["mingw_prefix"], env["arch"])
if not objcopy or not strip:
print('`separate_debug_symbols` requires both "objcopy" and "strip" to function.')
return
os.system("{0} --only-keep-debug {1} {1}.debugsymbols".format(objcopy, target[0]))
os.system("{0} --strip-debug --strip-unneeded {1}".format(strip, target[0]))
os.system("{0} --add-gnu-debuglink={1}.debugsymbols {1}".format(objcopy, target[0]))