@@ -97,9 +97,9 @@ def get_boolean_env(name, default=False):
97
97
98
98
SUITE = mx .suite ('graalpython' )
99
99
SUITE_COMPILER = mx .suite ("compiler" , fatalIfMissing = False )
100
- SUITE_SULONG = mx .suite ("sulong " )
100
+ SUITE_TRUFFLE = mx .suite ("truffle " )
101
101
102
- GRAAL_VERSION = SUITE .suiteDict ['version' ]
102
+ GRAAL_VERSION = SUITE_TRUFFLE .suiteDict ['version' ]
103
103
GRAAL_VERSION_MAJ_MIN = "." .join (GRAAL_VERSION .split ("." )[:2 ])
104
104
PYTHON_VERSION = SUITE .suiteDict [f'{ SUITE .name } :pythonVersion' ]
105
105
PYTHON_VERSION_MAJ_MIN = "." .join (PYTHON_VERSION .split ('.' )[:2 ])
@@ -2034,6 +2034,7 @@ def update_import_cmd(args):
2034
2034
2035
2035
def python_style_checks (args ):
2036
2036
"Check (and fix where possible) copyrights, eclipse formatting, and spotbugs"
2037
+ warn_about_old_hardcoded_version ()
2037
2038
python_run_mx_filetests (args )
2038
2039
python_checkcopyrights (["--fix" ] if "--fix" in args else [])
2039
2040
if not os .environ .get ("ECLIPSE_EXE" ):
@@ -2372,63 +2373,68 @@ def __closing__(self):
2372
2373
self .__services .pop ('java.nio.charset.spi.CharsetProvider' , None )
2373
2374
2374
2375
2375
- def mx_post_parse_cmd_line ( namespace ):
2376
+ def warn_about_old_hardcoded_version ( ):
2376
2377
"""
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 .
2379
2380
"""
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
+
2380
2394
files_with_versions = {
2381
2395
"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
2384
2398
},
2385
2399
"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 ,
2387
2401
},
2388
2402
"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 ,
2390
2404
},
2391
2405
"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 ,
2393
2407
},
2394
2408
"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 ,
2396
2410
},
2397
2411
"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 ,
2399
2413
},
2400
2414
"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 ,
2406
2416
},
2407
2417
}
2408
2418
replacements = set ()
2409
2419
for path , patterns in files_with_versions .items ():
2410
2420
full_path = os .path .join (SUITE .dir , path )
2411
2421
with open (full_path , "r" , encoding = "utf-8" ) as f :
2412
2422
content = f .read ()
2413
- has_replacement = False
2414
- for pattern , replacement in patterns .items ():
2423
+ for pattern , test in patterns .items ():
2415
2424
pattern = re .compile (pattern , flags = re .M )
2416
2425
start = 0
2417
2426
while m := pattern .search (content , start ):
2418
- group = m .group (1 )
2419
- length_diff = len (replacement ) - len (group )
2420
2427
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
+
2431
2436
2437
+ def mx_post_parse_cmd_line (namespace ):
2432
2438
# all projects are now available at this time
2433
2439
_register_vms (namespace )
2434
2440
_register_bench_suites (namespace )
0 commit comments