mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-22 19:25:56 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
f97408e8aa
commit
53c5e79d92
2 files changed
+40
-5
No files matched your search
@@ -54,11 +54,12 @@ fn break_module(root: &Path, id: &str) -> Result<(), Box<dyn std::error::Error>>
|
||||
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 <repo>/<commit> 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::<Vec<_>>().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<dyn std::error::Error>> {
|
||||
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}");
|
||||
|
||||
@@ -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<String> {
|
||||
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();
|
||||
|
||||
Reference in new issue
Block a user