This commit is contained in:
nora 2022-12-17 18:44:51 +01:00
parent d9f3f347e9
commit 002bad34ae
5 changed files with 96 additions and 40 deletions

View file

@ -1,45 +1,64 @@
use anyhow::{Context, Result};
use std::{fmt::Display, path::PathBuf};
use crate::Options;
#[derive(Debug)]
pub struct Build {
cargo: bool,
script_path: Option<PathBuf>,
mode: BuildMode,
input_path: PathBuf,
}
#[derive(Debug)]
enum BuildMode {
Cargo,
Script(PathBuf),
Rustc,
}
impl Build {
pub fn new(cargo: bool, script_path: Option<PathBuf>, input_path: PathBuf) -> Self {
pub fn new(options: &Options) -> Self {
let mode = if options.cargo {
BuildMode::Cargo
} else if let Some(script) = &options.verify_error_path {
BuildMode::Script(script.clone())
} else {
BuildMode::Rustc
};
Self {
cargo,
script_path,
input_path,
mode,
input_path: options.path.clone(),
}
}
pub fn build(&self) -> Result<BuildResult> {
let reproduces_issue = if self.cargo {
let mut cmd = std::process::Command::new("cargo");
cmd.arg("build");
let reproduces_issue = match &self.mode {
BuildMode::Cargo => {
let mut cmd = std::process::Command::new("cargo");
cmd.arg("build");
let output =
String::from_utf8(cmd.output().context("spawning rustc process")?.stderr).unwrap();
let output =
String::from_utf8(cmd.output().context("spawning rustc process")?.stderr)
.unwrap();
output.contains("internal compiler error")
} else if let Some(script_path) = &self.script_path {
let mut cmd = std::process::Command::new(script_path);
output.contains("internal compiler error")
}
BuildMode::Script(script_path) => {
let mut cmd = std::process::Command::new(script_path);
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 script")?.status.success()
}
BuildMode::Rustc => {
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)
cmd.output()
.context("spawning rustc process")?
.status
.code()
== Some(101)
}
};
Ok(BuildResult { reproduces_issue })