Skip to content

Commit

Permalink
Register custom javac arg processor for JDK builds without JMODs
Browse files Browse the repository at this point in the history
With JEP 493, part of JDK 24, it's possible to have JDK builds without
the `jmods` folder. Currently substratevm builds assume `jmods` are
always present. This patch adds an extension to mx so as to produce
custom javac args when specific substratevm dependencies get compiled.

All of this is activated only when `--no-jlinking` option is being
used.

This patch depends on (which adds the needed abstractions to mx):
graalvm/mx#287
  • Loading branch information
jerboaa committed Nov 26, 2024
1 parent d79ab18 commit ba73706
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,19 @@ def mx_post_parse_cmd_line(opts):
for dist in suite.dists:
if dist.isJARDistribution():
dist.set_archiveparticipant(GraalArchiveParticipant(dist, isTest=dist.name.endswith('_TEST')))
# Compilation of module-info.java classes need upgrade-module path arguments to
# when javac is invoked. This is in particular needed when the base JDK includes no
# JMODs.
if opts.no_jlinking:
all_jar_dists = set()
for p in suite.projects_recursive():
if p.isJavaProject():
jd = p.get_declaring_module_distribution()
if jd:
all_jar_dists.add(jd)
for d in all_jar_dists:
d.add_module_info_compilation_participant(NoJlinkModuleInfoCompilationParticipant(d, "jdk.graal.compiler").__process__)


def native_image_context_run(func, func_args=None, config=None, build_if_missing=False):
func_args = [] if func_args is None else func_args
Expand Down Expand Up @@ -1877,6 +1890,35 @@ def checkLine(line, marker, init_kind, msg, wrongly_initialized_lines):

native_image_context_run(build_and_test_clinittest_image, args)

class NoJlinkModuleInfoCompilationParticipant:

def __init__(self, dist, module_name):
self.dist = dist
self.module_name = module_name

# Upgrade module path for compilation of module-info.java files when not using jmods from the JDK
def __process__(self, module_desc):
"""
:param module_desc: The JavaModuleDescriptor for this distribution
:rtype: list of strings with extra javac arguments
"""
has_module_dep = False
graal_mod = None
for m in module_desc.modulepath:
if m.name == self.module_name:
has_module_dep = True
graal_mod = m
break
if has_module_dep:
return [ '--upgrade-module-path=' + self.safe_path_arg(graal_mod.jarpath) ]
return []

def safe_path_arg(self, p):
r"""
Return `p` with all `\` characters replaced with `\\`, all spaces replaced
with `\ ` and the result enclosed in double quotes.
"""
return '"' + p.replace('\\', '\\\\').replace(' ', '\\ ') + '"'

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

0 comments on commit ba73706

Please sign in to comment.