aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe')
-rw-r--r--crates/shirabe/src/console/application.rs22
-rw-r--r--crates/shirabe/src/dependency_resolver/generic_rule.rs9
-rw-r--r--crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs9
-rw-r--r--crates/shirabe/src/downloader/path_downloader.rs10
-rw-r--r--crates/shirabe/src/package/comparer/comparer.rs7
-rw-r--r--crates/shirabe/src/package/version/version_selector.rs11
-rw-r--r--crates/shirabe/src/self_update/versions.rs7
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs28
-rw-r--r--crates/shirabe/src/util/stream_context_factory.rs10
-rw-r--r--crates/shirabe/tests/dependency_resolver/rule_test.rs9
-rw-r--r--crates/shirabe/tests/package/version/version_selector_test.rs7
11 files changed, 46 insertions, 83 deletions
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![
("1.2.1".to_string(), "^1.2", None, "foo/bar"),