| @@ -0,0 +1,32 @@ |
| 1 | +"""Run the stock fixed Mathlib cache client using native Windows Lean on drive E.""" |
| 2 | +import argparse,ctypes,json,os,subprocess |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +def main(): |
| 6 | + p=argparse.ArgumentParser(description=__doc__);p.add_argument('--base',type=Path,required=True);p.add_argument('--report',type=Path,required=True);a=p.parse_args();base=a.base.resolve();source=base/'private-environment/original-source' |
| 7 | + bins=list((base/'private-environment/windows-toolchain').glob('*/bin/lean.exe')) |
| 8 | + if len(bins)!=1:raise ValueError('native compiler is not ready') |
| 9 | + leanbin=bins[0].parent |
| 10 | + version=subprocess.check_output([str(bins[0]),'--version'],text=True).strip() |
| 11 | + if '4.33.1' not in version or '819816b2' not in version:raise ValueError('incorrect native compiler') |
| 12 | + actual=subprocess.check_output(['git','-C',str(source/'.lake/packages/mathlib'),'rev-parse','HEAD'],text=True).strip() |
| 13 | + if actual!='0df444a360eaa60ab8c11dca51a86af692955474':raise ValueError('wrong Mathlib revision') |
| 14 | + env=os.environ.copy();env['PATH']=str(leanbin)+os.pathsep+env['PATH'] |
| 15 | + env['MATHLIB_CACHE_DIR']=str(base/'private-environment/mathlib-cache') |
| 16 | + env['MATHLIB_CACHE_GET_URL']='https://cache.mathlib.org/mathlib4';env['LAKE_ARTIFACT_CACHE']='false' |
| 17 | + env['LAKE_CACHE_DIR']=str(base/'private-environment/lake-cache');env['LEAN_ABORT_ON_PANIC']='1' |
| 18 | + env['GIT_CONFIG_COUNT']='3';env['GIT_CONFIG_KEY_0']='core.longpaths';env['GIT_CONFIG_VALUE_0']='true' |
| 19 | + env['GIT_CONFIG_KEY_1']='core.autocrlf';env['GIT_CONFIG_VALUE_1']='false';env['GIT_CONFIG_KEY_2']='credential.helper';env['GIT_CONFIG_VALUE_2']='';env['GIT_TERMINAL_PROMPT']='0' |
| 20 | + temp=base/'.shoal/tmp';temp.mkdir(exist_ok=True);env['TEMP']=str(temp);env['TMP']=str(temp) |
| 21 | + kernel=ctypes.WinDLL('kernel32',use_last_error=True);handle=kernel.GetCurrentProcess();allowed=ctypes.c_size_t();system=ctypes.c_size_t() |
| 22 | + if kernel.GetProcessAffinityMask(handle,ctypes.byref(allowed),ctypes.byref(system)): |
| 23 | + selected=[i for i in range(64) if allowed.value & (1<<i)][:4];kernel.SetProcessAffinityMask(handle,sum(1<<i for i in selected)) |
| 24 | + print('Using fixed native Windows Lean; fetching and decompressing the stock Mathlib cache.',flush=True) |
| 25 | + subprocess.run([str(leanbin/'lake.exe'),'-R','exe','mathlib/cache','get'],cwd=source,env=env,check=True) |
| 26 | + files=list(Path(env['MATHLIB_CACHE_DIR']).glob('*.ltar')) |
| 27 | + if not files:raise ValueError('no Mathlib cache files downloaded') |
| 28 | + marker=source/'.lake/packages/mathlib/.lake/build/lib/lean/Mathlib.olean' |
| 29 | + if not marker.is_file():raise ValueError('Mathlib.olean was not restored') |
| 30 | + a.report.write_text(json.dumps({'mathlib_revision':actual,'lean_version':version,'downloaded_archives':len(files),'downloaded_bytes':sum(f.stat().st_size for f in files),'mathlib_root_olean_exists':True,'scope':'Stock third-party Mathlib cache, not an independent proof build.'},indent=2)+'\n',encoding='utf-8') |
| 31 | + print('Fixed Mathlib cache downloaded and restored.',flush=True) |
| 32 | +if __name__=='__main__':main() |