feat(build): archive feature, progress UI, and workspace path fixes

This commit is contained in:
2026-07-23 13:56:36 +08:00
parent a9dd8c1631
commit 588e4dd13f
27 changed files with 597 additions and 276 deletions

View File

@@ -77,8 +77,15 @@ fn build_run_clean_flags_normal_project() {
assert!(out.status.success(), "dcr build --release should succeed");
let out = run_dcr_env(&["run"], &dir, &envs);
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(stdout.contains("Running"), "dcr run should start");
let combined = format!(
"{}{}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
);
assert!(
combined.contains("run") || combined.contains("Running"),
"dcr run should start"
);
let out = run_dcr_env(&["clean", "--release"], &dir, &envs);
assert!(out.status.success(), "dcr clean --release should succeed");
@@ -170,3 +177,92 @@ fn build_with_out_dir() {
"artifact should NOT be at default path when out_dir is set"
);
}
#[test]
fn flat_bin_nasm_build() {
let nasm_ok = std::process::Command::new("nasm")
.arg("-v")
.output()
.map(|o| o.status.success())
.unwrap_or(false);
if !nasm_ok {
eprintln!("nasm not found; skipping flat-bin test");
return;
}
let dir = unique_sandbox_dir("flat_bin");
let out = run_dcr(&["init"], &dir);
assert!(out.status.success(), "dcr init should succeed");
std::fs::write(
dir.join("dcr.toml"),
r#"[package]
name = "flatdemo"
version = "0.1.0"
[build]
language = "asm"
compiler = "nasm"
kind = "flat-bin"
extension = "bin"
roots = ["src"]
"#,
)
.expect("write dcr.toml");
std::fs::create_dir_all(dir.join("src")).expect("src");
std::fs::write(
dir.join("src/boot.asm"),
"bits 16\norg 0x7c00\ncli\nhlt\ntimes 510-($-$$) db 0\ndw 0xaa55\n",
)
.expect("write boot.asm");
let out = run_dcr(&["build"], &dir);
if !out.status.success() {
eprintln!("stdout: {}", String::from_utf8_lossy(&out.stdout));
eprintln!("stderr: {}", String::from_utf8_lossy(&out.stderr));
}
assert!(out.status.success(), "flat-bin nasm build should succeed");
let candidates = [
dir.join("target/debug/boot.bin"),
dir.join("target").join(format!(
"{}-unknown-linux-gnu/debug/boot.bin",
std::env::consts::ARCH
)),
];
assert!(
candidates.iter().any(|p| p.is_file()),
"expected boot.bin under target/…/debug, candidates: {candidates:?}"
);
}
#[test]
fn package_build_target_used_without_cli_flag() {
let Some(compiler) = available_compiler() else {
eprintln!("no compiler found; skipping package target test");
return;
};
let dir = unique_sandbox_dir("pkg_target");
let out = run_dcr(&["init"], &dir);
assert!(out.status.success());
let toml_path = dir.join("dcr.toml");
let toml = std::fs::read_to_string(&toml_path).unwrap();
let project_name = parse_project_name(&toml);
let updated = toml.replace("[build]", "[build]\ntarget = \"x86_64-unknown-linux-gnu\"");
std::fs::write(&toml_path, updated).unwrap();
let envs = [("DCR_COMPILER", compiler)];
let out = run_dcr_env(&["build"], &dir, &envs);
assert!(out.status.success(), "build should use package target");
let artifact = dir
.join("target/x86_64-unknown-linux-gnu/debug")
.join(&project_name);
assert!(
artifact.is_file(),
"artifact should be under package build.target path"
);
}