4
4
5
5
namespace SPC \builder ;
6
6
7
- use SPC \exception \FileSystemException ;
8
- use SPC \exception \RuntimeException ;
7
+ use SPC \exception \EnvironmentException ;
8
+ use SPC \exception \SPCException ;
9
+ use SPC \exception \ValidationException ;
9
10
use SPC \exception \WrongUsageException ;
10
11
use SPC \store \Config ;
11
12
use SPC \store \FileSystem ;
@@ -30,18 +31,18 @@ public function __construct(protected string $name, protected BuilderBase $build
30
31
$ unix_only = Config::getExt ($ this ->name , 'unix-only ' , false );
31
32
$ windows_only = Config::getExt ($ this ->name , 'windows-only ' , false );
32
33
if (PHP_OS_FAMILY !== 'Windows ' && $ windows_only ) {
33
- throw new RuntimeException ("{$ ext_type } extension {$ name } is not supported on Linux and macOS platform " );
34
+ throw new EnvironmentException ("{$ ext_type } extension {$ name } is not supported on Linux and macOS platform " );
34
35
}
35
36
if (PHP_OS_FAMILY === 'Windows ' && $ unix_only ) {
36
- throw new RuntimeException ("{$ ext_type } extension {$ name } is not supported on Windows platform " );
37
+ throw new EnvironmentException ("{$ ext_type } extension {$ name } is not supported on Windows platform " );
37
38
}
38
39
// set source_dir for builtin
39
40
if ($ ext_type === 'builtin ' ) {
40
41
$ this ->source_dir = SOURCE_PATH . '/php-src/ext/ ' . $ this ->name ;
41
42
} elseif ($ ext_type === 'external ' ) {
42
43
$ source = Config::getExt ($ this ->name , 'source ' );
43
44
if ($ source === null ) {
44
- throw new RuntimeException ("{$ ext_type } extension {$ name } source not found " );
45
+ throw new ValidationException ("{$ ext_type } extension {$ name } source not found " , validation_module: " Extension [ { $ name } ] loader " );
45
46
}
46
47
$ source_path = Config::getSource ($ source )['path ' ] ?? null ;
47
48
$ source_path = $ source_path === null ? SOURCE_PATH . '/ ' . $ source : SOURCE_PATH . '/ ' . $ source_path ;
@@ -287,13 +288,12 @@ public function runCliCheckUnix(): void
287
288
{
288
289
// Run compile check if build target is cli
289
290
// If you need to run some check, overwrite this or add your assert in src/globals/ext-tests/{extension_name}.php
290
- // If check failed, throw RuntimeException
291
291
$ sharedExtensions = $ this ->getSharedExtensionLoadString ();
292
292
[$ ret , $ out ] = shell ()->execWithResult (BUILD_BIN_PATH . '/php -n ' . $ sharedExtensions . ' --ri " ' . $ this ->getDistName () . '" ' );
293
293
if ($ ret !== 0 ) {
294
- throw new RuntimeException (
295
- ' extension ' . $ this ->getName () . ' failed runtime check: php-cli returned ' . $ ret . "\n" .
296
- join ( "\n" , $ out )
294
+ throw new ValidationException (
295
+ " extension { $ this ->getName ()} failed compile check: php-cli returned { $ ret}" ,
296
+ validation_module: ' Extension ' . $ this -> getName () . ' sanity check '
297
297
);
298
298
}
299
299
@@ -307,8 +307,10 @@ public function runCliCheckUnix(): void
307
307
308
308
[$ ret , $ out ] = shell ()->execWithResult (BUILD_BIN_PATH . '/php -n ' . $ sharedExtensions . ' -r " ' . trim ($ test ) . '" ' );
309
309
if ($ ret !== 0 ) {
310
- var_dump ($ out );
311
- throw new RuntimeException ('extension ' . $ this ->getName () . ' failed sanity check ' );
310
+ throw new ValidationException (
311
+ "extension {$ this ->getName ()} failed sanity check. Code: {$ ret }, output: " . implode ("\n" , $ out ),
312
+ validation_module: 'Extension ' . $ this ->getName () . ' function check '
313
+ );
312
314
}
313
315
}
314
316
}
@@ -317,10 +319,9 @@ public function runCliCheckWindows(): void
317
319
{
318
320
// Run compile check if build target is cli
319
321
// If you need to run some check, overwrite this or add your assert in src/globals/ext-tests/{extension_name}.php
320
- // If check failed, throw RuntimeException
321
322
[$ ret ] = cmd ()->execWithResult (BUILD_ROOT_PATH . '/bin/php.exe -n --ri " ' . $ this ->getDistName () . '" ' , false );
322
323
if ($ ret !== 0 ) {
323
- throw new RuntimeException ( ' extension ' . $ this ->getName () . ' failed compile check: php-cli returned ' . $ ret );
324
+ throw new ValidationException ( " extension { $ this ->getName ()} failed compile check: php-cli returned { $ ret }" , validation_module: " Extension { $ this -> getName ()} sanity check " );
324
325
}
325
326
326
327
if (file_exists (FileSystem::convertPath (ROOT_DIR . '/src/globals/ext-tests/ ' . $ this ->getName () . '.php ' ))) {
@@ -333,7 +334,10 @@ public function runCliCheckWindows(): void
333
334
334
335
[$ ret ] = cmd ()->execWithResult (BUILD_ROOT_PATH . '/bin/php.exe -n -r " ' . trim ($ test ) . '" ' );
335
336
if ($ ret !== 0 ) {
336
- throw new RuntimeException ('extension ' . $ this ->getName () . ' failed sanity check ' );
337
+ throw new ValidationException (
338
+ "extension {$ this ->getName ()} failed function check " ,
339
+ validation_module: "Extension {$ this ->getName ()} function check "
340
+ );
337
341
}
338
342
}
339
343
}
@@ -348,34 +352,39 @@ public function validate(): void
348
352
*/
349
353
public function buildShared (): void
350
354
{
351
- if (Config::getExt ($ this ->getName (), 'type ' ) === 'builtin ' || Config::getExt ($ this ->getName (), 'build-with-php ' ) === true ) {
352
- if (file_exists (BUILD_MODULES_PATH . '/ ' . $ this ->getName () . '.so ' )) {
353
- logger ()->info ('Shared extension [ ' . $ this ->getName () . '] was already built by php-src/configure ( ' . $ this ->getName () . '.so) ' );
354
- return ;
355
- }
356
- if (Config::getExt ($ this ->getName (), 'build-with-php ' ) === true ) {
357
- logger ()->warning ('Shared extension [ ' . $ this ->getName () . '] did not build with php-src/configure ( ' . $ this ->getName () . '.so) ' );
358
- logger ()->warning ('Try deleting your build and source folders and running `spc build`` again. ' );
359
- return ;
355
+ try {
356
+ if (Config::getExt ($ this ->getName (), 'type ' ) === 'builtin ' || Config::getExt ($ this ->getName (), 'build-with-php ' ) === true ) {
357
+ if (file_exists (BUILD_MODULES_PATH . '/ ' . $ this ->getName () . '.so ' )) {
358
+ logger ()->info ('Shared extension [ ' . $ this ->getName () . '] was already built by php-src/configure ( ' . $ this ->getName () . '.so) ' );
359
+ return ;
360
+ }
361
+ if (Config::getExt ($ this ->getName (), 'build-with-php ' ) === true ) {
362
+ logger ()->warning ('Shared extension [ ' . $ this ->getName () . '] did not build with php-src/configure ( ' . $ this ->getName () . '.so) ' );
363
+ logger ()->warning ('Try deleting your build and source folders and running `spc build`` again. ' );
364
+ return ;
365
+ }
360
366
}
361
- }
362
- if (file_exists (BUILD_MODULES_PATH . '/ ' . $ this ->getName () . '.so ' )) {
363
- logger ()->info ('Shared extension [ ' . $ this ->getName () . '] was already built, skipping ( ' . $ this ->getName () . '.so) ' );
364
- }
365
- logger ()->info ('Building extension [ ' . $ this ->getName () . '] as shared extension ( ' . $ this ->getName () . '.so) ' );
366
- foreach ($ this ->dependencies as $ dependency ) {
367
- if (!$ dependency instanceof Extension) {
368
- continue ;
367
+ if (file_exists (BUILD_MODULES_PATH . '/ ' . $ this ->getName () . '.so ' )) {
368
+ logger ()->info ('Shared extension [ ' . $ this ->getName () . '] was already built, skipping ( ' . $ this ->getName () . '.so) ' );
369
369
}
370
- if (!$ dependency ->isBuildStatic ()) {
371
- logger ()->info ('extension ' . $ this ->getName () . ' requires extension ' . $ dependency ->getName ());
372
- $ dependency ->buildShared ();
370
+ logger ()->info ('Building extension [ ' . $ this ->getName () . '] as shared extension ( ' . $ this ->getName () . '.so) ' );
371
+ foreach ($ this ->dependencies as $ dependency ) {
372
+ if (!$ dependency instanceof Extension) {
373
+ continue ;
374
+ }
375
+ if (!$ dependency ->isBuildStatic ()) {
376
+ logger ()->info ('extension ' . $ this ->getName () . ' requires extension ' . $ dependency ->getName ());
377
+ $ dependency ->buildShared ();
378
+ }
373
379
}
380
+ match (PHP_OS_FAMILY ) {
381
+ 'Darwin ' , 'Linux ' => $ this ->buildUnixShared (),
382
+ default => throw new WrongUsageException (PHP_OS_FAMILY . ' build shared extensions is not supported yet ' ),
383
+ };
384
+ } catch (SPCException $ e ) {
385
+ $ e ->bindExtensionInfo (['extension_name ' => $ this ->getName ()]);
386
+ throw $ e ;
374
387
}
375
- match (PHP_OS_FAMILY ) {
376
- 'Darwin ' , 'Linux ' => $ this ->buildUnixShared (),
377
- default => throw new WrongUsageException (PHP_OS_FAMILY . ' build shared extensions is not supported yet ' ),
378
- };
379
388
}
380
389
381
390
/**
@@ -479,7 +488,7 @@ protected function addLibraryDependency(string $name, bool $optional = false): v
479
488
$ depLib = $ this ->builder ->getLib ($ name );
480
489
if (!$ depLib ) {
481
490
if (!$ optional ) {
482
- throw new RuntimeException ("extension {$ this ->name } requires library {$ name }" );
491
+ throw new WrongUsageException ("extension {$ this ->name } requires library {$ name }" );
483
492
}
484
493
logger ()->info ("enabling {$ this ->name } without library {$ name }" );
485
494
} else {
@@ -492,7 +501,7 @@ protected function addExtensionDependency(string $name, bool $optional = false):
492
501
$ depExt = $ this ->builder ->getExt ($ name );
493
502
if (!$ depExt ) {
494
503
if (!$ optional ) {
495
- throw new RuntimeException ("{$ this ->name } requires extension {$ name }" );
504
+ throw new WrongUsageException ("{$ this ->name } requires extension {$ name } which is not included " );
496
505
}
497
506
logger ()->info ("enabling {$ this ->name } without extension {$ name }" );
498
507
} else {
0 commit comments