|
12 | 12 | use StaticPHP\DI\ApplicationContext; |
13 | 13 | use StaticPHP\Exception\WrongUsageException; |
14 | 14 | use StaticPHP\Registry\PackageLoader; |
| 15 | +use StaticPHP\Runtime\SystemTarget; |
15 | 16 | use StaticPHP\Util\DependencyResolver; |
16 | 17 | use StaticPHP\Util\FileSystem; |
17 | 18 | use StaticPHP\Util\InteractiveTerm; |
@@ -133,6 +134,9 @@ public function run(bool $interactive = true, bool $disable_delay_msg = false): |
133 | 134 | echo PHP_EOL; |
134 | 135 | } |
135 | 136 |
|
| 137 | + // Early validation: check if packages can be built or installed before downloading |
| 138 | + $this->validatePackagesBeforeBuild(); |
| 139 | + |
136 | 140 | // check download |
137 | 141 | if ($this->download) { |
138 | 142 | $downloaderOptions = DownloaderOptions::extractFromConsoleOptions($this->options, 'dl'); |
@@ -199,8 +203,6 @@ public function run(bool $interactive = true, bool $disable_delay_msg = false): |
199 | 203 | if ($interactive) { |
200 | 204 | InteractiveTerm::finish('Built package: ' . ConsoleColor::green($package->getName()) . ($status === SPC_STATUS_ALREADY_BUILT ? ' (already built, skipped)' : '')); |
201 | 205 | } |
202 | | - } elseif ($package->getType() === 'library') { |
203 | | - throw new WrongUsageException("Package '{$package->getName()}' cannot be installed: no build stage defined and no binary artifact available for current OS."); |
204 | 206 | } |
205 | 207 | } |
206 | 208 | } |
@@ -535,6 +537,23 @@ private function printArrayInfo(array $info): void |
535 | 537 | } |
536 | 538 | } |
537 | 539 |
|
| 540 | + private function validatePackagesBeforeBuild(): void |
| 541 | + { |
| 542 | + foreach ($this->packages as $package) { |
| 543 | + if ($package->getType() !== 'library') { |
| 544 | + continue; |
| 545 | + } |
| 546 | + $is_to_build = $this->isBuildPackage($package); |
| 547 | + $has_build_stage = $package instanceof LibraryPackage && $package->hasStage('build'); |
| 548 | + $should_use_binary = $package instanceof LibraryPackage && ($package->getArtifact()?->shouldUseBinary() ?? false); |
| 549 | + |
| 550 | + // Check if package can neither be built nor installed |
| 551 | + if (!$is_to_build && !$should_use_binary && !$has_build_stage) { |
| 552 | + throw new WrongUsageException("Package '{$package->getName()}' cannot be installed: no build stage defined and no binary artifact available for current OS: " . SystemTarget::getCurrentPlatformString()); |
| 553 | + } |
| 554 | + } |
| 555 | + } |
| 556 | + |
538 | 557 | private function performAfterInstallActions(Package $package): void |
539 | 558 | { |
540 | 559 | // ----------- perform post-install actions from extracted .package.{pkg_name}.postinstall.json ----------- |
|
0 commit comments