MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / dashboard_source_stamp

Function dashboard_source_stamp

build.rs:160–189  ·  view source on GitHub ↗

Content hash of the production dashboard source inputs (each input's path + bytes), independent of filesystem mtimes. Returns `None` when there are no source inputs - e.g. a published crate that ships only the prebuilt dist - so a stamp is never recorded and a rebuild is never triggered for crates.io.

(source_inputs: &[PathBuf])

Source from the content-addressed store, hash-verified

158/// source inputs - e.g. a published crate that ships only the prebuilt dist -
159/// so a stamp is never recorded and a rebuild is never triggered for crates.io.
160fn dashboard_source_stamp(source_inputs: &[PathBuf]) -> Option<String> {
161 if source_inputs.is_empty() {
162 return None;
163 }
164 // Hash in a stable path order so the stamp depends only on file content,
165 // not on the unspecified `read_dir` traversal order. Sort by the same
166 // normalized forward-slash string key the JS builder uses
167 // (build.shared.mjs `normalizedSourcePath`) so the two stamps stay
168 // byte-identical; `PathBuf`'s default component-wise ordering can diverge
169 // from JS string ordering.
170 let mut paths: Vec<&PathBuf> = source_inputs.iter().collect();
171 paths.sort_by(|a, b| {
172 normalized_dashboard_source_path(a).cmp(&normalized_dashboard_source_path(b))
173 });
174 let mut hasher = FNV_OFFSET_BASIS;
175 for path in paths {
176 // Hashing the path makes adds/removes/renames flip the stamp even when
177 // the surviving files are byte-identical.
178 fnv_hash_bytes(
179 &mut hasher,
180 normalized_dashboard_source_path(path).as_bytes(),
181 );
182 fnv_hash_bytes(&mut hasher, &[0]);
183 if let Ok(bytes) = fs::read(path) {
184 fnv_hash_bytes(&mut hasher, &bytes);
185 }
186 fnv_hash_bytes(&mut hasher, &[0]);
187 }
188 Some(format!("{hasher:016x}"))
189}
190
191/// True when the dashboard source inputs differ from the content stamp recorded
192/// by the previous build in this `OUT_DIR` - i.e. the sources genuinely changed

Callers 1

Calls 6

fnv_hash_bytesFunction · 0.85
collectMethod · 0.80
cmpMethod · 0.80
readFunction · 0.50
is_emptyMethod · 0.45

Tested by

no test coverage detected