|
13 | 13 | use SPC\store\Config; |
14 | 14 | use SPC\store\FileSystem; |
15 | 15 | use SPC\store\pkg\GoXcaddy; |
| 16 | +use SPC\store\SourceManager; |
16 | 17 | use SPC\toolchain\GccNativeToolchain; |
17 | 18 | use SPC\toolchain\ToolchainManager; |
18 | 19 | use SPC\util\DependencyUtil; |
@@ -344,22 +345,70 @@ protected function patchPhpScripts(): void |
344 | 345 | } |
345 | 346 | } |
346 | 347 |
|
| 348 | + /** |
| 349 | + * Process the --with-frankenphp-app option |
| 350 | + * Creates app.tar and app.checksum in source/frankenphp directory |
| 351 | + */ |
| 352 | + protected function processFrankenphpApp(): void |
| 353 | + { |
| 354 | + $frankenphpSourceDir = SOURCE_PATH . '/frankenphp'; |
| 355 | + SourceManager::initSource(['frankenphp'], ['frankenphp']); |
| 356 | + $frankenphpAppPath = $this->getOption('with-frankenphp-app'); |
| 357 | + |
| 358 | + if ($frankenphpAppPath) { |
| 359 | + if (!is_dir($frankenphpAppPath)) { |
| 360 | + throw new WrongUsageException("The path provided to --with-frankenphp-app is not a valid directory: {$frankenphpAppPath}"); |
| 361 | + } |
| 362 | + $appTarPath = $frankenphpSourceDir . '/app.tar'; |
| 363 | + logger()->info("Creating app.tar from {$frankenphpAppPath}"); |
| 364 | + |
| 365 | + shell()->exec('tar -cf ' . escapeshellarg($appTarPath) . ' -C ' . escapeshellarg($frankenphpAppPath) . ' .'); |
| 366 | + |
| 367 | + $checksum = hash_file('md5', $appTarPath); |
| 368 | + file_put_contents($frankenphpSourceDir . '/app_checksum.txt', $checksum); |
| 369 | + } else { |
| 370 | + FileSystem::removeFileIfExists($frankenphpSourceDir . '/app.tar'); |
| 371 | + FileSystem::removeFileIfExists($frankenphpSourceDir . '/app_checksum.txt'); |
| 372 | + file_put_contents($frankenphpSourceDir . '/app.tar', ''); |
| 373 | + file_put_contents($frankenphpSourceDir . '/app_checksum.txt', ''); |
| 374 | + } |
| 375 | + } |
| 376 | + |
| 377 | + protected function getFrankenPHPVersion(): string |
| 378 | + { |
| 379 | + $goModPath = SOURCE_PATH . '/frankenphp/caddy/go.mod'; |
| 380 | + |
| 381 | + if (!file_exists($goModPath)) { |
| 382 | + throw new SPCInternalException("FrankenPHP caddy/go.mod file not found at {$goModPath}, why did we not download FrankenPHP?"); |
| 383 | + } |
| 384 | + |
| 385 | + $content = file_get_contents($goModPath); |
| 386 | + if (preg_match('/github\.com\/dunglas\/frankenphp\s+v?(\d+\.\d+\.\d+)/', $content, $matches)) { |
| 387 | + return $matches[1]; |
| 388 | + } |
| 389 | + |
| 390 | + throw new SPCInternalException('Could not find FrankenPHP version in caddy/go.mod'); |
| 391 | + } |
| 392 | + |
347 | 393 | protected function buildFrankenphp(): void |
348 | 394 | { |
349 | 395 | GlobalEnvManager::addPathIfNotExists(GoXcaddy::getPath()); |
| 396 | + $this->processFrankenphpApp(); |
350 | 397 | $nobrotli = $this->getLib('brotli') === null ? ',nobrotli' : ''; |
351 | 398 | $nowatcher = $this->getLib('watcher') === null ? ',nowatcher' : ''; |
352 | 399 | $xcaddyModules = getenv('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES'); |
353 | | - // make it possible to build from a different frankenphp directory! |
354 | | - if (!str_contains($xcaddyModules, '--with github.com/dunglas/frankenphp')) { |
355 | | - $xcaddyModules = '--with github.com/dunglas/frankenphp ' . $xcaddyModules; |
356 | | - } |
| 400 | + $frankenphpSourceDir = SOURCE_PATH . '/frankenphp'; |
| 401 | + |
| 402 | + $xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp(=\S+)?#', '', $xcaddyModules); |
| 403 | + $xcaddyModules = preg_replace('#--with github.com/dunglas/frankenphp/caddy(=\S+)?#', '', $xcaddyModules); |
| 404 | + $xcaddyModules = "--with github.com/dunglas/frankenphp={$frankenphpSourceDir} " . |
| 405 | + "--with github.com/dunglas/frankenphp/caddy={$frankenphpSourceDir}/caddy {$xcaddyModules}"; |
357 | 406 | if ($this->getLib('brotli') === null && str_contains($xcaddyModules, '--with github.com/dunglas/caddy-cbrotli')) { |
358 | 407 | logger()->warning('caddy-cbrotli module is enabled, but brotli library is not built. Disabling caddy-cbrotli.'); |
359 | 408 | $xcaddyModules = str_replace('--with github.com/dunglas/caddy-cbrotli', '', $xcaddyModules); |
360 | 409 | } |
361 | | - [, $out] = shell()->execWithResult('go list -m github.com/dunglas/frankenphp@latest'); |
362 | | - $frankenPhpVersion = str_replace('github.com/dunglas/frankenphp v', '', $out[0]); |
| 410 | + |
| 411 | + $frankenPhpVersion = $this->getFrankenPHPVersion(); |
363 | 412 | $libphpVersion = $this->getPHPVersion(); |
364 | 413 | $dynamic_exports = ''; |
365 | 414 | if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { |
|
0 commit comments