Skip to content

Commit 36c69ed

Browse files
committed
[GR-60173] Register custom module-info compilation participant for JDK builds without JMODs #10161.
PullRequest: graal/19464
2 parents 5ba5d7b + 7d964fa commit 36c69ed

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,19 @@ def mx_post_parse_cmd_line(opts):
11931193
for dist in suite.dists:
11941194
if dist.isJARDistribution():
11951195
dist.set_archiveparticipant(GraalArchiveParticipant(dist, isTest=dist.name.endswith('_TEST')))
1196+
# Compilation of module-info.java classes need upgrade-module path arguments to
1197+
# when javac is invoked. This is in particular needed when the base JDK includes no
1198+
# JMODs.
1199+
if opts.no_jlinking:
1200+
all_jar_dists = set()
1201+
for p in suite.projects_recursive():
1202+
if p.isJavaProject():
1203+
jd = p.get_declaring_module_distribution()
1204+
if jd:
1205+
all_jar_dists.add(jd)
1206+
for d in all_jar_dists:
1207+
d.add_module_info_compilation_participant(NoJlinkModuleInfoCompilationParticipant(d, "jdk.graal.compiler").__process__)
1208+
11961209

11971210
def native_image_context_run(func, func_args=None, config=None, build_if_missing=False):
11981211
func_args = [] if func_args is None else func_args
@@ -1877,6 +1890,33 @@ def checkLine(line, marker, init_kind, msg, wrongly_initialized_lines):
18771890

18781891
native_image_context_run(build_and_test_clinittest_image, args)
18791892

1893+
class NoJlinkModuleInfoCompilationParticipant:
1894+
1895+
def __init__(self, dist, module_name):
1896+
self.dist = dist
1897+
self.module_name = module_name
1898+
1899+
# Upgrade module path for compilation of module-info.java files when not using jmods from the JDK
1900+
def __process__(self, module_desc):
1901+
"""
1902+
:param module_desc: The JavaModuleDescriptor for this distribution
1903+
:rtype: list of strings with extra javac arguments
1904+
"""
1905+
def safe_path_arg(p):
1906+
r"""
1907+
Return `p` with all `\` characters replaced with `\\`, all spaces replaced
1908+
with `\ ` and the result enclosed in double quotes.
1909+
"""
1910+
return '"' + p.replace('\\', '\\\\').replace(' ', '\\ ') + '"'
1911+
graal_mod = None
1912+
for m in module_desc.modulepath:
1913+
if m.name == self.module_name:
1914+
graal_mod = m
1915+
break
1916+
if graal_mod:
1917+
return [ '--upgrade-module-path=' + safe_path_arg(graal_mod.jarpath) ]
1918+
return []
1919+
18801920

18811921
class SubstrateJvmFuncsFallbacksBuilder(mx.Project):
18821922
def __init__(self, suite, name, deps, workingSets, theLicense, **kwArgs):

0 commit comments

Comments
 (0)