aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/process
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/process')
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/executable_finder.rs10
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs2
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/process.rs24
3 files changed, 15 insertions, 21 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
index a00a302c..cd7d378f 100644
--- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
@@ -25,9 +25,7 @@ impl ExecutableFinder {
pub fn find(&self, name: &str, default: Option<&str>, extra_dirs: &[String]) -> Option<String> {
// windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes
- if std::path::MAIN_SEPARATOR == '\\'
- && CMD_BUILTINS.contains(&shirabe_php_shim::strtolower(name).as_str())
- {
+ if cfg!(windows) && CMD_BUILTINS.contains(&shirabe_php_shim::strtolower(name).as_str()) {
return Some(name.to_string());
}
@@ -39,7 +37,7 @@ impl ExecutableFinder {
dirs.extend_from_slice(extra_dirs);
let mut suffixes: Vec<String> = vec![];
- if std::path::MAIN_SEPARATOR == '\\' {
+ if cfg!(windows) {
let path_ext =
shirabe_php_shim::getenv("PATHEXT").map(|v| v.to_string_lossy().into_owned());
suffixes = self.suffixes.clone();
@@ -70,7 +68,7 @@ impl ExecutableFinder {
let dir = if dir.is_empty() { "." } else { dir.as_str() };
let file = format!("{dir}{}{name}{suffix}", std::path::MAIN_SEPARATOR);
if shirabe_php_shim::is_file(&file)
- && (std::path::MAIN_SEPARATOR == '\\' || shirabe_php_shim::is_executable(&file))
+ && (cfg!(windows) || shirabe_php_shim::is_executable(&file))
{
return Some(file);
}
@@ -84,7 +82,7 @@ impl ExecutableFinder {
}
}
- if std::path::MAIN_SEPARATOR == '\\'
+ if cfg!(windows)
|| name.len()
!= shirabe_php_shim::strcspn(name, &format!("/{}", std::path::MAIN_SEPARATOR))
{
diff --git a/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs b/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs
index c4236743..cf4f3414 100644
--- a/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs
@@ -17,7 +17,7 @@ pub struct WindowsPipes {
impl WindowsPipes {
pub fn new(_input: PhpMixed) -> Self {
- // Windows-only path: never constructed on POSIX (MAIN_SEPARATOR is '/').
+ // Windows-only path: never constructed on non-Windows targets.
todo!()
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/process/process.rs b/crates/shirabe-external-packages/src/symfony/process/process.rs
index 64ed3a84..3fb3fab2 100644
--- a/crates/shirabe-external-packages/src/symfony/process/process.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/process.rs
@@ -245,7 +245,7 @@ impl Process {
this.set_input(input)?;
this.set_timeout(timeout)?;
- this.use_file_handles = std::path::MAIN_SEPARATOR == '\\';
+ this.use_file_handles = cfg!(windows);
Ok(this)
}
@@ -309,7 +309,7 @@ impl Process {
.collect::<Vec<_>>()
.join(" ");
- if std::path::MAIN_SEPARATOR != '\\' {
+ if !cfg!(windows) {
// exec is mandatory to deal with sending a signal to the process
cmd = format!("exec {}", cmd);
}
@@ -318,7 +318,7 @@ impl Process {
CommandLine::String(s) => self.replace_placeholders(s, &env)?,
};
- if std::path::MAIN_SEPARATOR == '\\' {
+ if cfg!(windows) {
commandline = self.prepare_windows_command_line(&commandline, &mut env)?;
} else if !self.use_file_handles && self.is_sigchild_enabled() {
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
@@ -414,9 +414,8 @@ impl Process {
loop {
self.check_timeout()?;
let running = self.is_running()
- && (std::path::MAIN_SEPARATOR == '\\'
- || self.process_pipes.as_ref().unwrap().are_open());
- self.read_pipes(running, std::path::MAIN_SEPARATOR != '\\' || !running);
+ && (cfg!(windows) || self.process_pipes.as_ref().unwrap().are_open());
+ self.read_pipes(running, !cfg!(windows) || !running);
if !running {
break;
}
@@ -641,7 +640,7 @@ impl Process {
/// Enables or disables the TTY mode.
pub fn set_tty(&mut self, tty: bool) -> anyhow::Result<&mut Self> {
- if std::path::MAIN_SEPARATOR == '\\' && tty {
+ if cfg!(windows) && tty {
return Err(RuntimeException::new(
"TTY mode is not supported on Windows platform.".to_string(),
)
@@ -740,7 +739,7 @@ impl Process {
/// Creates the descriptors needed by the proc_open.
fn get_descriptors(&mut self) -> Vec<Descriptor> {
// TODO(plugin): $this->input instanceof \Iterator -> rewind() is not modeled.
- if std::path::MAIN_SEPARATOR == '\\' {
+ if cfg!(windows) {
self.process_pipes = Some(Box::new(WindowsPipes::new(self.input.clone())));
} else {
self.process_pipes = Some(Box::new(UnixPipes::new(
@@ -813,10 +812,7 @@ impl Process {
}
}
- self.read_pipes(
- running && blocking,
- std::path::MAIN_SEPARATOR != '\\' || !running,
- );
+ self.read_pipes(running && blocking, !cfg!(windows) || !running);
if !self.fallback_status.is_empty() && self.is_sigchild_enabled() {
// processInformation = fallbackStatus + processInformation (fallback keys win)
@@ -996,7 +992,7 @@ impl Process {
Some(pid) => pid,
};
- if std::path::MAIN_SEPARATOR == '\\' {
+ if cfg!(windows) {
let mut output: Vec<String> = Vec::new();
let mut exit_code: i64 = 0;
shirabe_php_shim::exec(
@@ -1189,7 +1185,7 @@ impl Process {
None | Some("") => return "\"\"".to_string(),
Some(a) => a,
};
- if std::path::MAIN_SEPARATOR != '\\' {
+ if !cfg!(windows) {
return format!("'{}'", argument.replace('\'', "'\\''"));
}
let mut argument = argument.to_string();