4141from pathlib import Path
4242from textwrap import dedent
4343
44+ from typing import cast
45+
4446import mx_graalpython_benchmark
4547import mx_graalpython_gradleproject
4648import mx_urlrewrites
@@ -91,7 +93,7 @@ def get_boolean_env(name, default=False):
9193 return env .lower () in ('true' , '1' )
9294
9395
94- SUITE = mx .suite ('graalpython' )
96+ SUITE = cast ( mx .SourceSuite , mx . suite ('graalpython' ) )
9597SUITE_COMPILER = mx .suite ("compiler" , fatalIfMissing = False )
9698
9799GRAAL_VERSION = SUITE .suiteDict ['version' ]
@@ -1803,7 +1805,7 @@ def dev_tag(arg=None, **kwargs):
18031805mx_subst .results_substitutions .register_no_arg ('graalpy_ext' , graalpy_ext )
18041806
18051807
1806- def update_import (name , suite_py , args ):
1808+ def update_import (name , suite_py : Path , args ):
18071809 parent = os .path .join (SUITE .dir , ".." )
18081810 dep_dir = None
18091811 for dirpath , dirnames , _ in os .walk (parent ):
@@ -1815,12 +1817,10 @@ def update_import(name, suite_py, args):
18151817 if not dep_dir :
18161818 mx .warn ("could not find suite %s to update" % name )
18171819 return
1818- vc = mx .VC . get_vc (dep_dir )
1820+ vc = cast ( mx .VC , mx . VC . get_vc (dep_dir ) )
18191821 repo_name = os .path .basename (dep_dir )
18201822 if repo_name == "graal" and args .graal_rev :
18211823 rev = args .graal_rev
1822- elif repo_name == "graal-enterprise" and args .graal_enterprise_rev :
1823- rev = args .graal_enterprise_rev
18241824 elif args .no_pull :
18251825 rev = "HEAD"
18261826 else :
@@ -1838,7 +1838,7 @@ def update_import(name, suite_py, args):
18381838 start = dep_match .start (1 )
18391839 end = dep_match .end (1 )
18401840 assert end - start == len (tip )
1841- mx .update_file (suite_py , "" .join ([contents [:start ], tip , contents [end :]]), showDiff = True )
1841+ mx .update_file (suite_py . resolve (). as_posix () , "" .join ([contents [:start ], tip , contents [end :]]), showDiff = True )
18421842 return tip
18431843
18441844
@@ -1847,15 +1847,13 @@ def update_import_cmd(args):
18471847
18481848 parser = ArgumentParser ()
18491849 parser .add_argument ('--graal-rev' , default = '' )
1850- parser .add_argument ('--graal-enterprise-rev' , default = '' )
18511850 parser .add_argument ('--no-pull' , action = 'store_true' )
18521851 parser .add_argument ('--no-push' , action = 'store_true' )
18531852 parser .add_argument ('--allow-dirty' , action = 'store_true' )
18541853 parser .add_argument ('--no-master-check' , action = 'store_true' , help = "do not check if repos are on master branch (e.g., when detached)" )
18551854 args = parser .parse_args (args )
18561855
1857- join = os .path .join
1858- vc = SUITE .vc
1856+ vc = cast (mx .GitConfig , mx .VC .get_vc (SUITE .dir ))
18591857
18601858 current_branch = vc .active_branch (SUITE .dir , abortOnError = not args .no_master_check )
18611859 if vc .isDirty (SUITE .dir ) and not args .allow_dirty :
@@ -1864,121 +1862,38 @@ def update_import_cmd(args):
18641862 vc .git_command (SUITE .dir , ["checkout" , "-b" , f"update/GR-21590/{ datetime .datetime .now ().strftime ('%d%m%y' )} " ])
18651863 current_branch = vc .active_branch (SUITE .dir )
18661864
1867- local_names = ["graalpython" ]
1868- repos = [os .path .join (SUITE .dir , ".." , name ) for name in local_names ]
1869- suite_py_files = [os .path .join (SUITE .dir , ".." , name , f"mx.{ name } " , "suite.py" ) for name in local_names ]
1870- for suite_py in suite_py_files :
1871- assert os .path .isfile (suite_py ), f"Cannot find { suite_py } "
1872-
1873- # make sure all other repos are clean and on the same branch
1874- for d in repos :
1875- if vc .isDirty (d ) and not args .allow_dirty :
1876- mx .abort ("repo %s is not clean" % d )
1877- d_branch = vc .active_branch (d , abortOnError = not args .no_master_check )
1878- if d_branch == current_branch :
1879- pass
1880- elif args .no_master_check or d_branch == "master" :
1881- vc .set_branch (d , current_branch , with_remote = False )
1882- vc .git_command (d , ["checkout" , current_branch ], abortOnError = True )
1883- else :
1884- mx .abort ("repo %s is not on the main branch or on %s" % (d , current_branch ))
1885-
1886- # make sure we can update the overlays
1887- overlaydir = join (SUITE .dir , ".." , "ci-overlays" )
1888- if not os .path .exists (overlaydir ):
1889- mx .abort ("Overlays repo must be next to graalpython repo" )
1890- vc = mx .VC .get_vc (overlaydir )
1891- if vc .isDirty (overlaydir ) and not args .allow_dirty :
1892- mx .abort ("overlays repo must be clean" )
1893- overlaybranch = vc .active_branch (overlaydir , abortOnError = not args .no_master_check )
1894- if args .no_master_check or overlaybranch == "master" :
1895- if not args .no_pull :
1896- vc .pull (overlaydir )
1897- vc .set_branch (overlaydir , current_branch , with_remote = False )
1898- vc .git_command (overlaydir , ["checkout" , current_branch ], abortOnError = True )
1899- elif overlaybranch == current_branch :
1900- pass
1901- else :
1902- mx .abort ("overlays repo must be on the main branch or branch %s" % current_branch )
1865+ repo = Path (SUITE .dir )
1866+ truffle_repo = Path (cast (mx .SourceSuite , mx .suite ("truffle" )).dir ).parent
1867+ suite_py = Path (__file__ ).parent / "suite.py"
19031868
19041869 # find all imports we might update
19051870 imports_to_update = set ()
1906- for suite_py in suite_py_files :
1907- d = {}
1908- with open (suite_py ) as f :
1909- exec (f .read (), d , d ) # pylint: disable=exec-used;
1910- for suite in d ["suite" ].get ("imports" , {}).get ("suites" , []):
1911- import_name = suite ["name" ]
1912- if suite .get ("version" ) and import_name not in local_names and import_name != 'library-tester' :
1913- imports_to_update .add (import_name )
1871+ d = {}
1872+ with open (suite_py ) as f :
1873+ exec (f .read (), d , d ) # pylint: disable=exec-used;
1874+ for suite in d ["suite" ].get ("imports" , {}).get ("suites" , []):
1875+ imports_to_update .add (suite ["name" ])
19141876
19151877 revisions = {}
19161878 # now update all imports
19171879 for name in imports_to_update :
1918- for _ , suite_py in enumerate (suite_py_files ):
1919- revisions [name ] = update_import (name , suite_py , args )
1920-
1921- # copy files we inline from our imports
1922- shutil .copy (
1923- join (mx .suite ("truffle" ).dir , ".." , "common.json" ),
1924- join (overlaydir , "python" , "graal" , "common.json" ))
1925- shutil .copytree (
1926- join (mx .suite ("truffle" ).dir , ".." , "ci" ),
1927- join (overlaydir , "python" , "graal" , "ci" ),
1928- dirs_exist_ok = True )
1929-
1930- if not args .no_pull :
1931- run_mx (['--dynamicimports' , '/graal-enterprise' , 'checkout-downstream' , 'compiler' , 'graal-enterprise' ])
1932- enterprisedir = join (SUITE .dir , ".." , "graal-enterprise" )
1933- shutil .copy (
1934- join (enterprisedir , "common.json" ),
1935- join (overlaydir , "python" , "graal-enterprise" , "common.json" ))
1936- shutil .copytree (
1937- join (enterprisedir , "ci" ),
1938- join (overlaydir , "python" , "graal-enterprise" , "ci" ),
1939- dirs_exist_ok = True )
1940-
1941- repos_updated = []
1942-
1943- # now allow dependent repos to hook into update
1944- output = mx .OutputCapture ()
1945- for repo in repos :
1946- basename = os .path .basename (repo )
1947- cmdname = "%s-update-import" % basename
1948- is_mx_command = run_mx (["-p" , repo , "help" , cmdname ], out = output , err = output , nonZeroIsFatal = False , quiet = True ) == 0
1949- if is_mx_command :
1950- run_mx (["-p" , repo , cmdname , "--overlaydir=%s" % overlaydir ], suite = repo , nonZeroIsFatal = True )
1951- else :
1952- print (mx .colorize ('%s command for %s.. skipped!' % (cmdname , basename ), color = 'magenta' , bright = True , stream = sys .stdout ))
1953-
1954- # commit ci-overlays if dirty
1955- if vc .isDirty (overlaydir ):
1956- vc .commit (overlaydir , "Update Python imports" )
1957- repos_updated .append (overlaydir )
1958-
1959- overlaytip = str (vc .tip (overlaydir )).strip ()
1960-
1961- # update ci import in all our repos, commit the full update
1962- prev_verbosity = mx .get_opts ().very_verbose
1963- for repo in repos :
1964- jsonnetfile = os .path .join (repo , "ci.jsonnet" )
1965- with open (jsonnetfile , "w" ) as f :
1966- f .write ('{ "overlay": "%s" }\n ' % overlaytip )
1967- if vc .isDirty (repo ):
1968- vc .commit (repo , "Update imports" )
1969- repos_updated .append (repo )
1880+ revisions [name ] = update_import (name , suite_py , args )
19701881
1971- # push all repos
1972- if not args .no_push :
1973- for repo in repos_updated :
1974- try :
1975- mx .get_opts ().very_verbose = True
1976- vc .git_command (repo , ["push" , "-u" , "origin" , "HEAD:%s" % current_branch ], abortOnError = True )
1977- finally :
1978- mx .get_opts ().very_verbose = prev_verbosity
1882+ shutil .copy (truffle_repo / "common.json" , repo / "ci" / "graal" / "common.json" )
1883+ shutil .copytree (truffle_repo / "ci" , repo / "ci" / "graal" / "ci" , dirs_exist_ok = True )
19791884
1980- if repos_updated :
1981- mx .log ("\n " .join (["These repos were updated:" ] + repos_updated ))
1885+ if vc .isDirty (repo ):
1886+ prev_verbosity = mx .get_opts ().very_verbose
1887+ mx .get_opts ().very_verbose = True
1888+ try :
1889+ vc .commit (repo , "Update imports" )
1890+ if not args .no_push :
1891+ vc .git_command (repo , ["push" , "-u" , "origin" , "HEAD:%s" % current_branch ], abortOnError = True )
1892+ mx .log ("Import update was pushed" )
1893+ else :
1894+ mx .log ("Import update was committed" )
1895+ finally :
1896+ mx .get_opts ().very_verbose = prev_verbosity
19821897
19831898
19841899def python_style_checks (args ):
0 commit comments