Skip to main content

lensbench_engine/
provenance.rs

1//! --save の JSON に刻む版と系の hash(provenance)
2
3use lensbench_core::System;
4use serde_json::{json, Value};
5
6thread_local! {
7    /// このスレッドで最後に読んだ系の hash(--save の JSON の provenance に刻む)
8    static LOADED_HASH: std::cell::RefCell<Option<String>> = const { std::cell::RefCell::new(None) };
9}
10
11/// --save の provenance に刻む系(serve の登録簿の解析は load を通らないので、書く前にここで)
12pub fn set(s: &System) {
13    let h = lensbench_project::sysfile::system_hash(s).ok();
14    LOADED_HASH.with(|x| *x.borrow_mut() = h);
15}
16
17/// 刻む系を忘れる(解析ごとに読み直す前に)
18pub fn clear() {
19    LOADED_HASH.with(|x| *x.borrow_mut() = None);
20}
21
22/// 結果に刻む版と系の hash
23pub fn value() -> Value {
24    let h = LOADED_HASH.with(|x| x.borrow().clone());
25    json!({ "lensbench": lensbench_core::VERSION, "system_hash": h })
26}