mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 11:50:51 +00:00
add preload in build
This commit is contained in:
parent
00fcdc1f03
commit
f15648eb05
|
@ -30,6 +30,9 @@ $autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/scoper-auto
|
||||||
$autoloadIncluder->autoloadProjectAutoloaderFile();
|
$autoloadIncluder->autoloadProjectAutoloaderFile();
|
||||||
$autoloadIncluder->autoloadFromCommandLine();
|
$autoloadIncluder->autoloadFromCommandLine();
|
||||||
|
|
||||||
|
// make local php-parser a priority to avoid conflict
|
||||||
|
require_once __DIR__ . '/../preload.php';
|
||||||
|
|
||||||
$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesCaller());
|
$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesCaller());
|
||||||
$symfonyStyle = $symfonyStyleFactory->create();
|
$symfonyStyle = $symfonyStyleFactory->create();
|
||||||
|
|
||||||
|
|
52
build/build-preload.php
Normal file
52
build/build-preload.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// inspired at https://github.com/phpstan/phpstan-src/commit/87897c2a4980d68efa1c46049ac2eefe767ec946#diff-e897e523125a694bd8ea69bf83374c206803c98720c46d7401b7a7cf53915a26
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
|
|
||||||
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
$buildDirectory = $argv[1];
|
||||||
|
|
||||||
|
buildPreloadScript($buildDirectory);
|
||||||
|
|
||||||
|
function buildPreloadScript(string $buildDirectory): void
|
||||||
|
{
|
||||||
|
$vendorDir = $buildDirectory . '/vendor';
|
||||||
|
if (!is_dir($vendorDir . '/nikic/php-parser/lib/PhpParser')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$preloadScript = $buildDirectory . '/preload.php';
|
||||||
|
$template = <<<'php'
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
%s
|
||||||
|
php;
|
||||||
|
$root = realpath(__DIR__ . '/..');
|
||||||
|
if ($root === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$output = '';
|
||||||
|
|
||||||
|
$finder = (new Finder())
|
||||||
|
->files()
|
||||||
|
->name('*.php')
|
||||||
|
->in($vendorDir . '/nikic/php-parser/lib/PhpParser');
|
||||||
|
|
||||||
|
foreach ($finder->getIterator() as $fileInfo) {
|
||||||
|
$realPath = $fileInfo->getRealPath();
|
||||||
|
if ($realPath === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = substr($realPath, strlen($root));
|
||||||
|
$output .= 'require_once __DIR__ . ' . var_export($path, true) . ';' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents($preloadScript, sprintf($template, $output));
|
||||||
|
}
|
|
@ -37,12 +37,14 @@ note "Running scoper to $RESULT_DIRECTORY"
|
||||||
wget https://github.com/humbug/php-scoper/releases/download/0.14.0/php-scoper.phar -N --no-verbose
|
wget https://github.com/humbug/php-scoper/releases/download/0.14.0/php-scoper.phar -N --no-verbose
|
||||||
|
|
||||||
# Work around possible PHP memory limits
|
# Work around possible PHP memory limits
|
||||||
php -d memory_limit=-1 php-scoper.phar add-prefix bin config src packages rules vendor composer.json --output-dir "../$RESULT_DIRECTORY" --config scoper.php --force --ansi --working-dir "$BUILD_DIRECTORY"
|
php -d memory_limit=-1 php-scoper.phar add-prefix preload.php bin config src packages rules vendor composer.json --output-dir "../$RESULT_DIRECTORY" --config scoper.php --force --ansi --working-dir "$BUILD_DIRECTORY"
|
||||||
|
|
||||||
|
|
||||||
# note "Dumping Composer Autoload"
|
# note "Dumping Composer Autoload"
|
||||||
composer dump-autoload --working-dir "$RESULT_DIRECTORY" --ansi --classmap-authoritative --no-dev
|
composer dump-autoload --working-dir "$RESULT_DIRECTORY" --ansi --classmap-authoritative --no-dev
|
||||||
|
|
||||||
|
php "$BUILD_DIRECTORY/build/build-preload.php" $RESULT_DIRECTORY
|
||||||
|
|
||||||
rm -rf "$BUILD_DIRECTORY"
|
rm -rf "$BUILD_DIRECTORY"
|
||||||
|
|
||||||
|
|
||||||
|
|
0
preload.php
Normal file
0
preload.php
Normal file
Loading…
Reference in New Issue
Block a user