feat: cargo format struct
This commit is contained in:
1 parent
7860f8b931
commit
5edcb9238c
2 files changed
+43
-8
No files matched your search
+18
-8
@@ -77,18 +77,28 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<()> {
|
|||||||
|
|
||||||
let loading = loading::Loading::default();
|
let loading = loading::Loading::default();
|
||||||
loading.text("Building");
|
loading.text("Building");
|
||||||
let output = cmd.output()?;
|
let mut child = cmd.spawn()?;
|
||||||
for i in output.stdout.lines() {
|
let out = child.stdout.take().unwrap();
|
||||||
// println!("{:?}", i);
|
let mut out = std::io::BufReader::new(out);
|
||||||
|
let mut s = String::new();
|
||||||
|
let mut n = 0;
|
||||||
|
while let Ok(_) = out.read_line(&mut s) {
|
||||||
|
// 进程退出后结束循环
|
||||||
|
if let Ok(Some(_)) = child.try_wait() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
println!("\n{}\n", s);
|
||||||
|
loading.text(format!("Building {}", n));
|
||||||
|
n += 1;
|
||||||
}
|
}
|
||||||
loading.success("OK");
|
loading.success("OK");
|
||||||
loading.end();
|
loading.end();
|
||||||
|
|
||||||
if !output.status.success() {
|
// if !output.status.success() {
|
||||||
log::error!("Build failed!");
|
// log::error!("Build failed!");
|
||||||
let reason = String::from_utf8_lossy(&output.stderr).to_string();
|
// let reason = String::from_utf8_lossy(&output.stderr).to_string();
|
||||||
return Err(Error::BuildFailed(reason));
|
// return Err(Error::BuildFailed(reason));
|
||||||
}
|
// }
|
||||||
|
|
||||||
// [2] Establish the output directory structure
|
// [2] Establish the output directory structure
|
||||||
let bindgen_outdir = out_dir.join("assets").join("dioxus");
|
let bindgen_outdir = out_dir.join("assets").join("dioxus");
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
//! Utilities for working with cargo and rust files
|
//! Utilities for working with cargo and rust files
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use std::{
|
use std::{
|
||||||
env, fs,
|
env, fs,
|
||||||
@@ -90,3 +92,26 @@ impl Metadata {
|
|||||||
Err(Error::CargoError("InvalidOutput".to_string()))
|
Err(Error::CargoError("InvalidOutput".to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Debug, Clone)]
|
||||||
|
pub struct CargoFormatInfo {
|
||||||
|
pub reason: CargoFormatReason,
|
||||||
|
#[serde(default)]
|
||||||
|
pub package_id: String,
|
||||||
|
#[serde(default)]
|
||||||
|
manifest_path: String,
|
||||||
|
#[serde(default)]
|
||||||
|
message: Option<serde_json::Value>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Debug, Clone)]
|
||||||
|
pub enum CargoFormatReason {
|
||||||
|
#[serde(rename = "compiler-message")]
|
||||||
|
CompilerMessage,
|
||||||
|
#[serde(rename = "compiler-artifact")]
|
||||||
|
CompilerArtifact,
|
||||||
|
#[serde(rename = "build-script-executed")]
|
||||||
|
BuildScriptExecuted,
|
||||||
|
#[serde(rename = "build-finished")]
|
||||||
|
BuildFinished,
|
||||||
|
}
|
||||||
Reference in new issue
Block a user