9fa3a684c6
A port of tools/prepare_native_client.py and the helpers it imported from lab.py and the test_*_parity.py modules: the player's pinned game files are imported and checked against research-lock.json, the client's assets and data copied, the vanilla exporters compiled and run with the JDK (JAVA_HOME, the PATH, or java_home on macOS, at the pinned java_major), and the resources and their manifest written byte for byte as the script wrote them, with its sha256-keyed skips. tools/compare_prepare.py checks that against the Python preparer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.4 KiB
Rust
39 lines
1.4 KiB
Rust
//! HORIZON_PREPARE_SOURCES_SHA256: a digest of this crate's sources, which the launcher compares
|
|
//! with a version folder's copy to know whether it may prepare that version in-process. Keep the
|
|
//! algorithm the same as `horizon_prepare::sources_sha256`.
|
|
|
|
use sha2::Digest;
|
|
use std::fs;
|
|
use std::path::Path;
|
|
|
|
fn main() {
|
|
let dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
|
let mut files = Vec::new();
|
|
for name in ["Cargo.toml", "build.rs"] {
|
|
println!("cargo:rerun-if-changed={name}");
|
|
files.push((name.to_string(), fs::read(dir.join(name)).unwrap()));
|
|
}
|
|
println!("cargo:rerun-if-changed=src");
|
|
let mut sources: Vec<String> = fs::read_dir(dir.join("src"))
|
|
.unwrap()
|
|
.map(|e| e.unwrap().file_name().to_string_lossy().into_owned())
|
|
.filter(|n| n.ends_with(".rs"))
|
|
.collect();
|
|
sources.sort();
|
|
for name in sources {
|
|
println!("cargo:rerun-if-changed=src/{name}");
|
|
files.push((
|
|
format!("src/{name}"),
|
|
fs::read(dir.join("src").join(&name)).unwrap(),
|
|
));
|
|
}
|
|
let mut hash = sha2::Sha256::new();
|
|
for (name, data) in files {
|
|
let data: Vec<u8> = data.into_iter().filter(|b| *b != b'\r').collect();
|
|
hash.update(format!("{name}\0{}\0", data.len()));
|
|
hash.update(&data);
|
|
}
|
|
let hex: String = hash.finalize().iter().map(|b| format!("{b:02x}")).collect();
|
|
println!("cargo:rustc-env=HORIZON_PREPARE_SOURCES_SHA256={hex}");
|
|
}
|