perf(build): preserve no-op codegen artifacts

This commit is contained in:
slhx agent
2026-07-13 09:38:54 +02:00
parent 945122cb02
commit 7db05356ae
3 changed files with 55 additions and 5 deletions
+51 -4
View File
@@ -223,15 +223,26 @@ impl AppBuilder {
resources.add_stylesheet(&self.template_dir, &path, &source)?;
}
std::fs::write(
out_dir.join("hemx.generated.rs"),
resources.generated_rs(self.global_exports),
write_if_changed(
&out_dir.join("hemx.generated.rs"),
resources.generated_rs(self.global_exports).as_bytes(),
)?;
std::fs::write(out_dir.join("hemx.syms"), resources.syms())?;
write_if_changed(&out_dir.join("hemx.syms"), resources.syms().as_bytes())?;
Ok(())
}
}
fn write_if_changed(path: &Path, contents: &[u8]) -> io::Result<bool> {
match std::fs::read(path) {
Ok(existing) if existing == contents => return Ok(false),
Ok(_) => {}
Err(error) if error.kind() == io::ErrorKind::NotFound => {}
Err(error) => return Err(error),
}
std::fs::write(path, contents)?;
Ok(true)
}
pub fn app() -> AppBuilder {
AppBuilder {
out_dir: None,
@@ -2162,6 +2173,42 @@ fn parse_error(path: &Path, err: impl std::fmt::Display) -> io::Error {
mod tests {
use super::*;
#[test]
fn no_op_build_preserves_generated_artifact_timestamps() {
// req: build/009
let base = test_dir("hemx-build-no-op");
let templates = base.join("templates");
let out = base.join("out");
let _ = std::fs::remove_dir_all(&base);
std::fs::create_dir_all(&templates).unwrap();
std::fs::write(
templates.join("panel.heml"),
r#"<button data-hemx-handle="save">Save</button>"#,
)
.unwrap();
app().template_dir(&templates).out_dir(&out).run().unwrap();
let generated = out.join("hemx.generated.rs");
let symbols = out.join("hemx.syms");
let generated_modified = std::fs::metadata(&generated).unwrap().modified().unwrap();
let symbols_modified = std::fs::metadata(&symbols).unwrap().modified().unwrap();
std::thread::sleep(std::time::Duration::from_millis(20));
app().template_dir(&templates).out_dir(&out).run().unwrap();
assert_eq!(
std::fs::metadata(generated).unwrap().modified().unwrap(),
generated_modified,
"no-op codegen must not invalidate downstream Rust compilation"
);
assert_eq!(
std::fs::metadata(symbols).unwrap().modified().unwrap(),
symbols_modified,
"no-op symbol generation must preserve its artifact timestamp"
);
let _ = std::fs::remove_dir_all(&base);
}
#[test]
fn emits_generated_resources_from_heml() {
// req: codegen/003