Skip to content

Commit 88faf50

Browse files
committed
make a style check to ensure we update the hardcoded versions from time to time
1 parent 606ad64 commit 88faf50

File tree

6 files changed

+45
-36
lines changed

6 files changed

+45
-36
lines changed

graalpython/com.oracle.graal.python.test.integration/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Additionally, one can change the polyglot artifacts version with
6464
<maven.compiler.source>17</maven.compiler.source>
6565
<maven.compiler.target>17</maven.compiler.target>
6666
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
67-
<com.oracle.graal.python.test.polyglot.version>24.0.0</com.oracle.graal.python.test.polyglot.version>
67+
<com.oracle.graal.python.test.polyglot.version>24.1.0</com.oracle.graal.python.test.polyglot.version>
6868
</properties>
6969

7070
<build>

graalpython/graalpy-archetype-polyglot-app/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ SOFTWARE.
4444

4545
<groupId>org.graalvm.python</groupId>
4646
<artifactId>graalpy-archetype-polyglot-app</artifactId>
47+
<!-- This version is always overridden when deploying using mx -->
4748
<version>24.1.0</version>
4849
<url>http://www.graalvm.org/</url>
4950
<description>Maven archetype providing a skeleton GraalPy - Java polyglot application.</description>

graalpython/graalpy-jbang/templates/graalpy-template.java.qute

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
//DEPS {dep}
44
{/for}
55
{#if dependencies.isEmpty()}// //DEPS <dependency1> <dependency2>{/if}
6-
6+
{|
77
//DEPS org.graalvm.python:python-language:${env.GRAALPY_VERSION:24.0.0}
88
//DEPS org.graalvm.python:python-resources:${env.GRAALPY_VERSION:24.0.0}
99
//DEPS org.graalvm.python:python-launcher:${env.GRAALPY_VERSION:24.0.0}
1010
//DEPS org.graalvm.python:python-embedding:${env.GRAALPY_VERSION:24.0.0}
1111
//PIP termcolor
12-
12+
|}
1313
import org.graalvm.polyglot.Context;
1414
import org.graalvm.polyglot.PolyglotAccess;
1515
import org.graalvm.polyglot.PolyglotException;

graalpython/graalpy-jbang/templates/graalpy-template_local_repo.java.qute

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
//REPOS mc=https://repo1.maven.org/maven2/
88
//REPOS local=file://{path_to_local_repo}
9+
{|
910
//DEPS org.graalvm.python:python-language:${env.GRAALPY_VERSION:24.0.0}
1011
//DEPS org.graalvm.python:python-resources:${env.GRAALPY_VERSION:24.0.0}
1112
//DEPS org.graalvm.python:python-launcher:${env.GRAALPY_VERSION:24.0.0}
1213
//DEPS org.graalvm.python:python-embedding:${env.GRAALPY_VERSION:24.0.0}
1314
//PIP termcolor
14-
15+
|}
1516
import org.graalvm.polyglot.Context;
1617
import org.graalvm.polyglot.PolyglotAccess;
1718
import org.graalvm.polyglot.PolyglotException;

graalpython/graalpy-maven-plugin/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ SOFTWARE.
4747
<groupId>org.graalvm.python</groupId>
4848
<artifactId>graalpy-maven-plugin</artifactId>
4949
<packaging>maven-plugin</packaging>
50+
<!-- This version is always overridden when deploying using mx -->
5051
<version>24.1.0</version>
5152
<url>http://www.graalvm.org/</url>
5253
<name>graalpy-maven-plugin</name>
@@ -56,7 +57,7 @@ SOFTWARE.
5657
<maven.compiler.target>17</maven.compiler.target>
5758
<maven.compiler.source>17</maven.compiler.source>
5859
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
59-
<graalpy.version>24.0.0</graalpy.version>
60+
<graalpy.version>24.1.0</graalpy.version>
6061
</properties>
6162

6263
<profiles>

mx.graalpython/mx_graalpython.py

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ def get_boolean_env(name, default=False):
9797

9898
SUITE = mx.suite('graalpython')
9999
SUITE_COMPILER = mx.suite("compiler", fatalIfMissing=False)
100-
SUITE_SULONG = mx.suite("sulong")
100+
SUITE_TRUFFLE = mx.suite("truffle")
101101

102-
GRAAL_VERSION = SUITE.suiteDict['version']
102+
GRAAL_VERSION = SUITE_TRUFFLE.suiteDict['version']
103103
GRAAL_VERSION_MAJ_MIN = ".".join(GRAAL_VERSION.split(".")[:2])
104104
PYTHON_VERSION = SUITE.suiteDict[f'{SUITE.name}:pythonVersion']
105105
PYTHON_VERSION_MAJ_MIN = ".".join(PYTHON_VERSION.split('.')[:2])
@@ -2034,6 +2034,7 @@ def update_import_cmd(args):
20342034

20352035
def python_style_checks(args):
20362036
"Check (and fix where possible) copyrights, eclipse formatting, and spotbugs"
2037+
warn_about_old_hardcoded_version()
20372038
python_run_mx_filetests(args)
20382039
python_checkcopyrights(["--fix"] if "--fix" in args else [])
20392040
if not os.environ.get("ECLIPSE_EXE"):
@@ -2372,63 +2373,68 @@ def __closing__(self):
23722373
self.__services.pop('java.nio.charset.spi.CharsetProvider', None)
23732374

23742375

2375-
def mx_post_parse_cmd_line(namespace):
2376+
def warn_about_old_hardcoded_version():
23762377
"""
2377-
Ensure hardcoded versions everywhere match the suite version.
2378-
Fix and warn if they do not in CI, fail the build locally.
2378+
Ensure hardcoded versions everywhere are what we expect, either matching the master version
2379+
or one of the latest releases.
23792380
"""
2381+
graal_major = int(GRAAL_VERSION.split(".")[0])
2382+
graal_minor = int(GRAAL_VERSION.split(".")[1])
2383+
2384+
def hardcoded_ver_is_too_far_behind_master(m):
2385+
hardcoded_major = int(m.group(1).split(".")[0])
2386+
if hardcoded_major < graal_major:
2387+
if graal_minor > 0 or hardcoded_major < graal_minor - 1:
2388+
return f"Hardcoded version in `{m.group().strip()}` is too far behind {graal_major}.{graal_minor}. Update it to the latest released version."
2389+
2390+
def hardcoded_ver_is_behind_major_minor(m):
2391+
if m.group(1) != GRAAL_VERSION_MAJ_MIN:
2392+
return f"Hardcoded version in `{m.group().strip()}` should have {GRAAL_VERSION_MAJ_MIN} as <major>.<minor> version."
2393+
23802394
files_with_versions = {
23812395
"graalpython/graalpy-maven-plugin/pom.xml": {
2382-
r"^ <version>(\d+\.\d+(?:\.\d+)*)</version>": GRAAL_VERSION,
2383-
r"<graalpy.version>(\d+\.\d+(?:\.\d+)*)</graalpy.version>": GRAAL_VERSION,
2396+
r"^ <version>(\d+\.\d+)(?:\.\d+)*</version>" : hardcoded_ver_is_behind_major_minor,
2397+
r'<graalpy.version>(\d+\.\d+)(?:\.\d+)*</graalpy.version>' : hardcoded_ver_is_behind_major_minor
23842398
},
23852399
"graalpython/com.oracle.graal.python.test.integration/pom.xml": {
2386-
r"<com.oracle.graal.python.test.polyglot.version>(\d+\.\d+(?:\.\d+)*)</com.oracle.graal.python.test.polyglot.version>": GRAAL_VERSION,
2400+
r'<com.oracle.graal.python.test.polyglot.version>(\d+\.\d+)(?:\.\d+)*' : hardcoded_ver_is_behind_major_minor,
23872401
},
23882402
"graalpython/graalpy-archetype-polyglot-app/pom.xml": {
2389-
r"^ <version>(\d+\.\d+(?:\.\d+)*)</version>": GRAAL_VERSION,
2403+
r"^ <version>(\d+\.\d+)(?:\.\d+)*</version>" : hardcoded_ver_is_behind_major_minor,
23902404
},
23912405
"graalpython/graalpy-jbang/examples/hello.java": {
2392-
r"//DEPS org.graalvm.python:python[^:]*:(\d+\.\d+(?:\.\d+)*)": GRAAL_VERSION,
2406+
r"//DEPS org.graalvm.python:python[^:]*:\${env.GRAALPY_VERSION:(\d+\.\d+)(?:\.\d+)*" : hardcoded_ver_is_too_far_behind_master,
23932407
},
23942408
"graalpython/graalpy-jbang/templates/graalpy-template_local_repo.java.qute": {
2395-
r"//DEPS org.graalvm.python:python[^:]*:(\d+\.\d+(?:\.\d+)*)": GRAAL_VERSION,
2409+
r"//DEPS org.graalvm.python:python[^:]*:\${env.GRAALPY_VERSION:(\d+\.\d+)(?:\.\d+)*" : hardcoded_ver_is_too_far_behind_master,
23962410
},
23972411
"graalpython/graalpy-jbang/templates/graalpy-template.java.qute": {
2398-
r"//DEPS org.graalvm.python:python[^:]*:(\d+\.\d+(?:\.\d+)*)": GRAAL_VERSION,
2412+
r"//DEPS org.graalvm.python:python[^:]*:\${env.GRAALPY_VERSION:(\d+\.\d+)(?:\.\d+)*" : hardcoded_ver_is_too_far_behind_master,
23992413
},
24002414
"graalpython/graalpy-archetype-polyglot-app/src/main/resources/archetype-resources/pom.xml": {
2401-
r"<graalpy.version>(\d+\.\d+(?:\.\d+)*)</graalpy.version>": GRAAL_VERSION,
2402-
},
2403-
"graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java": {
2404-
r"GRAALVM_MAJOR = (\d+);" : GRAAL_VERSION.split(".")[0],
2405-
r"GRAALVM_MINOR = (\d+);" : GRAAL_VERSION.split(".")[1],
2415+
r'<graalpy.version>(\d+\.\d+)(?:\.\d+)*</graalpy.version>' : hardcoded_ver_is_behind_major_minor,
24062416
},
24072417
}
24082418
replacements = set()
24092419
for path, patterns in files_with_versions.items():
24102420
full_path = os.path.join(SUITE.dir, path)
24112421
with open(full_path, "r", encoding="utf-8") as f:
24122422
content = f.read()
2413-
has_replacement = False
2414-
for pattern, replacement in patterns.items():
2423+
for pattern, test in patterns.items():
24152424
pattern = re.compile(pattern, flags=re.M)
24162425
start = 0
24172426
while m := pattern.search(content, start):
2418-
group = m.group(1)
2419-
length_diff = len(replacement) - len(group)
24202427
mx.logvv(f"[{SUITE.name}] {path} with hardcoded version `{m.group()}'")
2421-
if group != replacement:
2422-
replacements.add(path)
2423-
has_replacement = True
2424-
content = content[:m.start(1)] + replacement + content[m.end(1):]
2425-
start = m.end() + length_diff
2426-
if has_replacement:
2427-
with open(full_path, "w", encoding="utf-8") as f:
2428-
f.write(content)
2429-
for replacement in replacements:
2430-
mx.warn(f"Updated Graal version in {replacement}, you should check this in!")
2428+
if msg := test(m):
2429+
replacements.add((path, msg))
2430+
start = m.end()
2431+
if replacements:
2432+
mx.abort("\n".join([
2433+
": ".join(r) for r in replacements
2434+
]))
2435+
24312436

2437+
def mx_post_parse_cmd_line(namespace):
24322438
# all projects are now available at this time
24332439
_register_vms(namespace)
24342440
_register_bench_suites(namespace)

0 commit comments

Comments
 (0)