make things cool and good and wow

This commit is contained in:
nora 2022-12-17 18:18:21 +01:00
parent 958383f991
commit d9f3f347e9
8 changed files with 486 additions and 41 deletions

View file

@ -1,28 +1,60 @@
use anyhow::{Context, Result};
use std::path::PathBuf;
use std::{fmt::Display, path::PathBuf};
#[derive(Debug)]
pub struct Build {
path: PathBuf,
cargo: bool,
script_path: Option<PathBuf>,
input_path: PathBuf,
}
impl Build {
pub fn new(path: impl Into<PathBuf>) -> Self {
Self { path: path.into() }
pub fn new(cargo: bool, script_path: Option<PathBuf>, input_path: PathBuf) -> Self {
Self {
cargo,
script_path,
input_path,
}
}
pub fn build(&self) -> Result<BuildResult> {
let mut cmd = std::process::Command::new("cargo");
let reproduces_issue = if self.cargo {
let mut cmd = std::process::Command::new("cargo");
cmd.arg("build");
cmd.current_dir(&self.path).arg("build");
let output =
String::from_utf8(cmd.output().context("spawning rustc process")?.stderr).unwrap();
let output = cmd.output().context("spawning cargo")?;
output.contains("internal compiler error")
} else if let Some(script_path) = &self.script_path {
let mut cmd = std::process::Command::new(script_path);
Ok(BuildResult {
success: output.status.success(),
})
cmd.output().context("spawning script")?.status.success()
} else {
let mut cmd = std::process::Command::new("rustc");
cmd.args(["--edition", "2018"]);
cmd.arg(&self.input_path);
cmd.output()
.context("spawning rustc process")?
.status
.code()
== Some(101)
};
Ok(BuildResult { reproduces_issue })
}
}
pub struct BuildResult {
pub success: bool,
pub reproduces_issue: bool,
}
impl Display for BuildResult {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.reproduces_issue {
true => f.write_str("yes"),
false => f.write_str("no"),
}
}
}