diff options
Diffstat (limited to 'crates/shirabe/src/platform')
| -rw-r--r-- | crates/shirabe/src/platform/hhvm_detector.rs | 28 | ||||
| -rw-r--r-- | crates/shirabe/src/platform/mod.rs | 3 | ||||
| -rw-r--r-- | crates/shirabe/src/platform/runtime.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/platform/version.rs | 35 |
4 files changed, 52 insertions, 20 deletions
diff --git a/crates/shirabe/src/platform/hhvm_detector.rs b/crates/shirabe/src/platform/hhvm_detector.rs index 634b724..c6a53cb 100644 --- a/crates/shirabe/src/platform/hhvm_detector.rs +++ b/crates/shirabe/src/platform/hhvm_detector.rs @@ -1,10 +1,10 @@ //! ref: composer/src/Composer/Platform/HhvmDetector.php -use std::sync::Mutex; -use shirabe_external_packages::symfony::process::executable_finder::ExecutableFinder; -use shirabe_php_shim::{defined, HHVM_VERSION}; use crate::util::platform::Platform; use crate::util::process_executor::ProcessExecutor; +use shirabe_external_packages::symfony::process::executable_finder::ExecutableFinder; +use shirabe_php_shim::{HHVM_VERSION, defined}; +use std::sync::Mutex; // None = null (uninitialized), Some(None) = false (not found), Some(Some(v)) = version static HHVM_VERSION_CACHE: Mutex<Option<Option<String>>> = Mutex::new(None); @@ -15,7 +15,10 @@ pub struct HhvmDetector { } impl HhvmDetector { - pub fn new(executable_finder: Option<ExecutableFinder>, process_executor: Option<ProcessExecutor>) -> Self { + pub fn new( + executable_finder: Option<ExecutableFinder>, + process_executor: Option<ProcessExecutor>, + ) -> Self { Self { executable_finder, process_executor, @@ -41,13 +44,24 @@ impl HhvmDetector { if cache.as_ref().unwrap().is_none() && !Platform::is_windows() { *cache = Some(None); - let finder = self.executable_finder.get_or_insert_with(ExecutableFinder::new); + let finder = self + .executable_finder + .get_or_insert_with(ExecutableFinder::new); let hhvm_path = finder.find("hhvm"); if let Some(hhvm_path) = hhvm_path { - let executor = self.process_executor.get_or_insert_with(ProcessExecutor::new); + let executor = self + .process_executor + .get_or_insert_with(ProcessExecutor::new); let mut version_output = String::new(); let exit_code = executor.execute( - &[&hhvm_path, "--php", "-d", "hhvm.jit=0", "-r", "echo HHVM_VERSION;"], + &[ + &hhvm_path, + "--php", + "-d", + "hhvm.jit=0", + "-r", + "echo HHVM_VERSION;", + ], &mut version_output, ); if exit_code == 0 { diff --git a/crates/shirabe/src/platform/mod.rs b/crates/shirabe/src/platform/mod.rs new file mode 100644 index 0000000..35916e5 --- /dev/null +++ b/crates/shirabe/src/platform/mod.rs @@ -0,0 +1,3 @@ +pub mod hhvm_detector; +pub mod runtime; +pub mod version; diff --git a/crates/shirabe/src/platform/runtime.rs b/crates/shirabe/src/platform/runtime.rs index 4c9c3f5..2e04453 100644 --- a/crates/shirabe/src/platform/runtime.rs +++ b/crates/shirabe/src/platform/runtime.rs @@ -19,7 +19,11 @@ impl Runtime { todo!() } - pub fn invoke(&self, callable: Box<dyn Fn(Vec<PhpMixed>) -> PhpMixed>, arguments: Vec<PhpMixed>) -> PhpMixed { + pub fn invoke( + &self, + callable: Box<dyn Fn(Vec<PhpMixed>) -> PhpMixed>, + arguments: Vec<PhpMixed>, + ) -> PhpMixed { todo!() } diff --git a/crates/shirabe/src/platform/version.rs b/crates/shirabe/src/platform/version.rs index 5c64098..a9566ee 100644 --- a/crates/shirabe/src/platform/version.rs +++ b/crates/shirabe/src/platform/version.rs @@ -15,7 +15,10 @@ impl Version { )?; let patch = if version_compare(&matches["version"], "3.0.0", "<") { - format!(".{}", Self::convert_alpha_version_to_int_version(&matches["patch"])) + format!( + ".{}", + Self::convert_alpha_version_to_int_version(&matches["patch"]) + ) } else { String::new() }; @@ -25,25 +28,33 @@ impl Version { .replace("-fips", "") .replace("-pre", "-alpha"); - Some(format!("{}{}{}", matches["version"], patch, suffix).trim_end_matches('-').to_string()) + Some( + format!("{}{}{}", matches["version"], patch, suffix) + .trim_end_matches('-') + .to_string(), + ) } pub fn parse_libjpeg(libjpeg_version: &str) -> Option<String> { - let matches = Preg::match_strict_groups( - r"^(?P<major>\d+)(?P<minor>[a-z]*)$", - libjpeg_version, - )?; + let matches = + Preg::match_strict_groups(r"^(?P<major>\d+)(?P<minor>[a-z]*)$", libjpeg_version)?; - Some(format!("{}.{}", matches["major"], Self::convert_alpha_version_to_int_version(&matches["minor"]))) + Some(format!( + "{}.{}", + matches["major"], + Self::convert_alpha_version_to_int_version(&matches["minor"]) + )) } pub fn parse_zoneinfo_version(zoneinfo_version: &str) -> Option<String> { - let matches = Preg::match_strict_groups( - r"^(?P<year>\d{4})(?P<revision>[a-z]*)$", - zoneinfo_version, - )?; + let matches = + Preg::match_strict_groups(r"^(?P<year>\d{4})(?P<revision>[a-z]*)$", zoneinfo_version)?; - Some(format!("{}.{}", matches["year"], Self::convert_alpha_version_to_int_version(&matches["revision"]))) + Some(format!( + "{}.{}", + matches["year"], + Self::convert_alpha_version_to_int_version(&matches["revision"]) + )) } fn convert_alpha_version_to_int_version(alpha: &str) -> i64 { |
