aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-08 03:52:33 +0900
committernsfisis <nsfisis@gmail.com>2026-08-08 10:38:35 +0900
commit0209f63210e5b547b5c6b73367bb80ea86c255ec (patch)
tree6ce0f50f343fc51da0db413278093d63d0a9fe70
parentb4f16a379e919eefc2cb37bcddee589c0f26eaad (diff)
downloadphp-shirabe-0209f63210e5b547b5c6b73367bb80ea86c255ec.tar.gz
php-shirabe-0209f63210e5b547b5c6b73367bb80ea86c255ec.tar.zst
php-shirabe-0209f63210e5b547b5c6b73367bb80ea86c255ec.zip
feat(composer): bake the dev build warning deadline in at build time
Composer defines COMPOSER_DEV_WARNING_TIME from its phar stub when the compiled version is a commit hash rather than a tag, so the value exists only in the build artifact. It was a todo!() in the PHP shim, leaving the warning branch in Application::do_run unreachable. A build script now derives it the way Compiler does, from git describe and the HEAD commit date, and composer::COMPOSER_DEV_WARNING_TIME holds the result as a Rust constant instead of a runtime-defined one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-rw-r--r--crates/shirabe-php-shim/src/runtime.rs6
-rw-r--r--crates/shirabe/build.rs55
-rw-r--r--crates/shirabe/src/composer.rs10
-rw-r--r--crates/shirabe/src/console/application.rs4
-rw-r--r--crates/shirabe/tests/application_test.rs7
5 files changed, 68 insertions, 14 deletions
diff --git a/crates/shirabe-php-shim/src/runtime.rs b/crates/shirabe-php-shim/src/runtime.rs
index 591c7260..05396b3b 100644
--- a/crates/shirabe-php-shim/src/runtime.rs
+++ b/crates/shirabe-php-shim/src/runtime.rs
@@ -455,12 +455,6 @@ pub fn ini_set(_varname: &str, _value: &str) -> Option<String> {
todo!()
}
-pub fn composer_dev_warning_time() -> i64 {
- // TODO(phase-c): COMPOSER_DEV_WARNING_TIME is a build-time constant baked into Composer's release
- // artifact; it has no fixed value in source and must be provided by the build process.
- todo!()
-}
-
pub fn gc_collect_cycles() -> i64 {
// Rust has no cycle collector; nothing is collected.
0
diff --git a/crates/shirabe/build.rs b/crates/shirabe/build.rs
new file mode 100644
index 00000000..22c8be58
--- /dev/null
+++ b/crates/shirabe/build.rs
@@ -0,0 +1,55 @@
+//! ref: composer/src/Composer/Compiler.php
+//!
+//! Generates a constant value of `composer::COMPOSER_DEV_WARNING_TIME`.
+
+fn git(repo_root: &std::path::Path, args: &[&str]) -> Option<String> {
+ let output = std::process::Command::new("git")
+ .args(args)
+ .current_dir(repo_root)
+ .output()
+ .ok()?;
+ if !output.status.success() {
+ return None;
+ }
+ Some(String::from_utf8(output.stdout).ok()?.trim().to_string())
+}
+
+fn main() {
+ println!("cargo::rerun-if-changed=build.rs");
+
+ let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
+ let repo_root = std::path::Path::new(&manifest_dir)
+ .parent()
+ .unwrap()
+ .parent()
+ .unwrap();
+
+ if let Some(git_dir) = git(repo_root, &["rev-parse", "--git-dir"]) {
+ let git_dir = repo_root.join(git_dir);
+ for path in ["HEAD", "packed-refs", "refs/tags"] {
+ let path = git_dir.join(path);
+ if path.exists() {
+ println!("cargo::rerun-if-changed={}", path.display());
+ }
+ }
+ }
+
+ let dev_warning_time =
+ if git(repo_root, &["describe", "--tags", "--exact-match", "HEAD"]).is_some() {
+ None
+ } else {
+ git(repo_root, &["log", "-n1", "--pretty=%ct", "HEAD"])
+ .and_then(|date| date.parse::<i64>().ok())
+ .map(|date| date + 60 * 86400)
+ };
+
+ let out_dir = std::env::var("OUT_DIR").unwrap();
+ std::fs::write(
+ std::path::Path::new(&out_dir).join("dev_warning_time.rs"),
+ match dev_warning_time {
+ Some(time) => format!("Some({time})"),
+ None => "None".to_string(),
+ },
+ )
+ .unwrap();
+}
diff --git a/crates/shirabe/src/composer.rs b/crates/shirabe/src/composer.rs
index 356aefc1..fca19539 100644
--- a/crates/shirabe/src/composer.rs
+++ b/crates/shirabe/src/composer.rs
@@ -21,6 +21,16 @@ pub const RELEASE_DATE: &str = "2026-04-14 13:31:52";
pub const SOURCE_VERSION: &str = "";
pub const RUNTIME_API_VERSION: &str = "2.2.2";
+/// The deadline after which a development build reports itself as outdated, or `None` for a build
+/// made from a tagged revision. Baked in by `build.rs`.
+///
+/// Composer declares this as the global constant COMPOSER_DEV_WARNING_TIME from its phar stub, so
+/// a plugin can read it back with `defined()`/`constant()`. Here it is a Rust constant, and
+/// plugins cannot observe it. Technically speaking, it is incompatible with Composer, but trivial
+/// enough.
+pub const COMPOSER_DEV_WARNING_TIME: Option<i64> =
+ include!(concat!(env!("OUT_DIR"), "/dev_warning_time.rs"));
+
pub fn get_version() -> String {
if VERSION == "@package_version@" {
return SOURCE_VERSION.to_string();
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index 36151563..96f80d9b 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -2301,10 +2301,10 @@ impl ApplicationHandle {
io.write_error("<warning>Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug</warning>");
}
- if defined("COMPOSER_DEV_WARNING_TIME")
+ if let Some(dev_warning_time) = composer::COMPOSER_DEV_WARNING_TIME
&& command_name.as_deref() != Some("self-update")
&& command_name.as_deref() != Some("selfupdate")
- && time() > shirabe_php_shim::composer_dev_warning_time()
+ && time() > dev_warning_time
{
io.write_error(&format!(
"<warning>Warning: This development build of Composer is over 60 days old. It is recommended to update it by running \"{} self-update\" to get the latest version.</warning>",
diff --git a/crates/shirabe/tests/application_test.rs b/crates/shirabe/tests/application_test.rs
index 6ce9166b..794a4352 100644
--- a/crates/shirabe/tests/application_test.rs
+++ b/crates/shirabe/tests/application_test.rs
@@ -1,10 +1,5 @@
//! ref: composer/tests/Composer/Test/ApplicationTest.php
-// These drive the console Application (doRun, command resolution, plugin disabling).
-// The tests exercising do_run's script-command registration (a todo!() pending the
-// Symfony command-registry model), or a runtime define() of COMPOSER_DEV_WARNING_TIME,
-// remain unportable.
-
#[path = "common/bootstrap.rs"]
mod bootstrap;
#[path = "common/test_case.rs"]
@@ -40,7 +35,7 @@ impl Drop for TearDown {
}
}
-#[ignore = "shirabe_php_shim::define is a todo!() (there is no runtime constant registry), so COMPOSER_DEV_WARNING_TIME cannot be defined and defined() — a fixed matches! that omits it — keeps the warning branch unreachable"]
+#[ignore = "the dev warning deadline is a Rust constant baked in by build.rs, so a runtime define() of COMPOSER_DEV_WARNING_TIME cannot make Application take the warning branch"]
#[test]
fn test_dev_warning() {
let _tear_down = TearDown;