diff --git a/index.html b/index.html index 6a43da1..daa30e0 100644 --- a/index.html +++ b/index.html @@ -34,13 +34,28 @@ cols="80" placeholder="// Rust code goes here..." > -fn main() {}
- + + +

@@ -64,6 +79,7 @@ fn main() {}, conn: Connection) { Err(_) => return, }; - info!(id = %job.id, "Starting bisection job"); - - let mut bisect = Bisection { - id: job.id, - code: job.code.clone(), - status: BisectStatus::InProgress, - }; - - match db::add_bisection(&conn, &bisect).wrap_err("insert bisection") { - Ok(()) => { - let status = match bisect_job(job) { - Ok(status) => status, - Err(err) => { - error!(?err, "error processing bisection"); - BisectStatus::Error { - output: err.to_string(), - } - } - }; - - bisect.status = status; - - match db::update_bisection_status(&conn, &bisect) { - Ok(()) => {} - Err(err) => error!(?err, "error updating bisection"), - } + match process_job(job, &conn) { + Ok(()) => {} + Err(err) => { + error!(?err, "error processing bisection") } - Err(err) => error!(?err, "error inserting bisection"), } } } -#[tracing::instrument(skip(job), fields(id = %job.id))] +#[tracing::instrument(skip(job, conn), fields(id = %job.id))] +pub fn process_job(job: Job, conn: &Connection) -> Result<()> { + info!(id = %job.id, "Starting bisection job"); + + let mut bisect = Bisection { + id: job.id, + code: job.code.clone(), + status: BisectStatus::InProgress, + }; + + db::add_bisection(&conn, &bisect).wrap_err("insert bisection")?; + + let status = match bisect_job(job) { + Ok(status) => status, + Err(err) => { + error!(?err, "error processing bisection"); + BisectStatus::Error { + output: format!("Internal error"), + } + } + }; + + bisect.status = status; + + db::update_bisection_status(&conn, &bisect).wrap_err("writing bisection result")?; + + trace!(?bisect, "Finished bisection job"); + + Ok(()) +} + fn bisect_job(job: Job) -> Result { - let (output, state) = run_bisect_for_file(job.code, job.options.start, job.options.end)?; + let (output, state) = run_bisect_for_file(job.code, &job.options)?; info!(state = %state.status(), "Bisection finished"); process_result(output, state).wrap_err("process result") @@ -113,7 +120,9 @@ fn process_result(output: Output, state: JobState) -> Result { match state { JobState::Failed => { - let output = stderr.lines().rev().take(10).collect::(); + let mut output = stderr.lines().rev().take(30).collect::>(); + output.reverse(); + let output = output.join("\n"); info!(?output, "output"); Ok(BisectStatus::Error { output }) } @@ -127,11 +136,7 @@ fn process_result(output: Output, state: JobState) -> Result { } } -fn run_bisect_for_file( - input: String, - start: chrono::NaiveDate, - end: Option, -) -> Result<(Output, JobState)> { +fn run_bisect_for_file(input: String, options: &Options) -> Result<(Output, JobState)> { let temp_dir = tempdir::TempDir::new("bisect").wrap_err("creating tempdir")?; let mut cargo_new = Command::new("cargo"); cargo_new @@ -156,12 +161,18 @@ fn run_bisect_for_file( bisect.arg("--timeout").arg("30"); // don't hang bisect.current_dir(&cargo_dir); - bisect.arg("--start").arg(start.to_string()); + bisect.arg("--start").arg(options.start.to_string()); - if let Some(end) = end { + if let Some(end) = options.end { bisect.arg("--end").arg(end.to_string()); } + bisect + .arg("--regress") + .arg(options.kind.as_deref().unwrap_or("ice")); // FIXME Make this configurable + + bisect.env("RUST_LOG", "error"); // overwrite RUST_LOG + let output = bisect.output().wrap_err("spawning cargo-bisect-rustc")?; if output.status.success() { diff --git a/src/main.rs b/src/main.rs index 90d90de..9e2b075 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,6 +97,7 @@ async fn get_bisections(Extension(conn): Extension) -> impl IntoResponse { pub struct Options { start: chrono::NaiveDate, end: Option, + kind: Option, } #[derive(Debug, Serialize)]