From 31747c15ccbc98bd9aa5e013a88975a8ef7272e7 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Mon, 25 Nov 2024 21:31:58 +0100 Subject: [PATCH 1/2] Register custom javac arg processor for JDK builds without JMODs 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): https://github.com/graalvm/mx/pull/287 --- substratevm/mx.substratevm/mx_substratevm.py | 40 ++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index d36e4d5d043c..2c64c06ddca6 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -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 @@ -1877,6 +1890,33 @@ 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 + """ + def safe_path_arg(p): + r""" + Return `p` with all `\` characters replaced with `\\`, all spaces replaced + with `\ ` and the result enclosed in double quotes. + """ + return '"' + p.replace('\\', '\\\\').replace(' ', '\\ ') + '"' + graal_mod = None + for m in module_desc.modulepath: + if m.name == self.module_name: + graal_mod = m + break + if graal_mod: + return [ '--upgrade-module-path=' + safe_path_arg(graal_mod.jarpath) ] + return [] + class SubstrateJvmFuncsFallbacksBuilder(mx.Project): def __init__(self, suite, name, deps, workingSets, theLicense, **kwArgs): From b72ef9810296756006a02949fc9288752f8bdef8 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Wed, 27 Nov 2024 13:20:42 +0100 Subject: [PATCH 2/2] Bump to mx version 7.35.1 which has the required dependency --- common.json | 2 +- substratevm/mx.substratevm/suite.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common.json b/common.json index d6c2a1b88528..a7b9d457b02b 100644 --- a/common.json +++ b/common.json @@ -4,7 +4,7 @@ "Jsonnet files should not include this file directly but use ci/common.jsonnet instead." ], - "mx_version": "7.34.1", + "mx_version": "7.35.1", "COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet", "jdks": { diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 73a8eb0b4e38..cb3a6d52efa2 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -1,6 +1,6 @@ # pylint: disable=line-too-long suite = { - "mxversion": "7.33.1", + "mxversion": "7.35.1", "name": "substratevm", "version" : "24.2.0", "release" : False,