Skip to content

Commit 0890e36

Browse files
committed
[GR-46465] Make it easy to add to create a debug builds of our native libs
PullRequest: graalpython/2804
2 parents 3feb308 + 91d8fc6 commit 0890e36

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import mx
5252
import mx_benchmark
5353
import mx_gate
54+
import mx_native
5455
import mx_unittest
5556
import mx_sdk
5657
import mx_subst
@@ -103,6 +104,15 @@ def is_collectiong_coverage():
103104
if os.environ.get("CI") == "true" and not os.environ.get("GRAALPYTEST_FAIL_FAST"):
104105
os.environ["GRAALPYTEST_FAIL_FAST"] = "true"
105106

107+
108+
def wants_debug_build(flags=os.environ.get("CFLAGS", "")):
109+
return any(x in flags for x in ["-g", "-ggdb", "-ggdb3"])
110+
111+
112+
if wants_debug_build():
113+
mx_native.DefaultNativeProject.cflags = property(lambda self: self._cflags + ["-fPIC", "-ggdb3"])
114+
115+
106116
def _sibling(filename):
107117
return os.path.join(os.path.dirname(__file__), filename)
108118

@@ -2447,14 +2457,20 @@ def run(self, args, env=None, cwd=None, **kwargs):
24472457
# besides keeping custom sysroot, since our toolchain forwards to the system headers
24482458
for var in ["CC", "CFLAGS", "LDFLAGS"]:
24492459
value = env.pop(var, None)
2450-
if value and "--sysroot" in value:
2451-
seen_sysroot = False
2452-
for element in shlex.split(value):
2453-
if element == "--sysroot":
2454-
seen_sysroot = True
2455-
elif seen_sysroot:
2456-
env[var] = f"--sysroot {element}"
2457-
break
2460+
new_value = []
2461+
if value:
2462+
if wants_debug_build(value):
2463+
new_value.append("-ggdb3")
2464+
if "--sysroot" in value:
2465+
seen_sysroot = False
2466+
for element in shlex.split(value):
2467+
if element == "--sysroot":
2468+
seen_sysroot = True
2469+
elif seen_sysroot:
2470+
new_value.append(f"--sysroot {element}")
2471+
break
2472+
if new_value:
2473+
env[var] = " ".join(new_value)
24582474
return super().run(args, env=env, cwd=cwd, **kwargs)
24592475

24602476
def _dev_headers_dir(self):

mx.graalpython/suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@
494494
"use_jdk_headers": True, # the generated JNI header includes jni.h
495495
"cflags": [
496496
"-DHPY_UNIVERSAL_ABI", "-DNDEBUG",
497-
"-g", "-O3", "-Werror",
497+
"-O3", "-Werror",
498498
"-I\"<path:com.oracle.graal.python.cext>/include\"",
499499
"-I\"<path:com.oracle.graal.python.cext>/include/internal\"",
500500
"-I\"<path:com.oracle.graal.python.cext>/src\"",

0 commit comments

Comments
 (0)