mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
aa2403e2eb
## Why `codex-core` was re-exporting APIs owned by sibling `codex-*` crates, which made downstream crates depend on `codex-core` as a proxy module instead of the actual owner crate. Removing those forwards makes crate boundaries explicit and lets leaf crates drop unnecessary `codex-core` dependencies. In this PR, this reduces the dependency on `codex-core` to `codex-login` in the following files: ``` codex-rs/backend-client/Cargo.toml codex-rs/mcp-server/tests/common/Cargo.toml ``` ## What - Remove `codex-rs/core/src/lib.rs` re-exports for symbols owned by `codex-login`, `codex-mcp`, `codex-rollout`, `codex-analytics`, `codex-protocol`, `codex-shell-command`, `codex-sandboxing`, `codex-tools`, and `codex-utils-path`. - Delete the `default_client` forwarding shim in `codex-rs/core`. - Update in-crate and downstream callsites to import directly from the owning `codex-*` crate. - Add direct Cargo dependencies where callsites now target the owner crate, and remove `codex-core` from `codex-rs/backend-client`.
60 lines
1.7 KiB
Rust
60 lines
1.7 KiB
Rust
use std::ffi::OsStr;
|
|
|
|
/// Returns true if the current process is running under WSL.
|
|
pub use codex_utils_path::env::is_wsl;
|
|
|
|
/// Convert a Windows absolute path (`C:\foo\bar` or `C:/foo/bar`) to a WSL mount path (`/mnt/c/foo/bar`).
|
|
/// Returns `None` if the input does not look like a Windows drive path.
|
|
pub fn win_path_to_wsl(path: &str) -> Option<String> {
|
|
let bytes = path.as_bytes();
|
|
if bytes.len() < 3
|
|
|| bytes[1] != b':'
|
|
|| !(bytes[2] == b'\\' || bytes[2] == b'/')
|
|
|| !bytes[0].is_ascii_alphabetic()
|
|
{
|
|
return None;
|
|
}
|
|
let drive = (bytes[0] as char).to_ascii_lowercase();
|
|
let tail = path[3..].replace('\\', "/");
|
|
if tail.is_empty() {
|
|
return Some(format!("/mnt/{drive}"));
|
|
}
|
|
Some(format!("/mnt/{drive}/{tail}"))
|
|
}
|
|
|
|
/// If under WSL and given a Windows-style path, return the equivalent `/mnt/<drive>/…` path.
|
|
/// Otherwise returns the input unchanged.
|
|
pub fn normalize_for_wsl<P: AsRef<OsStr>>(path: P) -> String {
|
|
let value = path.as_ref().to_string_lossy().to_string();
|
|
if !is_wsl() {
|
|
return value;
|
|
}
|
|
if let Some(mapped) = win_path_to_wsl(&value) {
|
|
return mapped;
|
|
}
|
|
value
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn win_to_wsl_basic() {
|
|
assert_eq!(
|
|
win_path_to_wsl(r"C:\Temp\codex.zip").as_deref(),
|
|
Some("/mnt/c/Temp/codex.zip")
|
|
);
|
|
assert_eq!(
|
|
win_path_to_wsl("D:/Work/codex.tgz").as_deref(),
|
|
Some("/mnt/d/Work/codex.tgz")
|
|
);
|
|
assert!(win_path_to_wsl("/home/user/codex").is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn normalize_is_noop_on_unix_paths() {
|
|
assert_eq!(normalize_for_wsl("/home/u/x"), "/home/u/x");
|
|
}
|
|
}
|