@@ -97,9 +97,9 @@ def get_boolean_env(name, default=False):
9797
9898SUITE = mx .suite ('graalpython' )
9999SUITE_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' ]
103103GRAAL_VERSION_MAJ_MIN = "." .join (GRAAL_VERSION .split ("." )[:2 ])
104104PYTHON_VERSION = SUITE .suiteDict [f'{ SUITE .name } :pythonVersion' ]
105105PYTHON_VERSION_MAJ_MIN = "." .join (PYTHON_VERSION .split ('.' )[:2 ])
@@ -2034,6 +2034,7 @@ def update_import_cmd(args):
20342034
20352035def 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