49 lines
1.5 KiB
Plaintext
49 lines
1.5 KiB
Plaintext
// NAC Lint Build Script
|
||
// 将此文件复制为 build.rs 放在项目根目录
|
||
// Cargo会在编译前自动运行此脚本
|
||
|
||
use std::process::Command;
|
||
use std::env;
|
||
|
||
fn main() {
|
||
// 只在非release模式下运行检查(加快release构建速度)
|
||
let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string());
|
||
|
||
if profile == "release" {
|
||
println!("cargo:warning=Skipping NAC Lint check in release mode");
|
||
return;
|
||
}
|
||
|
||
println!("cargo:warning=Running NAC Lint check...");
|
||
|
||
// 运行NAC Lint检查
|
||
let output = Command::new("python3")
|
||
.arg("memory/tools/nac_lint.py")
|
||
.arg("check")
|
||
.arg("--path")
|
||
.arg("src/")
|
||
.output();
|
||
|
||
match output {
|
||
Ok(output) => {
|
||
if !output.status.success() {
|
||
// 输出违规信息
|
||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||
|
||
eprintln!("{}", stdout);
|
||
eprintln!("{}", stderr);
|
||
|
||
// 阻止编译
|
||
panic!("NAC Lint check failed. Fix violations before building.");
|
||
} else {
|
||
println!("cargo:warning=NAC Lint check passed");
|
||
}
|
||
}
|
||
Err(e) => {
|
||
println!("cargo:warning=Failed to run NAC Lint: {}", e);
|
||
println!("cargo:warning=Continuing build without lint check");
|
||
}
|
||
}
|
||
}
|