fn handle_compile_response()

in src/commands.rs [504:581]


fn handle_compile_response<T>(
    mut creator: T,
    runtime: &mut Runtime,
    conn: &mut ServerConnection,
    response: CompileResponse,
    exe: &Path,
    cmdline: Vec<OsString>,
    cwd: &Path,
    stdout: &mut dyn Write,
    stderr: &mut dyn Write,
) -> Result<i32>
where
    T: CommandCreatorSync,
{
    match response {
        CompileResponse::CompileStarted => {
            debug!("Server sent CompileStarted");
            // Wait for CompileFinished.
            match conn.read_one_response() {
                Ok(Response::CompileFinished(result)) => {
                    return handle_compile_finished(result, stdout, stderr)
                }
                Ok(_) => bail!("unexpected response from server"),
                Err(e) => {
                    match e.downcast_ref::<io::Error>() {
                        Some(io_e) if io_e.kind() == io::ErrorKind::UnexpectedEof => {
                            eprintln!(
                                "sccache: warning: The server looks like it shut down \
                                 unexpectedly, compiling locally instead"
                            );
                        }
                        _ => {
                            //TODO: something better here?
                            if ignore_all_server_io_errors() {
                                eprintln!(
                                    "sccache: warning: error reading compile response from server \
                                     compiling locally instead"
                                );
                            } else {
                                return Err(e)
                                    .context("error reading compile response from server");
                            }
                        }
                    }
                }
            }
        }
        CompileResponse::UnsupportedCompiler(s) => {
            debug!("Server sent UnsupportedCompiler: {:?}", s);
            bail!("Compiler not supported: {:?}", s);
        }
        CompileResponse::UnhandledCompile => {
            debug!("Server sent UnhandledCompile");
        }
    };

    let mut cmd = creator.new_command_sync(exe);
    cmd.args(&cmdline).current_dir(cwd);
    if log_enabled!(Trace) {
        trace!("running command: {:?}", cmd);
    }

    let status = runtime.block_on(async move {
        let child = cmd.spawn().await?;
        child
            .wait()
            .await
            .with_context(|| "failed to wait for a child")
    })?;

    Ok(status.code().unwrap_or_else(|| {
        if let Some(sig) = status_signal(status) {
            println!("sccache: Compile terminated by signal {}", sig);
        }
        // Arbitrary.
        2
    }))
}