| @@ -0,0 +1,65 @@ |
| 1 | +"""Prepare the official, digest-pinned Linux Lean release in a private directory.""" |
| 2 | +import argparse |
| 3 | +from concurrent.futures import ThreadPoolExecutor, as_completed |
| 4 | +import hashlib |
| 5 | +import json |
| 6 | +from pathlib import Path |
| 7 | +import subprocess |
| 8 | + |
| 9 | +URL = 'https://github.com/leanprover/lean4/releases/download/v4.33.1/lean-4.33.1-linux.tar.zst' |
| 10 | +SIZE = 570405234 |
| 11 | +SHA256 = '890afd185370f85666025b883914ab4f4b339136f8c96167b69cfb62aecaf235' |
| 12 | +CHUNK = 8 * 1024 * 1024 |
| 13 | + |
| 14 | +def windows_path(path): |
| 15 | + return subprocess.check_output(['wslpath', '-w', str(path.resolve())], text=True).strip() |
| 16 | + |
| 17 | +def main(): |
| 18 | + parser = argparse.ArgumentParser(description=__doc__) |
| 19 | + parser.add_argument('--private-root', required=True, type=Path) |
| 20 | + parser.add_argument('--report', required=True, type=Path) |
| 21 | + args = parser.parse_args() |
| 22 | + root = args.private_root.resolve() |
| 23 | + chunks = root / 'lean-release-chunks'; chunks.mkdir(parents=True, exist_ok=True) |
| 24 | + ranges = [(start, min(start + CHUNK, SIZE) - 1) for start in range(0, SIZE, CHUNK)] |
| 25 | + def download(pair): |
| 26 | + start, end = pair |
| 27 | + target = chunks / f'{start:012d}-{end:012d}.bin' |
| 28 | + if target.exists() and target.stat().st_size == end - start + 1: return target |
| 29 | + partial = target.with_suffix('.partial'); headers = target.with_suffix('.headers') |
| 30 | + subprocess.run(['curl','-fsSL','--max-time','180','--retry','2', |
| 31 | + '-r',f'{start}-{end}','-D',str(headers),'-o',str(partial), |
| 32 | + URL + f'?shoal-range={start}-{end}'],check=True) |
| 33 | + text = headers.read_text().lower().replace('\r','') |
| 34 | + expected = f'content-range: bytes {start}-{end}/{SIZE}' |
| 35 | + if expected not in text or partial.stat().st_size != end - start + 1: |
| 36 | + raise ValueError('server did not honor the requested release range') |
| 37 | + partial.replace(target) |
| 38 | + return target |
| 39 | + print('progress: 0/100 downloading digest-pinned official Lean release',flush=True) |
| 40 | + with ThreadPoolExecutor(max_workers=16) as pool: |
| 41 | + jobs = [pool.submit(download, pair) for pair in ranges] |
| 42 | + for count, job in enumerate(as_completed(jobs), 1): |
| 43 | + job.result() |
| 44 | + print(f'progress: {int(75 * count / len(ranges))}/100 downloaded {count}/{len(ranges)} release chunks',flush=True) |
| 45 | + archive = root / 'lean-4.33.1-linux.tar.zst' |
| 46 | + h = hashlib.sha256() |
| 47 | + with archive.open('wb') as output: |
| 48 | + for start,end in ranges: |
| 49 | + with (chunks / f'{start:012d}-{end:012d}.bin').open('rb') as stream: |
| 50 | + while block := stream.read(1024 * 1024): h.update(block); output.write(block) |
| 51 | + if archive.stat().st_size != SIZE or h.hexdigest() != SHA256: |
| 52 | + raise ValueError('official release digest/size mismatch; nothing extracted') |
| 53 | + print('progress: 80/100 official release digest matched; extracting private toolchain',flush=True) |
| 54 | + |
| 55 | + subprocess.run(['tar.exe','-xf',windows_path(archive),'-C',windows_path(root)],check=True) |
| 56 | + binary = root / 'lean-4.33.1-linux/bin/lean' |
| 57 | + version = subprocess.check_output([str(binary),'--version'],text=True).strip() |
| 58 | + if '4.33.1' not in version or '819816b2' not in version: |
| 59 | + raise ValueError('installed Lean does not match the project pin: '+version) |
| 60 | + report = {'release_url':URL,'bytes':SIZE,'sha256':SHA256,'lean_version':version, |
| 61 | + 'scope':'Official toolchain only; project and Mathlib have not been built.'} |
| 62 | + args.report.write_text(json.dumps(report,indent=2)+'\n') |
| 63 | + print('progress: 100/100 pinned Lean toolchain ready; project build not yet performed',flush=True) |
| 64 | + |
| 65 | +if __name__ == '__main__': main() |