Skip to content

Commit a2d2fd1

Browse files
committed
Use version from PythonLanguage in __graalpython__.get_graalvm_version()
1 parent c52bcdf commit a2d2fd1

File tree

4 files changed

+61
-33
lines changed

4 files changed

+61
-33
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,21 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
183183
public static final int MICRO = 7;
184184
public static final int RELEASE_LEVEL_ALPHA = 0xA;
185185
public static final int RELEASE_LEVEL_BETA = 0xB;
186-
public static final int RELEASE_LEVEL_GAMMA = 0xC;
186+
public static final int RELEASE_LEVEL_CANDIDATE = 0xC;
187187
public static final int RELEASE_LEVEL_FINAL = 0xF;
188-
public static final int RELEASE_LEVEL = RELEASE_LEVEL_ALPHA;
188+
public static final int RELEASE_LEVEL;
189189
public static final TruffleString RELEASE_LEVEL_STRING;
190190
public static final String FROZEN_FILENAME_PREFIX = "<frozen ";
191191
public static final String FROZEN_FILENAME_SUFFIX = ">";
192192

193193
/**
194194
* GraalVM version. Unfortunately, we cannot just use {@link Version#getCurrent} as it relies on
195-
* a GraalVM build, but we may run from Jar files directly during development. We generate the
196-
* version during the build that are checked against these constants.
195+
* a GraalVM build, but we may run outside GraalVM. We generate the version during the build
196+
* that are checked against these constants.
197197
*/
198198
public static final int GRAALVM_MAJOR;
199199
public static final int GRAALVM_MINOR;
200+
public static final int GRAALVM_MICRO;
200201
public static final String DEV_TAG;
201202

