diff options
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | crates/shirabe-class-map-generator/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/shirabe-class-map-generator/src/php_file_parser.rs | 11 | ||||
| -rw-r--r-- | crates/shirabe-php-rpc/src/lib.rs | 75 | ||||
| -rw-r--r-- | crates/shirabe-php-shim/src/runtime.rs | 11 | ||||
| -rw-r--r-- | crates/shirabe-symfony-process/src/process.rs | 25 | ||||
| -rw-r--r-- | crates/shirabe/src/console/application.rs | 22 | ||||
| -rw-r--r-- | crates/shirabe/src/dependency_resolver/generic_rule.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/path_downloader.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/package/comparer/comparer.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/src/package/version/version_selector.rs | 11 | ||||
| -rw-r--r-- | crates/shirabe/src/self_update/versions.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/src/util/remote_filesystem.rs | 28 | ||||
| -rw-r--r-- | crates/shirabe/src/util/stream_context_factory.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/tests/dependency_resolver/rule_test.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/tests/package/version/version_selector_test.rs | 7 |
17 files changed, 109 insertions, 144 deletions
@@ -2128,6 +2128,7 @@ dependencies = [ "anyhow", "indexmap", "shirabe-pcre", + "shirabe-php-rpc", "shirabe-php-shim", "shirabe-symfony-finder", ] diff --git a/crates/shirabe-class-map-generator/Cargo.toml b/crates/shirabe-class-map-generator/Cargo.toml index b34a1406..4d66ac00 100644 --- a/crates/shirabe-class-map-generator/Cargo.toml +++ b/crates/shirabe-class-map-generator/Cargo.toml @@ -9,6 +9,7 @@ license.workspace = true [dependencies] shirabe-pcre.workspace = true +shirabe-php-rpc.workspace = true shirabe-php-shim.workspace = true shirabe-symfony-finder.workspace = true anyhow.workspace = true diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs index f71b993a..0c82a558 100644 --- a/crates/shirabe-class-map-generator/src/php_file_parser.rs +++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs @@ -4,8 +4,8 @@ use crate::php_file_cleaner::PhpFileCleaner; use indexmap::IndexMap; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ - PHP_EOL, PHP_VERSION_ID, RuntimeException, file_exists, file_get_contents, function_exists, - is_file, is_readable, ltrim, php_strip_whitespace, str_replace_array, strrpos, substr, trim, + PHP_EOL, RuntimeException, file_exists, file_get_contents, function_exists, is_file, + is_readable, ltrim, php_strip_whitespace, str_replace_array, strrpos, substr, trim, }; use std::sync::OnceLock; @@ -176,10 +176,9 @@ impl PhpFileParser { EXTRA_TYPES.get_or_init(|| { let mut extra_types = String::new(); let mut extra_types_array: Vec<String> = vec![]; - // TODO(php-runtime): whether `enum` is scanned for belongs to the runtime that loads - // the generated class map, i.e. the worker, while PHP_VERSION_ID is the version this - // build models. PHP also scans for enums on HHVM 3.3 and above. - if PHP_VERSION_ID >= 80100 { + // TODO(port): PHP also scans for enums on HHVM 3.3 and above + // (`defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')`). + if shirabe_php_rpc::get_php_version().version_id >= 80100 { extra_types += "|enum"; extra_types_array = vec!["enum".to_string()]; } diff --git a/crates/shirabe-php-rpc/src/lib.rs b/crates/shirabe-php-rpc/src/lib.rs index e5234ecd..f95a9d45 100644 --- a/crates/shirabe-php-rpc/src/lib.rs +++ b/crates/shirabe-php-rpc/src/lib.rs @@ -16,20 +16,38 @@ use std::os::unix::net::UnixStream; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{LazyLock, Mutex, OnceLock}; -/// PHP `\PHP_VERSION`. -pub fn get_php_version() -> String { - match get_constant("PHP_VERSION") { - PhpMixed::String(s) => s, - other => panic!("PHP RPC: PHP_VERSION constant did not resolve to a string: {other:?}"), - } +/// The version constants of the PHP the worker runs. +#[derive(Debug)] +pub struct PhpVersion { + /// `\PHP_VERSION`. + pub version: String, + /// `\PHP_VERSION_ID`. + pub version_id: i64, + /// `\PHP_MAJOR_VERSION`. + pub major: i64, + /// `\PHP_MINOR_VERSION`. + pub minor: i64, + /// `\PHP_RELEASE_VERSION`. + pub release: i64, +} + +static PHP_VERSION: OnceLock<PhpVersion> = OnceLock::new(); + +/// The PHP version the worker runs. The worker is queried once per process; subsequent calls +/// reuse the cached constants. +pub fn get_php_version() -> &'static PhpVersion { + PHP_VERSION.get_or_init(|| PhpVersion { + version: string_constant("PHP_VERSION"), + version_id: int_constant("PHP_VERSION_ID"), + major: int_constant("PHP_MAJOR_VERSION"), + minor: int_constant("PHP_MINOR_VERSION"), + release: int_constant("PHP_RELEASE_VERSION"), + }) } /// PHP `\PHP_BINARY`. pub fn get_php_binary() -> String { - match get_constant("PHP_BINARY") { - PhpMixed::String(s) => s, - other => panic!("PHP RPC: PHP_BINARY constant did not resolve to a string: {other:?}"), - } + string_constant("PHP_BINARY") } /// PHP `constant($name)`. @@ -37,6 +55,20 @@ fn get_constant(name: &str) -> PhpMixed { call("constant", name) } +fn string_constant(name: &str) -> String { + match get_constant(name) { + PhpMixed::String(s) => s, + other => panic!("PHP RPC: {name} constant did not resolve to a string: {other:?}"), + } +} + +fn int_constant(name: &str) -> i64 { + match get_constant(name) { + PhpMixed::Int(n) => n, + other => panic!("PHP RPC: {name} constant did not resolve to an int: {other:?}"), + } +} + /// `curl_version()`, together with the `CURL_*` constants the `diagnose` command consults. Every /// `Option` field is `None` when the corresponding array key or constant is absent. #[derive(Debug)] @@ -1237,7 +1269,7 @@ mod tests { } let diagnostics = get_diagnostics(); - assert_eq!(diagnostics.php_version, get_php_version()); + assert_eq!(diagnostics.php_version, get_php_version().version); assert!(diagnostics.php_version_id >= 70205); let php_binary = get_php_binary(); assert_eq!(diagnostics.php_binary.as_deref(), Some(php_binary.as_str())); @@ -1257,15 +1289,20 @@ mod tests { return; } - let version = get_php_version(); - assert!(!version.is_empty(), "expected a PHP version"); - assert!( - version + let php = get_php_version(); + assert!(!php.version.is_empty(), "expected a PHP version"); + assert_eq!( + php.version .split('.') .next() - .and_then(|n| n.parse::<u32>().ok()) - .is_some(), - "version should start with a number: {version}", + .and_then(|n| n.parse::<i64>().ok()), + Some(php.major), + "version should start with the major version: {}", + php.version, + ); + assert_eq!( + php.version_id, + php.major * 10000 + php.minor * 100 + php.release ); let binary = get_php_binary(); @@ -1292,7 +1329,7 @@ mod tests { ); assert_eq!( platform_info.get_extension_version("Core"), - get_php_version() + get_php_version().version ); assert!(platform_info.has_constant("PHP_VERSION", None)); diff --git a/crates/shirabe-php-shim/src/runtime.rs b/crates/shirabe-php-shim/src/runtime.rs index 286343b4..6fba5774 100644 --- a/crates/shirabe-php-shim/src/runtime.rs +++ b/crates/shirabe-php-shim/src/runtime.rs @@ -2,17 +2,6 @@ use crate::PhpMixed; use indexmap::IndexMap; use shirabe_php_src::standard::versioning::php_version_compare; -pub const PHP_VERSION_ID: i64 = 80100; -pub const PHP_VERSION: &str = "8.1.0"; - -pub const PHP_MAJOR_VERSION: i64 = 8; -pub const PHP_MINOR_VERSION: i64 = 1; -pub const PHP_RELEASE_VERSION: i64 = 0; - -pub const PHP_WINDOWS_VERSION_MAJOR: i64 = 0; -pub const PHP_WINDOWS_VERSION_MINOR: i64 = 0; -pub const PHP_WINDOWS_VERSION_BUILD: i64 = 0; - pub const E_ALL: i64 = 32767; pub const E_WARNING: i64 = 2; pub const E_NOTICE: i64 = 8; diff --git a/crates/shirabe-symfony-process/src/process.rs b/crates/shirabe-symfony-process/src/process.rs index b7459d41..87c6c68d 100644 --- a/crates/shirabe-symfony-process/src/process.rs +++ b/crates/shirabe-symfony-process/src/process.rs @@ -62,7 +62,6 @@ pub struct Process { options: IndexMap<String, PhpMixed>, process_pipes: Option<Box<dyn PipesInterface>>, latest_signal: Option<i64>, - cached_exit_code: Option<i64>, /// Test-only mock state. `None` in production; set via [`Process::__mock`] in tests. mock: Option<ProcessMock>, } @@ -189,7 +188,6 @@ impl Process { options, process_pipes: None, latest_signal: None, - cached_exit_code: None, mock: None, } } @@ -745,29 +743,6 @@ impl Process { .map(shirabe_php_shim::php_truthy) .unwrap_or(false); - // In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. - if shirabe_php_shim::PHP_VERSION_ID < 80300 { - let exitcode = self - .process_information - .as_ref() - .unwrap() - .get("exitcode") - .and_then(|v| v.as_int()); - if self.cached_exit_code.is_none() && !running && exitcode != Some(-1) { - self.cached_exit_code = exitcode; - } - - if let Some(cached) = self.cached_exit_code - && !running - && exitcode == Some(-1) - { - self.process_information - .as_mut() - .unwrap() - .insert("exitcode".to_string(), PhpMixed::Int(cached)); - } - } - self.read_pipes(running && blocking, !cfg!(windows) || !running); if !running { diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 1c0f0560..9bb810f7 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -57,13 +57,13 @@ use crate::util::Silencer; use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - LogicException as ShimLogicException, PHP_VERSION, PHP_VERSION_ID, PhpMixed, RuntimeException, - bin2hex, chdir, date_default_timezone_get, date_default_timezone_set, defined, dirname, - disk_free_space, extension_loaded, file_exists, file_get_contents, file_put_contents, - function_exists, getcwd, getmypid, glob, ini_set, is_array, is_dir, is_file, is_string, - json_decode, memory_get_peak_usage, memory_get_usage, microtime, php_regex, php_uname, - posix_getuid, random_bytes, realpath, restore_error_handler, round, str_replace, strpos, - strtoupper, sys_get_temp_dir, time, unlink, + LogicException as ShimLogicException, PhpMixed, RuntimeException, bin2hex, chdir, + date_default_timezone_get, date_default_timezone_set, defined, dirname, disk_free_space, + extension_loaded, file_exists, file_get_contents, file_put_contents, function_exists, getcwd, + getmypid, glob, ini_set, is_array, is_dir, is_file, is_string, json_decode, + memory_get_peak_usage, memory_get_usage, microtime, php_regex, php_uname, posix_getuid, + random_bytes, realpath, restore_error_handler, round, str_replace, strpos, strtoupper, + sys_get_temp_dir, time, unlink, }; use shirabe_seld_json_lint::ParsingException; use shirabe_symfony_console::application::Application as BaseApplication; @@ -2262,7 +2262,7 @@ impl ApplicationHandle { "Running {} ({}) with PHP {} on {}", composer::get_version(), composer::RELEASE_DATE, - PHP_VERSION, + shirabe_php_rpc::get_php_version().version, (if function_exists("php_uname") { format!("{} / {}", php_uname("s"), php_uname("r")) } else { @@ -2273,8 +2273,8 @@ impl ApplicationHandle { io_interface::DEBUG, ); - if PHP_VERSION_ID < 70205 { - io.write_error(&format!("<warning>Composer supports PHP 7.2.5 and above, you will most likely encounter problems with your PHP {}. Upgrading is strongly recommended but you can use Composer 2.2.x LTS as a fallback.</warning>", PHP_VERSION)); + if shirabe_php_rpc::get_php_version().version_id < 70205 { + io.write_error(&format!("<warning>Composer supports PHP 7.2.5 and above, you will most likely encounter problems with your PHP {}. Upgrading is strongly recommended but you can use Composer 2.2.x LTS as a fallback.</warning>", shirabe_php_rpc::get_php_version().version)); } if shirabe_php_rpc::xdebug::is_xdebug_active() @@ -2588,7 +2588,7 @@ impl ApplicationHandle { { io.write_error(&format!( "<info>PHP</info> version <comment>{}</comment> ({})", - shirabe_php_rpc::get_php_version(), + shirabe_php_rpc::get_php_version().version, shirabe_php_rpc::get_php_binary(), )); io.write_error( diff --git a/crates/shirabe/src/dependency_resolver/generic_rule.rs b/crates/shirabe/src/dependency_resolver/generic_rule.rs index 3f098f01..8c702d32 100644 --- a/crates/shirabe/src/dependency_resolver/generic_rule.rs +++ b/crates/shirabe/src/dependency_resolver/generic_rule.rs @@ -2,7 +2,7 @@ use super::rule::ReasonData; use crate::dependency_resolver::{Rule, RuleBase}; -use shirabe_php_shim::{PHP_VERSION_ID, RuntimeException, hash_raw}; +use shirabe_php_shim::{RuntimeException, hash_raw}; #[derive(Debug)] pub struct GenericRule { @@ -36,12 +36,7 @@ impl GenericRule { .map(|l| l.to_string()) .collect::<Vec<_>>() .join(","); - let algo = if PHP_VERSION_ID > 80100 { - "xxh3" - } else { - "sha1" - }; - let binary = hash_raw(algo, &joined); + let binary = hash_raw("xxh3", &joined); match binary.get(..4) { Some(chunk) => Ok(i32::from_ne_bytes(chunk.try_into().unwrap()) as i64), None => Err(RuntimeException::new(format!("Failed unpacking: {}", joined)).into()), diff --git a/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs b/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs index d43d9a79..b7f21074 100644 --- a/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs +++ b/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs @@ -1,7 +1,7 @@ //! ref: composer/src/Composer/DependencyResolver/MultiConflictRule.php use crate::dependency_resolver::{ReasonData, Rule, RuleBase}; -use shirabe_php_shim::{PHP_VERSION_ID, RuntimeException, hash_raw}; +use shirabe_php_shim::{RuntimeException, hash_raw}; #[derive(Debug)] pub struct MultiConflictRule { @@ -50,12 +50,7 @@ impl MultiConflictRule { .map(|l| l.to_string()) .collect::<Vec<_>>() .join(","); - let algo = if PHP_VERSION_ID > 80100 { - "xxh3" - } else { - "sha1" - }; - let binary = hash_raw(algo, &format!("c:{}", joined)); + let binary = hash_raw("xxh3", &format!("c:{}", joined)); match binary.get(..4) { Some(chunk) => Ok(i32::from_ne_bytes(chunk.try_into().unwrap()) as i64), None => Err(RuntimeException::new(format!("Failed unpacking: {}", joined)).into()), diff --git a/crates/shirabe/src/downloader/path_downloader.rs b/crates/shirabe/src/downloader/path_downloader.rs index 5fa69ec7..8586de3d 100644 --- a/crates/shirabe/src/downloader/path_downloader.rs +++ b/crates/shirabe/src/downloader/path_downloader.rs @@ -22,8 +22,7 @@ use crate::util::Platform; use crate::util::ProcessExecutor; use indexmap::IndexMap; use shirabe_php_shim::{ - PHP_WINDOWS_VERSION_MAJOR, PHP_WINDOWS_VERSION_MINOR, PhpMixed, RuntimeException, file_exists, - function_exists, impl_php_class, is_dir, realpath, + PhpMixed, RuntimeException, file_exists, function_exists, impl_php_class, is_dir, realpath, }; use shirabe_symfony_filesystem::Filesystem as SymfonyFilesystem; @@ -188,9 +187,10 @@ impl PathDownloader { // The PHP bug was fixed in 7.2.16 and 7.3.3 (requires at least Windows 7). fn safe_junctions(&self) -> bool { // We need to call mklink, and rmdir on Windows 7 (version 6.1) - function_exists("proc_open") - && (PHP_WINDOWS_VERSION_MAJOR > 6 - || (PHP_WINDOWS_VERSION_MAJOR == 6 && PHP_WINDOWS_VERSION_MINOR >= 1)) + // TODO(windows): PHP reads the Windows version off PHP_WINDOWS_VERSION_MAJOR and + // PHP_WINDOWS_VERSION_MINOR, which describe the host rather than PHP; this port has to + // ask the OS for it. + todo!() } } diff --git a/crates/shirabe/src/package/comparer/comparer.rs b/crates/shirabe/src/package/comparer/comparer.rs index b0e01bd8..d18d82b3 100644 --- a/crates/shirabe/src/package/comparer/comparer.rs +++ b/crates/shirabe/src/package/comparer/comparer.rs @@ -140,12 +140,7 @@ impl Comparer { } else if Path::new(&path).is_file() { let size = std::fs::metadata(&path).map(|m| m.len()).unwrap_or(0); if size > 0 { - let algo = if shirabe_php_shim::PHP_VERSION_ID > 80100 { - "xxh3" - } else { - "sha1" - }; - let hash = shirabe_php_shim::hash_file(algo, &path); + let hash = shirabe_php_shim::hash_file("xxh3", &path); array.entry(dir.to_string()).or_default().insert(file, hash); } } diff --git a/crates/shirabe/src/package/version/version_selector.rs b/crates/shirabe/src/package/version/version_selector.rs index 775aadc5..1661c749 100644 --- a/crates/shirabe/src/package/version/version_selector.rs +++ b/crates/shirabe/src/package/version/version_selector.rs @@ -17,10 +17,7 @@ use crate::repository::RepositoryInterface; use crate::repository::RepositorySetInterface; use indexmap::IndexMap; use shirabe_pcre::Preg; -use shirabe_php_shim::{ - CmpOp, PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, php_regex, strtolower, - version_compare, -}; +use shirabe_php_shim::{CmpOp, php_regex, strtolower, version_compare}; use shirabe_semver::constraint::AnyConstraint; use shirabe_semver::constraint::SimpleConstraint; @@ -258,10 +255,8 @@ impl VersionSelector { package: PackageInterfaceHandle, ) -> anyhow::Result<String> { if package.get_name().starts_with("ext-") { - let php_version = format!( - "{}.{}.{}", - PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION - ); + let php = shirabe_php_rpc::get_php_version(); + let php_version = format!("{}.{}.{}", php.major, php.minor, php.release); let package_version = package.get_version(); let ext_parts: Vec<&str> = package_version.splitn(4, '.').collect(); let ext_version = ext_parts[..3.min(ext_parts.len())].join("."); diff --git a/crates/shirabe/src/self_update/versions.rs b/crates/shirabe/src/self_update/versions.rs index 19459e7b..4276c646 100644 --- a/crates/shirabe/src/self_update/versions.rs +++ b/crates/shirabe/src/self_update/versions.rs @@ -7,8 +7,7 @@ use crate::util::HttpDownloader; use indexmap::IndexMap; use shirabe_pcre::Preg; use shirabe_php_shim::{ - InvalidArgumentException, PHP_EOL, PHP_VERSION, PHP_VERSION_ID, PhpMixed, - UnexpectedValueException, php_regex, + InvalidArgumentException, PHP_EOL, PhpMixed, UnexpectedValueException, php_regex, }; pub struct Versions { @@ -133,7 +132,7 @@ impl Versions { for version in list { if let PhpMixed::Array(ref v) = *version { let min_php = v.get("min-php").and_then(|p| p.as_int()).unwrap_or(0); - if min_php <= PHP_VERSION_ID { + if min_php <= shirabe_php_rpc::get_php_version().version_id { return Ok(Ok(v .iter() .map(|(k, val)| (k.clone(), val.clone())) @@ -145,7 +144,7 @@ impl Versions { Ok(Err(UnexpectedValueException::new(format!( "There is no version of Composer available for your PHP version ({})", - PHP_VERSION + shirabe_php_rpc::get_php_version().version )))) } diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index ce24e39a..1f0b1279 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -16,12 +16,12 @@ use indexmap::IndexMap; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PHP_VERSION_ID, PhpMixed, RuntimeException, - STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_PROGRESS, - array_replace_recursive, base64_encode, explode, extension_loaded, file_get_contents, - file_get_contents5, file_put_contents, filter_var_boolean, gethostbyname, - http_clear_last_response_headers, http_get_last_response_headers, ini_get, json_decode, - parse_url, php_regex, preg_quote, strpos, strtolower, strtr, substr, trim, zlib_decode, + PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PhpMixed, RuntimeException, STREAM_NOTIFY_FAILURE, + STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_PROGRESS, array_replace_recursive, base64_encode, + explode, extension_loaded, file_get_contents, file_get_contents5, file_put_contents, + filter_var_boolean, gethostbyname, http_clear_last_response_headers, + http_get_last_response_headers, ini_get, json_decode, parse_url, php_regex, preg_quote, strpos, + strtolower, strtr, substr, trim, zlib_decode, }; /// Result of `RemoteFilesystem::get` — string content, `true` (for copy), or `false`. @@ -723,9 +723,9 @@ impl RemoteFilesystem { ) -> anyhow::Result<Option<String>> { let mut result: Option<String> = None; - if PHP_VERSION_ID >= 80400 { - http_clear_last_response_headers(); - } + // PHP reads the magic `$http_response_header` variable instead before 8.4, which is where + // http_get_last_response_headers() and its companion appeared. + http_clear_last_response_headers(); let mut caught_e: Option<anyhow::Error> = None; // PHP has no scheme branch here: `file_get_contents` reads `file://` URLs and plain @@ -760,14 +760,8 @@ impl RemoteFilesystem { .into()); } - if PHP_VERSION_ID >= 80400 { - *response_headers = http_get_last_response_headers().unwrap_or_default(); - http_clear_last_response_headers(); - } else { - // TODO(http): read the magic `$http_response_header` PHP variable; depends on the - // unmodeled PHP stream layer that populates it. - *response_headers = Vec::new(); - } + *response_headers = http_get_last_response_headers().unwrap_or_default(); + http_clear_last_response_headers(); if let Some(e) = caught_e { return Err(e); diff --git a/crates/shirabe/src/util/stream_context_factory.rs b/crates/shirabe/src/util/stream_context_factory.rs index 7706a5cd..dea964ec 100644 --- a/crates/shirabe/src/util/stream_context_factory.rs +++ b/crates/shirabe/src/util/stream_context_factory.rs @@ -9,8 +9,8 @@ use crate::util::http::ProxyManager; use indexmap::IndexMap; use shirabe_ca_bundle::CaBundle; use shirabe_php_shim::{ - PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, PhpMixed, array_replace_recursive, - extension_loaded, function_exists, php_uname, stream_context_create, stripos, uasort, + PhpMixed, array_replace_recursive, extension_loaded, function_exists, php_uname, + stream_context_create, stripos, uasort, }; pub struct StreamContextFactory; @@ -147,10 +147,8 @@ impl StreamContextFactory { } } - let php_version = format!( - "PHP {}.{}.{}", - PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION - ); + let php = shirabe_php_rpc::get_php_version(); + let php_version = format!("PHP {}.{}.{}", php.major, php.minor, php.release); let http_version = if for_curl { // PHP reports `cURL <version>` here. Shirabe's "curl" transport is backed by reqwest, diff --git a/crates/shirabe/tests/dependency_resolver/rule_test.rs b/crates/shirabe/tests/dependency_resolver/rule_test.rs index 9526bf39..4cd11139 100644 --- a/crates/shirabe/tests/dependency_resolver/rule_test.rs +++ b/crates/shirabe/tests/dependency_resolver/rule_test.rs @@ -7,7 +7,7 @@ use shirabe::dependency_resolver::{ }; use shirabe::package::Link; use shirabe::repository::RepositorySet; -use shirabe_php_shim::{PHP_VERSION_ID, hash_raw}; +use shirabe_php_shim::hash_raw; use shirabe_semver::constraint::MatchAllConstraint; fn root_require_reason() -> ReasonData { @@ -29,12 +29,7 @@ fn generic_rule(literals: Vec<i64>) -> Rule { fn test_get_hash() { let rule = generic_rule(vec![123]); - let algo = if PHP_VERSION_ID > 80100 { - "xxh3" - } else { - "sha1" - }; - let binary = hash_raw(algo, "123"); + let binary = hash_raw("xxh3", "123"); let hash = i32::from_ne_bytes(binary[..4].try_into().unwrap()) as i64; assert_eq!(Some(hash), rule.get_hash().unwrap().as_int()); diff --git a/crates/shirabe/tests/package/version/version_selector_test.rs b/crates/shirabe/tests/package/version/version_selector_test.rs index 8a3e44a5..9792e0bf 100644 --- a/crates/shirabe/tests/package/version/version_selector_test.rs +++ b/crates/shirabe/tests/package/version/version_selector_test.rs @@ -16,7 +16,6 @@ use shirabe::package::version::version_parser::VersionParser; use shirabe::repository::PlatformRepository; use shirabe::repository::RepositorySetInterface; use shirabe_php_shim::PhpMixed; -use shirabe_php_shim::{PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION}; use shirabe_semver::constraint::AnyConstraint; use shirabe_symfony_console::output::output_interface; @@ -535,10 +534,8 @@ fn test_false_returned_on_no_packages() { #[test] fn test_find_recommended_require_version() { - let php_version = format!( - "{}.{}.{}", - PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION - ); + let php = shirabe_php_rpc::get_php_version(); + let php_version = format!("{}.{}.{}", php.major, php.minor, php.release); // real version, expected recommendation, [branch-alias], [pkg name] let cases: Vec<(String, &str, Option<&str>, &str)> = vec