From 53c5e79d922357317352fa82f4645440fd9da035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 6 Nov 2026 17:43:09 +0500 Subject: [PATCH] rebuild: a module that fails to build is switched off with the compiler's error build_module_with_bundle reports a failed compile as Ok(success: false). rebuild ignored the flag, installed the package left by the previous build (made for the old core) and only then switched the module off as 'does not match the installed core'. Now the failed build stops there and the reason names the first compiler error. Co-Authored-By: Claude Opus 5.5 --- .../examples/preview_core_update_e2e.rs | 12 ++++--- crates/coa-core/src/rebuild.rs | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/crates/coa-core/examples/preview_core_update_e2e.rs b/crates/coa-core/examples/preview_core_update_e2e.rs index ddca330..a1b2841 100644 --- a/crates/coa-core/examples/preview_core_update_e2e.rs +++ b/crates/coa-core/examples/preview_core_update_e2e.rs @@ -54,11 +54,12 @@ fn break_module(root: &Path, id: &str) -> Result<(), Box> let recipe_path = coa_core::plugins::meta_dir(root).join("build-recipes").join(format!("{id}.json")); let mut recipe: serde_json::Value = serde_json::from_slice(&std::fs::read(&recipe_path)?)?; let src = PathBuf::from(recipe["source_dir"].as_str().ok_or("recipe has no source_dir")?); - // Short path on purpose (Ninja's path limit), next to the fixture, never inside the shared cache. - let broken = root.parent().unwrap().join(format!("brk-{id}")); - assert!(!broken.exists(), "{} already exists", broken.display()); - copy_dir(&src, &broken)?; - let cpp = first_cpp(&broken.join("src")).ok_or("no .cpp in the module sources")?; + // Next to the fixture, never inside the shared cache. Same / tail as the cache, because the + // manager reads the module's identity from it: the build itself must be what fails. + let tail: PathBuf = src.components().rev().take(2).collect::>().into_iter().rev().collect(); + let broken = root.parent().unwrap().join("brk").join(tail); + copy_dir(&src, &broken)?; // a fresh copy over any earlier one + let cpp = ["src", "module/src"].iter().find_map(|d| first_cpp(&broken.join(d))).ok_or("no .cpp in the module sources")?; let text = std::fs::read_to_string(&cpp)?; std::fs::write(&cpp, format!("#error coa e2e: this module deliberately does not build\n{text}"))?; println!("broke {id}: {} (recipe now -> {})", cpp.display(), broken.display()); @@ -125,6 +126,7 @@ fn main() -> Result<(), Box> { let line = shown.iter().find(|m| m.contains(&format!("\"{id}\""))).cloned().unwrap_or_default(); if broken.as_deref() == Some(id.as_str()) { assert!(line.starts_with("Disabled") && !e.enabled && e.disabled_reason.is_some(), "{id} must be switched off with a reason: {line}"); + assert!(line.contains("does not build"), "{id} must be switched off because it does not build: {line}"); assert!(!lock_after.contains(&format!("{id}|")), "{id} is still in plugins.lock"); } else if lock_before.contains(&format!("{id}|")) { assert!(line.starts_with("Rebuilt") || line.starts_with("Reused"), "{id} was not rebuilt for the new core: {line}"); diff --git a/crates/coa-core/src/rebuild.rs b/crates/coa-core/src/rebuild.rs index 6b0e78a..9c069d7 100644 --- a/crates/coa-core/src/rebuild.rs +++ b/crates/coa-core/src/rebuild.rs @@ -99,6 +99,10 @@ fn bring_up_to_date( let started = std::time::Instant::now(); let built = build_engine::build_module_with_bundle(&recipe.source_dir, &recipe.bundled, realm_root, None, None) .map_err(|e| e.to_string())?; + if !built.success { + // Never fall through to a package left by an earlier build: that one was made for the old core. + return Err(build_failure_reason(&built.errors)); + } if built.module_id != id { return Err(format!("the sources now build module '{}', not '{id}'", built.module_id)); } @@ -112,6 +116,18 @@ fn bring_up_to_date( Ok(ModuleRebuild::Rebuilt { id: id.to_string(), seconds: started.elapsed().as_secs() }) } +/// Why a module did not build for the new core, from the compiler's first error. +fn build_failure_reason(errors: &[build_engine::BuildErrorDiagnostic]) -> String { + match errors.first() { + Some(e) if !e.file.is_empty() => { + let file = e.file.rsplit(['/', '\\']).next().unwrap_or(&e.file); + format!("it does not build for the new core: {} ({file}:{}, {})", first_line(&e.message), e.line, e.error_code) + } + Some(e) => format!("it does not build for the new core: {}", first_line(&e.message)), + None => "it does not build for the new core".into(), + } +} + /// The store keeps every build by content hash: find one made for `host`. fn stored_build_for(realm_root: &Path, id: &str, host: &str) -> Option { let dir = plugins::store_dir(realm_root).join(id); @@ -456,6 +472,23 @@ mod tests { println!("{lock}"); } + #[test] + fn a_failed_build_names_the_compiler_error() { + let e = build_engine::BuildErrorDiagnostic { + file: "C:\\brk\\src\\PlayerbotAIConfig.cpp".into(), + line: 1, + error_code: "C1189".into(), + message: "#error: coa e2e: this module deliberately does not build\nmore".into(), + explanation: None, + resolution: None, + }; + assert_eq!( + build_failure_reason(&[e]), + "it does not build for the new core: #error: coa e2e: this module deliberately does not build (PlayerbotAIConfig.cpp:1, C1189)" + ); + assert_eq!(build_failure_reason(&[]), "it does not build for the new core"); + } + #[test] fn a_monolithic_core_needs_no_rebuild() { let dir = tempfile::tempdir().unwrap();