41
41
from pathlib import Path
42
42
from textwrap import dedent
43
43
44
+ from typing import cast
45
+
44
46
import mx_graalpython_benchmark
45
47
import mx_graalpython_gradleproject
46
48
import mx_urlrewrites
@@ -91,7 +93,7 @@ def get_boolean_env(name, default=False):
91
93
return env .lower () in ('true' , '1' )
92
94
93
95
94
- SUITE = mx .suite ('graalpython' )
96
+ SUITE = cast ( mx .SourceSuite , mx . suite ('graalpython' ) )
95
97
SUITE_COMPILER = mx .suite ("compiler" , fatalIfMissing = False )
96
98
97
99
GRAAL_VERSION = SUITE .suiteDict ['version' ]
@@ -1803,7 +1805,7 @@ def dev_tag(arg=None, **kwargs):
1803
1805
mx_subst .results_substitutions .register_no_arg ('graalpy_ext' , graalpy_ext )
1804
1806
1805
1807
1806
- def update_import (name , suite_py , args ):
1808
+ def update_import (name , suite_py : Path , args ):
1807
1809
parent = os .path .join (SUITE .dir , ".." )
1808
1810
dep_dir = None
1809
1811
for dirpath , dirnames , _ in os .walk (parent ):
@@ -1815,12 +1817,10 @@ def update_import(name, suite_py, args):
1815
1817
if not dep_dir :
1816
1818
mx .warn ("could not find suite %s to update" % name )
1817
1819
return
1818
- vc = mx .VC . get_vc (dep_dir )
1820
+ vc = cast ( mx .VC , mx . VC . get_vc (dep_dir ) )
1819
1821
repo_name = os .path .basename (dep_dir )
1820
1822
if repo_name == "graal" and args .graal_rev :
1821
1823
rev = args .graal_rev
1822
- elif repo_name == "graal-enterprise" and args .graal_enterprise_rev :
1823
- rev = args .graal_enterprise_rev
1824
1824
elif args .no_pull :
1825
1825
rev = "HEAD"
1826
1826
else :
@@ -1838,7 +1838,7 @@ def update_import(name, suite_py, args):
1838
1838
start = dep_match .start (1 )
1839
1839
end = dep_match .end (1 )
1840
1840
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 )
1842
1842
return tip
1843
1843
1844
1844
@@ -1847,15 +1847,13 @@ def update_import_cmd(args):
1847
1847
1848
1848
parser = ArgumentParser ()
1849
1849
parser .add_argument ('--graal-rev' , default = '' )
1850
- parser .add_argument ('--graal-enterprise-rev' , default = '' )
1851
1850
parser .add_argument ('--no-pull' , action = 'store_true' )
1852
1851
parser .add_argument ('--no-push' , action = 'store_true' )
1853
1852
parser .add_argument ('--allow-dirty' , action = 'store_true' )
1854
1853
parser .add_argument ('--no-master-check' , action = 'store_true' , help = "do not check if repos are on master branch (e.g., when detached)" )
1855
1854
args = parser .parse_args (args )
1856
1855
1857
- join = os .path .join
1858
- vc = SUITE .vc
1856
+ vc = cast (mx .GitConfig , mx .VC .get_vc (SUITE .dir ))
1859
1857
1860
1858
current_branch = vc .active_branch (SUITE .dir , abortOnError = not args .no_master_check )
1861
1859
if vc .isDirty (SUITE .dir ) and not args .allow_dirty :
@@ -1864,121 +1862,38 @@ def update_import_cmd(args):
1864
1862
vc .git_command (SUITE .dir , ["checkout" , "-b" , f"update/GR-21590/{ datetime .datetime .now ().strftime ('%d%m%y' )} " ])
1865
1863
current_branch = vc .active_branch (SUITE .dir )
1866
1864
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"
1903
1868
1904
1869
# find all imports we might update
1905
1870
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" ])
1914
1876
1915
1877
revisions = {}
1916
1878
# now update all imports
1917
1879
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 )
1970
1881
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 )
1979
1884
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
1982
1897
1983
1898
1984
1899
def python_style_checks (args ):
0 commit comments