35 lines
2.3 KiB
Python
35 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib,json,subprocess,tarfile,shutil
|
|
from pathlib import Path
|
|
package='plasma-next-rust-build-tools';dest=Path('debian')/package
|
|
expected=json.loads(Path('debian/bootstrap-inputs.json').read_text())
|
|
assert {p.name for p in Path('bootstrap').glob('*.tar.xz')}==set(expected)
|
|
for archive in sorted(Path('bootstrap').glob('*.tar.xz')):
|
|
with archive.open('rb') as stream:assert hashlib.file_digest(stream,'sha256').hexdigest()==expected[archive.name]
|
|
root=Path('obj-module')/archive.name.removesuffix('.tar.xz');root.mkdir(parents=True,exist_ok=True)
|
|
with tarfile.open(archive) as tar:tar.extractall(root,filter='data')
|
|
entries=list(root.iterdir());assert len(entries)==1
|
|
subprocess.run(['bash',str(entries[0]/'install.sh'),'--prefix=/opt/plasma-build/rust-1.88.0','--destdir='+str(dest.resolve()),'--disable-ldconfig'],check=True)
|
|
for p in entries[0].glob('*'):
|
|
if p.is_file() and p.name.startswith(('LICENSE','COPYRIGHT')):
|
|
target=dest/'usr/share/doc'/package/'upstream-licenses'/archive.name/p.name;target.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(p,target)
|
|
# Keep upstream documentation in the Debian documentation hierarchy.
|
|
docs=dest/'opt/plasma-build/rust-1.88.0/share/doc'
|
|
if docs.exists():
|
|
target=dest/'usr/share/doc'/package/'upstream';target.parent.mkdir(parents=True,exist_ok=True);shutil.move(str(docs),target)
|
|
|
|
# Check real compilation/linking against the staged compiler and standard library.
|
|
prefix=dest/'opt/plasma-build/rust-1.88.0'
|
|
probe=Path('obj-module/bootstrap-probe.rs')
|
|
probe.write_text('fn main() { let v = vec![1_u64, 2, 3]; println!("{}", v.iter().sum::<u64>()); }\n')
|
|
subprocess.run([str(prefix/'bin/rustc'),'--edition=2021','--crate-name','plasma_next_bootstrap_probe',str(probe),'-o','obj-module/bootstrap-probe'],check=True)
|
|
subprocess.run([str(prefix/'bin/cargo'),'--version'],check=True)
|
|
|
|
# Keep Rust metadata/compiler archives intact through Debian packaging.
|
|
files={}
|
|
for p in prefix.rglob('*'):
|
|
rel=p.relative_to(prefix)
|
|
if p.is_file() and not p.is_symlink() and p.suffix=='.rlib':
|
|
with p.open('rb') as stream:files[str(p)]=hashlib.file_digest(stream,'sha256').hexdigest()
|
|
Path('debian/bootstrap-payload.json').write_text(json.dumps(files,sort_keys=True)+'\n')
|