Skip to content

Commit 7fe91bd

Browse files
committed
Pass jacoco arguments via a temporary launcher
1 parent 5acaa95 commit 7fe91bd

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import platform
3434
import re
3535
import shutil
36+
import shlex
3637
import sys
3738

3839
PY3 = sys.version_info[0] == 3 # compatibility between Python versions
@@ -514,19 +515,22 @@ def is_included(path):
514515

515516
args += [_graalpytest_driver(), "-v"]
516517

517-
agent_args = " ".join(mx_gate.get_jacoco_agent_args() or [])
518+
agent_args = mx_gate.get_jacoco_agent_args()
518519
if agent_args:
519-
# if we leave the excludes, the string is too long and it will be ignored by
520-
# the JVM, which ignores JAVA_TOOL_OPTIONS long than 1024 chars silently on JDK8
521-
agent_args = re.sub("excludes=[^,]+,", "", agent_args)
522-
# we know these can be excluded
523-
agent_args += ",excludes=*NodeGen*:*LibraryGen*:*BuiltinsFactory*"
524-
assert len(agent_args) < 1024
520+
# We need to make sure the arguments get passed to subprocesses, so we create a temporary launcher
521+
# with the arguments
522+
new_launcher_path = os.path.join(os.path.dirname(os.path.realpath(python_binary)), 'graalpython-jacoco')
523+
with open(python_binary, 'r', encoding='ascii', errors='ignore') as old_launcher:
524+
lines = old_launcher.readlines()
525+
assert re.match(r'^#!.*bash', lines[0]), "jacoco needs a bash launcher"
526+
lines.insert(-1, f'jvm_args+=({shlex.join(agent_args)})\n')
527+
with open(new_launcher_path, 'w') as new_launcher:
528+
new_launcher.writelines(lines)
529+
os.chmod(new_launcher_path, 0o755)
525530
# jacoco only dumps the data on exit, and when we run all our unittests
526531
# at once it generates so much data we run out of heap space
527-
env['JAVA_TOOL_OPTIONS'] = agent_args
528532
for testfile in testfiles:
529-
mx.run([python_binary] + args + [testfile], nonZeroIsFatal=True, env=env)
533+
mx.run([new_launcher_path] + args + [testfile], nonZeroIsFatal=True, env=env)
530534
else:
531535
args += testfiles
532536
mx.logv(" ".join([python_binary] + args))

0 commit comments

Comments
 (0)