Skip to content

Commit

Permalink
Try to support windows
Browse files Browse the repository at this point in the history
  • Loading branch information
flub committed Dec 14, 2023
1 parent 1011100 commit 7229e33
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ const CARGO_PID_FILE_NAME: &str = "cargo-pid";
/// Whether we are a cargo sub-process.
static CARGO_PID: Lazy<Option<Pid>> = Lazy::new(cargo_pid);

#[cfg(target_family == "unix")]
const CARGO_NAME: &str = "cargo";

#[cfg(target_family == "unix")]
const NEXTEST_NAME: &str = "cargo-nextest";

#[cfg(target_family == "windows")]
const CARGO_NAME: &str = "cargo.exe";

#[cfg(target_family == "windows")]
const NEXTEST_NAME: &str = "cargo-nextest.exe";

/// Returns the process ID of our parent Cargo process.
///
/// If our parent process is not Cargo, `None` is returned.
Expand All @@ -43,7 +55,7 @@ fn cargo_pid() -> Option<Pid> {
let parent = sys.process(ppid)?;
let parent_exe = parent.exe();
let parent_file_name = dbg!(parent_exe.file_name()?);
if parent_file_name == OsStr::new("cargo") || parent_file_name == OsStr::new("cargo-nextest") {
if parent_file_name == OsStr::new(CARGO_NAME) || parent_file_name == OsStr::new(NEXTEST_NAME) {
Some(parent.pid())
} else if parent_file_name == OsStr::new("rustdoc") {
let ppid = parent.parent()?;
Expand Down

0 comments on commit 7229e33

Please sign in to comment.