202203
/**
@@ -207,21 +208,6 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
207208
private static final int VERSION_BASE = '!';
208209

209210
static {
210-
switch (RELEASE_LEVEL) {
211-
case RELEASE_LEVEL_ALPHA:
212-
RELEASE_LEVEL_STRING = tsLiteral("alpha");
213-
break;
214-
case RELEASE_LEVEL_BETA:
215-
RELEASE_LEVEL_STRING = tsLiteral("beta");
216-
break;
217-
case RELEASE_LEVEL_GAMMA:
218-
RELEASE_LEVEL_STRING = tsLiteral("rc");
219-
break;
220-
case RELEASE_LEVEL_FINAL:
221-
default:
222-
RELEASE_LEVEL_STRING = tsLiteral("final");
223-
}
224-
225211
// The resource file is built by mx from "graalpy-versions" project using mx substitutions.
226212
// The actual values of the versions are computed by mx helper functions py_version_short,
227213
// graal_version_short, and dev_tag defined in mx_graalpython.py
@@ -238,7 +224,22 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
238224
}
239225
GRAALVM_MAJOR = is.read() - VERSION_BASE;
240226
GRAALVM_MINOR = is.read() - VERSION_BASE;
241-
is.read(); // skip GraalVM micro version
227+
GRAALVM_MICRO = is.read() - VERSION_BASE;
228+
RELEASE_LEVEL = is.read() - VERSION_BASE;
229+
switch (RELEASE_LEVEL) {
230+
case RELEASE_LEVEL_ALPHA:
231+
RELEASE_LEVEL_STRING = tsLiteral("alpha");
232+
break;
233+
case RELEASE_LEVEL_BETA:
234+
RELEASE_LEVEL_STRING = tsLiteral("beta");
235+
break;
236+
case RELEASE_LEVEL_CANDIDATE:
237+
RELEASE_LEVEL_STRING = tsLiteral("candidate");
238+
break;
239+
case RELEASE_LEVEL_FINAL:
240+
default:
241+
RELEASE_LEVEL_STRING = tsLiteral("final");
242+
}
242243
// see mx.graalpython/mx_graalpython.py:dev_tag
243244
byte[] rev = new byte[3 /* 'dev' */ + 10 /* revision */];
244245
if (is.read(rev) == rev.length) {
@@ -254,7 +255,7 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
254255
public static final int VERSION_HEX = MAJOR << 24 |
255256
MINOR << 16 |
256257
MICRO << 8 |
257-
RELEASE_LEVEL_ALPHA << 4 |
258+
RELEASE_LEVEL << 4 |
258259
RELEASE_SERIAL;
259260
public static final String VERSION = MAJOR + "." + MINOR + "." + MICRO;
260261
// Rarely updated version of the C API, we should take it from the imported CPython version

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules;
4242

43+
import static com.oracle.graal.python.PythonLanguage.GRAALVM_MAJOR;
44+
import static com.oracle.graal.python.PythonLanguage.GRAALVM_MICRO;
45+
import static com.oracle.graal.python.PythonLanguage.GRAALVM_MINOR;
4346
import static com.oracle.graal.python.PythonLanguage.J_GRAALPYTHON_ID;
47+
import static com.oracle.graal.python.PythonLanguage.RELEASE_LEVEL;
48+
import static com.oracle.graal.python.PythonLanguage.RELEASE_LEVEL_FINAL;
4449
import static com.oracle.graal.python.nodes.BuiltinNames.J_EXTEND;
4550
import static com.oracle.graal.python.nodes.BuiltinNames.J___GRAALPYTHON__;
4651
import static com.oracle.graal.python.nodes.BuiltinNames.T_SHA3;
@@ -78,11 +83,6 @@
7883
import java.util.List;
7984
import java.util.logging.Level;
8085

81-
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
82-
import com.oracle.truffle.api.interop.TruffleObject;
83-
import com.oracle.truffle.api.library.ExportLibrary;
84-
import com.oracle.truffle.api.library.ExportMessage;
85-
import org.graalvm.home.Version;
8686
import org.graalvm.nativeimage.ImageInfo;
8787

8888
import com.oracle.graal.python.PythonLanguage;
@@ -185,9 +185,13 @@
185185
import com.oracle.truffle.api.dsl.TypeSystemReference;
186186
import com.oracle.truffle.api.frame.VirtualFrame;
187187
import com.oracle.truffle.api.interop.InteropLibrary;
188+
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
189+
import com.oracle.truffle.api.interop.TruffleObject;
188190
import com.oracle.truffle.api.interop.UnknownIdentifierException;
189191
import com.oracle.truffle.api.interop.UnsupportedMessageException;
190192
import com.oracle.truffle.api.library.CachedLibrary;
193+
import com.oracle.truffle.api.library.ExportLibrary;
194+
import com.oracle.truffle.api.library.ExportMessage;
191195
import com.oracle.truffle.api.nodes.LanguageInfo;
192196
import com.oracle.truffle.api.nodes.Node;
193197
import com.oracle.truffle.api.nodes.NodeUtil;
@@ -1056,11 +1060,18 @@ static PythonClass createType(VirtualFrame frame, TruffleString name, PTuple bas
10561060
@Builtin(name = "get_graalvm_version", minNumOfPositionalArgs = 0)
10571061
@GenerateNodeFactory
10581062
abstract static class GetGraalVmVersion extends PythonBuiltinNode {
1059-
@TruffleBoundary
1063+
private static final TruffleString VERSION_STRING;
1064+
static {
1065+
String version = String.format("%d.%d.%d", GRAALVM_MAJOR, GRAALVM_MINOR, GRAALVM_MICRO);
1066+
if (RELEASE_LEVEL != RELEASE_LEVEL_FINAL) {
1067+
version += "-dev";
1068+
}
1069+
VERSION_STRING = TruffleString.fromJavaStringUncached(version, TS_ENCODING);
1070+
}
1071+
10601072
@Specialization
10611073
TruffleString get() {
1062-
Version current = Version.getCurrent();
1063-
return TruffleString.fromJavaStringUncached(current.toString(), TS_ENCODING);
1074+
return VERSION_STRING;
10641075
}
10651076
}
10661077

mx.graalpython/mx_graalpython.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,14 +1959,29 @@ def graal_version_short(variant=None, **kwargs):
19591959
if variant == 'major_minor_nodot':
19601960
return GRAAL_VERSION_MAJ_MIN.replace(".", "")
19611961
elif variant == 'binary':
1962-
# PythonLanguage and PythonResource consume this data, and they assume 3 components
1963-
# (although the 3rd is not used), so we cap the list size to 3 although the version
1964-
# may have even more components
1962+
# PythonLanguage and PythonResource consume this data, and they assume 3 components, so we cap the list size
1963+
# to 3 although the version may have even more components
19651964
return "".join([chr(int(p) + ord(VERSION_BASE)) for p in GRAAL_VERSION.split(".")[:3]])
19661965
else:
19671966
return GRAAL_VERSION_MAJ_MIN
19681967

19691968

1969+
def release_level(variant=None):
1970+
# CPython has alpha, beta, candidate and final. We distinguish just two at the moment
1971+
level = 'alpha'
1972+
if SUITE.suiteDict['release']:
1973+
level = 'final'
1974+
if variant == 'binary':
1975+
level_num = {
1976+
'alpha': 0xA,
1977+
'beta': 0xB,
1978+
'candidate': 0xC,
1979+
'final': 0xF,
1980+
}[level]
1981+
return chr(level_num + ord(VERSION_BASE))
1982+
return level
1983+
1984+
19701985
def graalpy_ext(llvm_mode, **kwargs):
19711986
if not llvm_mode:
19721987
mx.abort("substitution 'graalpy_ext' is missing argument 'llvm_mode'")
@@ -2016,6 +2031,7 @@ def dev_tag(arg=None, **kwargs):
20162031
mx_subst.path_substitutions.register_with_arg('output_root', _get_output_root)
20172032
mx_subst.path_substitutions.register_with_arg('py_ver', py_version_short)
20182033
mx_subst.path_substitutions.register_with_arg('graal_ver', graal_version_short)
2034+
mx_subst.path_substitutions.register_with_arg('release_level', release_level)
20192035
mx_subst.results_substitutions.register_with_arg('dev_tag', dev_tag)
20202036

20212037
mx_subst.path_substitutions.register_with_arg('graalpy_ext', graalpy_ext)

mx.graalpython/suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@
658658
"max_jobs": "1",
659659
"ninja_targets": ["all"],
660660
"cmakeConfig": {
661-
"GRAALPY_VER": "<py_ver:binary><graal_ver:binary><dev_tag:none>",
661+
"GRAALPY_VER": "<py_ver:binary><graal_ver:binary><release_level:binary><dev_tag:none>",
662662
},
663663
"results": [
664664
"graalpy_versions"

0 commit comments

Comments
 (0)