aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/platform')
-rw-r--r--crates/shirabe/src/platform/hhvm_detector.rs11
-rw-r--r--crates/shirabe/src/platform/version.rs84
2 files changed, 74 insertions, 21 deletions
diff --git a/crates/shirabe/src/platform/hhvm_detector.rs b/crates/shirabe/src/platform/hhvm_detector.rs
index b425bfe..4e40a00 100644
--- a/crates/shirabe/src/platform/hhvm_detector.rs
+++ b/crates/shirabe/src/platform/hhvm_detector.rs
@@ -12,13 +12,13 @@ static HHVM_VERSION_CACHE: Mutex<Option<Option<String>>> = Mutex::new(None);
#[derive(Debug)]
pub struct HhvmDetector {
executable_finder: Option<ExecutableFinder>,
- process_executor: Option<ProcessExecutor>,
+ process_executor: Option<std::rc::Rc<std::cell::RefCell<ProcessExecutor>>>,
}
impl HhvmDetector {
pub fn new(
executable_finder: Option<ExecutableFinder>,
- process_executor: Option<ProcessExecutor>,
+ process_executor: Option<std::rc::Rc<std::cell::RefCell<ProcessExecutor>>>,
) -> Self {
Self {
executable_finder,
@@ -50,9 +50,9 @@ impl HhvmDetector {
.get_or_insert_with(ExecutableFinder::new);
let hhvm_path = finder.find("hhvm", None, &[]);
if let Some(hhvm_path) = hhvm_path {
- let executor = self
- .process_executor
- .get_or_insert_with(|| ProcessExecutor::new(None, None));
+ let executor = self.process_executor.get_or_insert_with(|| {
+ std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(None)))
+ });
let mut version_output = shirabe_php_shim::PhpMixed::Null;
let cmd = shirabe_php_shim::PhpMixed::List(
[
@@ -68,6 +68,7 @@ impl HhvmDetector {
.collect(),
);
let exit_code = executor
+ .borrow_mut()
.execute(cmd, Some(&mut version_output), None)
.unwrap_or(1);
if exit_code == 0 {
diff --git a/crates/shirabe/src/platform/version.rs b/crates/shirabe/src/platform/version.rs
index a9566ee..2071d2a 100644
--- a/crates/shirabe/src/platform/version.rs
+++ b/crates/shirabe/src/platform/version.rs
@@ -1,6 +1,7 @@
//! ref: composer/src/Composer/Platform/Version.php
-use shirabe_external_packages::composer::pcre::preg::Preg;
+use indexmap::IndexMap;
+use shirabe_external_packages::composer::pcre::preg::{CaptureKey, Preg};
use shirabe_php_shim::version_compare;
pub struct Version;
@@ -9,51 +10,102 @@ impl Version {
pub fn parse_openssl(openssl_version: &str, is_fips: &mut bool) -> Option<String> {
*is_fips = false;
- let matches = Preg::match_strict_groups(
+ let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
+ if !Preg::match_strict_groups3(
r"^(?P<version>[0-9.]+)(?P<patch>[a-z]{0,2})(?P<suffix>(?:-?(?:dev|pre|alpha|beta|rc|fips)[\d]*)*)(?:-\w+)?(?: \(.+?\))?$",
openssl_version,
- )?;
+ Some(&mut matches),
+ )
+ .unwrap_or(false)
+ {
+ return None;
+ }
+
+ let version = matches
+ .get(&CaptureKey::ByName("version".to_string()))
+ .cloned()
+ .unwrap_or_default();
+ let patch_str = matches
+ .get(&CaptureKey::ByName("patch".to_string()))
+ .cloned()
+ .unwrap_or_default();
+ let suffix_str = matches
+ .get(&CaptureKey::ByName("suffix".to_string()))
+ .cloned()
+ .unwrap_or_default();
- let patch = if version_compare(&matches["version"], "3.0.0", "<") {
+ let patch = if version_compare(&version, "3.0.0", "<") {
format!(
".{}",
- Self::convert_alpha_version_to_int_version(&matches["patch"])
+ Self::convert_alpha_version_to_int_version(&patch_str)
)
} else {
String::new()
};
- *is_fips = matches["suffix"].contains("fips");
- let suffix = format!("-{}", matches["suffix"].trim_start_matches('-'))
+ *is_fips = suffix_str.contains("fips");
+ let suffix = format!("-{}", suffix_str.trim_start_matches('-'))
.replace("-fips", "")
.replace("-pre", "-alpha");
Some(
- format!("{}{}{}", matches["version"], patch, suffix)
+ format!("{}{}{}", 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 mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
+ if !Preg::match_strict_groups3(
+ r"^(?P<major>\d+)(?P<minor>[a-z]*)$",
+ libjpeg_version,
+ Some(&mut matches),
+ )
+ .unwrap_or(false)
+ {
+ return None;
+ }
+ let major = matches
+ .get(&CaptureKey::ByName("major".to_string()))
+ .cloned()
+ .unwrap_or_default();
+ let minor = matches
+ .get(&CaptureKey::ByName("minor".to_string()))
+ .cloned()
+ .unwrap_or_default();
Some(format!(
"{}.{}",
- matches["major"],
- Self::convert_alpha_version_to_int_version(&matches["minor"])
+ major,
+ Self::convert_alpha_version_to_int_version(&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 mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
+ if !Preg::match_strict_groups3(
+ r"^(?P<year>\d{4})(?P<revision>[a-z]*)$",
+ zoneinfo_version,
+ Some(&mut matches),
+ )
+ .unwrap_or(false)
+ {
+ return None;
+ }
+ let year = matches
+ .get(&CaptureKey::ByName("year".to_string()))
+ .cloned()
+ .unwrap_or_default();
+ let revision = matches
+ .get(&CaptureKey::ByName("revision".to_string()))
+ .cloned()
+ .unwrap_or_default();
Some(format!(
"{}.{}",
- matches["year"],
- Self::convert_alpha_version_to_int_version(&matches["revision"])
+ year,
+ Self::convert_alpha_version_to_int_version(&revision)
))
}