aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/plugin-stub-generator/generate-stubs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/plugin-stub-generator/generate-stubs')
-rwxr-xr-xscripts/plugin-stub-generator/generate-stubs61
1 files changed, 60 insertions, 1 deletions
diff --git a/scripts/plugin-stub-generator/generate-stubs b/scripts/plugin-stub-generator/generate-stubs
index c6b03c97..934577f3 100755
--- a/scripts/plugin-stub-generator/generate-stubs
+++ b/scripts/plugin-stub-generator/generate-stubs
@@ -7,6 +7,7 @@ require __DIR__ . '/vendor/autoload.php';
use Shirabe\PluginStubGenerator\GenerationError;
use Shirabe\PluginStubGenerator\Generator;
+use Shirabe\PluginStubGenerator\Project;
use Shirabe\PluginStubGenerator\Report;
$repoRoot = dirname(__DIR__, 2);
@@ -39,8 +40,29 @@ foreach (file(__DIR__ . '/targets.list', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY
}
}
+// Hand-written dual-mode classes (php/runtime/) resolve through the same worker autoloader as
+// the generated stubs; the generator must know them so they can serve as stub base classes and
+// so a targets.list entry can never shadow one.
+$runtimeDir = $repoRoot . '/crates/shirabe-php-rpc/php/runtime';
+$runtimeProvided = [];
+$runtimeFiles = [];
+if (is_dir($runtimeDir)) {
+ $iterator = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator($runtimeDir, FilesystemIterator::SKIP_DOTS)
+ );
+ foreach ($iterator as $entry) {
+ if ($entry->isFile() && str_ends_with($entry->getFilename(), '.php')) {
+ $relative = substr($entry->getPathname(), strlen($runtimeDir) + 1);
+ $runtimeFiles[] = $relative;
+ $runtimeProvided[] = str_replace('/', '\\', substr($relative, 0, -strlen('.php')));
+ }
+ }
+}
+sort($runtimeProvided);
+sort($runtimeFiles);
+
try {
- $generator = new Generator($composerRoot, Report::load($reportPath), $targets);
+ $generator = new Generator($composerRoot, Report::load($reportPath), $targets, $runtimeProvided);
$files = $generator->generate();
} catch (GenerationError $e) {
foreach ($e->errors as $error) {
@@ -51,6 +73,38 @@ try {
$problems = [];
+// Handoff classification of Composer\Console\Application's declared properties. The worker-side
+// runtime definition (php/runtime/Composer/Console/Application.php) hands off exactly the state
+// a plugin-visible application exposes; a property the upstream class declares and this table
+// does not know means the handoff decision has not been made, and generation fails so a
+// Composer version bump surfaces it explicitly instead of silently dropping state.
+$applicationPropertyTable = [
+ 'composer' => 'handoff', // carried by __shirabe_console_application_boot
+ 'io' => 'handoff', // the IO seam proxy
+ 'initialWorkingDirectory' => 'handoff', // copied once at boot
+ 'disablePluginsByDefault' => 'handoff', // copied once at boot
+ 'disableScriptsByDefault' => 'handoff', // copied once at boot
+ 'hasPluginCommands' => 'rust-local', // Rust-side runtime state, never shared
+ 'logo' => 'static-config', // static rendering data, the worker never needs it
+];
+$applicationFile = (new Project($composerRoot))->sourceFor('Composer\\Console\\Application');
+$declaredProperties = [];
+foreach ($applicationFile->classLike->getProperties() as $property) {
+ foreach ($property->props as $prop) {
+ $declaredProperties[$prop->name->toString()] = true;
+ }
+}
+foreach ($declaredProperties as $name => $_) {
+ if (!isset($applicationPropertyTable[$name])) {
+ $problems[] = "Composer\\Console\\Application::\$$name is not classified in the handoff property table in generate-stubs";
+ }
+}
+foreach ($applicationPropertyTable as $name => $_) {
+ if (!isset($declaredProperties[$name])) {
+ $problems[] = "the handoff property table in generate-stubs classifies Composer\\Console\\Application::\$$name, which the class no longer declares";
+ }
+}
+
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($stubsDir, FilesystemIterator::SKIP_DOTS)
);
@@ -70,6 +124,11 @@ foreach ($files as $relative => $_) {
$problems[] = "STUB_FILES in $libRs does not embed $relative";
}
}
+foreach ($runtimeFiles as $relative) {
+ if (!str_contains($libRsText, "include_str!(\"../php/runtime/$relative\")")) {
+ $problems[] = "RUNTIME_FILES in $libRs does not embed $relative";
+ }
+}
if ($check) {
foreach ($files as $relative => $content) {