use crate::error::PlatformError;
use rch_common::{
CommandPriority, CommandTimingBreakdown, CompilationKind, RequiredRuntime, SelectionResponse,
ToolchainInfo, WorkerId,
};
use std::io::Read;
use std::path::PathBuf;
#[path = "hook/command_parsing.rs"]
mod command_parsing;
pub(crate) use command_parsing::{
cargo_job_count_for_command, estimate_cores_for_command, extract_project_name,
extract_project_name_with_policy, preferred_workers,
};
pub(crate) fn install_hook_mode_panic_handler() {}
pub async fn run_hook() -> anyhow::Result<()> {
let mut _buf = String::new();
let _ = std::io::stdin().read_to_string(&mut _buf);
Ok(())
}
pub async fn run_exec(
base: Option<String>,
dependency_bases: Vec<String>,
clean_overlay: bool,
overlay_paths: Vec<PathBuf>,
no_overlay: bool,
source_content_receipt: bool,
job: bool,
result_dirs: Vec<PathBuf>,
command_parts: Vec<String>,
_out_ctx: &crate::ui::context::OutputContext,
) -> anyhow::Result<()> {
if clean_overlay
|| base.is_some()
|| !dependency_bases.is_empty()
|| !overlay_paths.is_empty()
|| no_overlay
{
anyhow::bail!("clean-overlay remote execution is not supported on non-Unix clients");
}
if source_content_receipt {
anyhow::bail!("source-content receipts require the Unix rsync transport");
}
if job {
anyhow::bail!("--job remote admission requires the Unix daemon transport");
}
if !result_dirs.is_empty() {
anyhow::bail!("--result-dir requires the Unix rsync transport");
}
let command = command_parts.join(" ");
if command.is_empty() {
anyhow::bail!("No command provided to exec");
}
let status = std::process::Command::new("cmd") .arg("/C")
.arg(&command)
.status()?;
std::process::exit(status.code().unwrap_or(1));
}
pub(crate) async fn query_daemon(
_socket_path: &str,
_project: &str,
_cores: u32,
_command: &str,
_toolchain: Option<&ToolchainInfo>,
_required_runtime: RequiredRuntime,
_command_priority: CommandPriority,
_classification_duration_us: u64,
_hook_pid: Option<u32>,
_local_wrapper_id: Option<&str>,
_wait_for_worker: bool,
_preferred_workers: &[WorkerId],
_job_mode: bool,
) -> anyhow::Result<SelectionResponse> {
Err(PlatformError::UnixSocketUnsupported)?
}
pub(crate) async fn query_daemon_dry_run(
_socket_path: &str,
_project: &str,
_cores: u32,
_command: &str,
_toolchain: Option<&ToolchainInfo>,
_required_runtime: RequiredRuntime,
_preferred_workers: &[WorkerId],
) -> anyhow::Result<SelectionResponse> {
Err(PlatformError::UnixSocketUnsupported)?
}
pub(crate) async fn release_worker(
_socket_path: &str,
_worker_id: &WorkerId,
_slots: u32,
_build_id: Option<u64>,
_exit_code: Option<i32>,
_duration_ms: Option<u64>,
_bytes_transferred: Option<u64>,
_timing: Option<&CommandTimingBreakdown>,
_local_wrapper_id: Option<&str>,
) -> anyhow::Result<()> {
Ok(())
}
pub(crate) fn required_runtime_for_kind(kind: Option<CompilationKind>) -> RequiredRuntime {
match kind {
Some(k) => match k {
CompilationKind::CargoBuild
| CompilationKind::CargoTest
| CompilationKind::CargoCheck
| CompilationKind::CargoClippy
| CompilationKind::CargoDoc
| CompilationKind::CargoNextest
| CompilationKind::CargoBench
| CompilationKind::Rustc => RequiredRuntime::Rust,
CompilationKind::CargoZigbuild => RequiredRuntime::Zig,
CompilationKind::BunTest | CompilationKind::BunTypecheck => RequiredRuntime::Bun,
CompilationKind::NixBuild => RequiredRuntime::Nix,
CompilationKind::GoBuild | CompilationKind::GoTest | CompilationKind::GoVet => {
RequiredRuntime::Go
}
CompilationKind::Tsc => RequiredRuntime::Node,
_ => RequiredRuntime::None,
},
None => RequiredRuntime::None,
}
}