From 5f9b918a48d4098d898f47b128588137983e7755 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Thu, 21 Nov 2024 16:12:48 +0100 Subject: [PATCH] Enable build support for JEP 493 enabled base JDKs --- common.json | 16 ++++++++-------- src/mx/_impl/mx.py | 6 ++++-- src/mx/_impl/mx_jardistribution.py | 12 ++++++++++++ src/mx/_impl/mx_javamodules.py | 17 +++++++++++++---- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/common.json b/common.json index c867b8da..d6c2a1b8 100644 --- a/common.json +++ b/common.json @@ -8,7 +8,7 @@ "COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet", "jdks": { - "galahad-jdk": {"name": "jpg-jdk", "version": "24", "build_id": "jdk-24+22-2651", "platformspecific": true, "extrabundles": ["static-libs"]}, + "galahad-jdk": {"name": "jpg-jdk", "version": "24", "build_id": "jdk-24+24-2950", "platformspecific": true, "extrabundles": ["static-libs"]}, "oraclejdk17": {"name": "jpg-jdk", "version": "17.0.7", "build_id": "jdk-17.0.7+8", "platformspecific": true, "extrabundles": ["static-libs"]}, "labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.7+4-jvmci-23.1-b02", "platformspecific": true }, @@ -45,13 +45,13 @@ "oraclejdk23": {"name": "jpg-jdk", "version": "23", "build_id": "jdk-23+37", "platformspecific": true, "extrabundles": ["static-libs"]}, - "oraclejdk-latest": {"name": "jpg-jdk", "version": "24", "build_id": "jdk-24+22", "platformspecific": true, "extrabundles": ["static-libs"]}, - "labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-24+22-jvmci-b01", "platformspecific": true }, - "labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-24+22-jvmci-b01-debug", "platformspecific": true }, - "labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-24+22-jvmci-b01-sulong", "platformspecific": true }, - "labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-24+22-jvmci-b01", "platformspecific": true }, - "labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-24+22-jvmci-b01-debug", "platformspecific": true }, - "labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-24+22-jvmci-b01-sulong", "platformspecific": true } + "oraclejdk-latest": {"name": "jpg-jdk", "version": "24", "build_id": "jdk-24+24", "platformspecific": true, "extrabundles": ["static-libs"]}, + "labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-24+24-jvmci-b01", "platformspecific": true }, + "labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-24+24-jvmci-b01-debug", "platformspecific": true }, + "labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-24+24-jvmci-b01-sulong", "platformspecific": true }, + "labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-24+24-jvmci-b01", "platformspecific": true }, + "labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-24+24-jvmci-b01-debug", "platformspecific": true }, + "labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-24+24-jvmci-b01-sulong", "platformspecific": true } }, "eclipse": { diff --git a/src/mx/_impl/mx.py b/src/mx/_impl/mx.py index c64875f0..f68c9c21 100755 --- a/src/mx/_impl/mx.py +++ b/src/mx/_impl/mx.py @@ -849,7 +849,9 @@ def __init__(self, parents=None): # TODO GR-49766 completely remove this line and usages of `mx_tests` # self.add_argument('--mx-tests', action='store_true', help='load mxtests suite (mx debugging)') self.add_argument('--jdk', action='store', help='JDK to use for the "java" command', metavar='') - self.add_argument('--jmods-dir', action='store', help='path to built jmods (default JAVA_HOME/jmods)', metavar='') + self.add_argument('--jmods-dir', action='store', help="path to directory containing jmods which are added to --module-path when compiling " + "module-info.java for a distribution's module. The default is JAVA_HOME/jmods. Specify NO_JMODS to indicate " + "JAVA_HOME is a JEP 493-enabled JDK (i.e. has no jmods).", metavar='') self.add_argument('--version-conflict-resolution', dest='version_conflict_resolution', action='store', help='resolution mechanism used when a suite is imported with different versions', default='suite', choices=['suite', 'none', 'latest', 'latest_all', 'ignore']) self.add_argument('-c', '--max-cpus', action='store', type=int, dest='cpu_count', help='the maximum number of cpus to use during build', metavar='', default=None) self.add_argument('--proguard-cp', action='store', help='class path containing ProGuard jars to be used instead of default versions') @@ -18222,7 +18224,7 @@ def alarm_handler(signum, frame): _CACHE_DIR = get_env('MX_CACHE_DIR', join(dot_mx_dir(), 'cache')) # The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue -version = VersionSpec("7.35.0") # [GR-59726] Fix use of internal xml function changed in Python 3.13+ +version = VersionSpec("7.35.1") # [GR-60117] Enable build support for JEP 493 enabled base JDKs _mx_start_datetime = datetime.utcnow() diff --git a/src/mx/_impl/mx_jardistribution.py b/src/mx/_impl/mx_jardistribution.py index 3dc86bb8..a0a59a4e 100644 --- a/src/mx/_impl/mx_jardistribution.py +++ b/src/mx/_impl/mx_jardistribution.py @@ -98,6 +98,7 @@ def __init__(self, suite, name, subDir, path, sourcesPath, deps, mainClass, excl else: self._sources_path = '' + self.module_info_compilation_participants = [] self.archiveparticipants = [] self.mainClass = mainClass self.javaCompliance = mx.JavaCompliance(javaCompliance) if javaCompliance else None @@ -285,6 +286,17 @@ def set_archiveparticipant(self, archiveparticipant): def origin(self): return mx.Dependency.origin(self) + def add_module_info_compilation_participant(self, participant): + """ + Adds a callable that can add javac args when compiling ``module-info.java`` + for the Java module derived from this distribution. + + :param participant: a callable that takes a JavaModuleDescriptor (describing this + distribution's Java module) and returns a list of + args to be added to javac when compiling ``module-info.java`` + """ + self.module_info_compilation_participants.append(participant) + def classpath_repr(self, resolve=True): if resolve and not exists(self.path): if exists(self.original_path()): diff --git a/src/mx/_impl/mx_javamodules.py b/src/mx/_impl/mx_javamodules.py index 4d95eda3..0ab982ff 100644 --- a/src/mx/_impl/mx_javamodules.py +++ b/src/mx/_impl/mx_javamodules.py @@ -1085,14 +1085,18 @@ def safe_path_arg(p): # The --system=none and --limit-modules options are used to support distribution defined modules # that override non-upgradeable modules in the source JDK (e.g. org.graalvm.sdk is part of a # GraalVM JDK). This means --module-path needs to contain the jmods for the JDK modules. - javac_args.append('--system=none') + use_jmods = not (mx.get_opts().jmods_dir and mx.get_opts().jmods_dir == 'NO_JMODS') + if use_jmods: + javac_args.append('--system=none') if requires_clean: javac_args.append('--limit-modules=' + ','.join(requires_clean.keys())) jdk_jmods = (mx.get_opts().jmods_dir or join(jdk.home, 'jmods')) - if not exists(jdk_jmods): + if use_jmods and not exists(jdk_jmods): mx.abort('Missing directory containing JMOD files: ' + jdk_jmods) - modulepath_jars.extend((join(jdk_jmods, m) for m in os.listdir(jdk_jmods) if m.endswith('.jmod'))) - javac_args.append('--module-path=' + safe_path_arg(os.pathsep.join(modulepath_jars))) + if use_jmods: + modulepath_jars.extend((join(jdk_jmods, m) for m in os.listdir(jdk_jmods) if m.endswith('.jmod'))) + if modulepath_jars: + javac_args.append('--module-path=' + safe_path_arg(os.pathsep.join(modulepath_jars))) if concealedRequires: for module, packages in concealedRequires.items(): @@ -1105,6 +1109,11 @@ def safe_path_arg(p): # modules in qualified exports (not sure how to avoid these since we build modules # separately). javac_args.append('-Xlint:-options,-module') + + # Apply module-info compilation participants + for part in dist.module_info_compilation_participants: + javac_args.extend(part(jmd)) + javac_args.append(safe_path_arg(module_info_java)) # Convert javac args to @args file