Skip to content

Commit 8ef2508

Browse files
committed
[GR-60387] Fix mx jvmci-version-check --as-tag for LTS versions.
PullRequest: graal/19633
2 parents aa5db3f + 11699ba commit 8ef2508

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

compiler/mx.compiler/mx_compiler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ def _capture_jvmci_version(args=None):
182182
if out.data:
183183
try:
184184
(jdk_version, jvmci_major, jvmci_minor, jvmci_build) = out.data.split(',')
185-
if jdk_version.endswith('-LTS'):
186-
jdk_version = jdk_version[:-len('-LTS')]
187185
return JVMCIVersionCheckVersion(JavaLangRuntimeVersion(jdk_version), int(jvmci_major), int(jvmci_minor), int(jvmci_build))
188186
except ValueError:
189187
mx.warn(f'Could not parse jvmci version from JVMCIVersionCheck output:\n{out.data}')
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package jdk.graal.compiler.hotspot.test;
26+
27+
import jdk.graal.compiler.core.test.GraalCompilerTest;
28+
import jdk.graal.compiler.hotspot.JVMCIVersionCheck;
29+
import org.junit.Assert;
30+
import org.junit.Test;
31+
32+
/**
33+
* Tests that {@link JVMCIVersionCheck} can strip the -LTS suffix.
34+
*/
35+
public class JVMCIVersionCheckLTSTest extends GraalCompilerTest {
36+
37+
private static void expect(String jdkVersionString, String expected) {
38+
JVMCIVersionCheck.Version version = JVMCIVersionCheck.createLabsJDKVersion(jdkVersionString, 1);
39+
Assert.assertEquals(expected, version.stripLTS().toString());
40+
}
41+
42+
@Test
43+
public void test() {
44+
expect("24+17", "24+17-jvmci-b01");
45+
expect("25+1", "25+1-jvmci-b01");
46+
expect("25+1-LTS", "25+1-jvmci-b01");
47+
}
48+
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/JVMCIVersionCheck.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ public String printFormat(PrintFormat format) {
225225
case AS_TAG -> toString();
226226
};
227227
}
228+
229+
public Version stripLTS() {
230+
if ("LTS".equals(jdkVersion.optional().orElse(null))) {
231+
String version = jdkVersion.toString();
232+
assert version.endsWith("-LTS");
233+
String stripped = version.substring(0, version.length() - 4);
234+
return new Version(stripped, jvmciMajor, jvmciMinor, jvmciBuild, legacy, isOpenJDK);
235+
} else {
236+
return this;
237+
}
238+
}
228239
}
229240

230241
public static final String OPEN_LABSJDK_RELEASE_URL_PATTERN = "https://github.com/graalvm/labs-openjdk-*/releases";
@@ -369,7 +380,7 @@ private String run(Version minVersion, PrintFormat format) {
369380
Version v = Version.parse(vmVersion);
370381
if (v != null) {
371382
if (format != null) {
372-
System.out.println(v.printFormat(format));
383+
System.out.println(v.stripLTS().printFormat(format));
373384
}
374385
if (v.isLessThan(minVersion)) {
375386
return String.format("The VM does not support the minimum JVMCI API version required by Graal: %s < %s.", v, minVersion);

0 commit comments

Comments
 (0)