Updated Rector to commit 1869c1dc00

1869c1dc00 [DX] Add --memory-limit option to pass memory limit to parallel subprocesses (#1726)
This commit is contained in:
Tomas Votruba 2022-01-25 11:53:27 +00:00
parent 37ad68b794
commit 538fae2da2
13 changed files with 100 additions and 23 deletions

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'caeeb78f6f8473434b33aa1d818ec90a8c43fc31';
public const PACKAGE_VERSION = '1869c1dc00370ac88497f295fc5782abdb294180';
/**
* @var string
*/
public const RELEASE_DATE = '2022-01-25 11:35:55';
public const RELEASE_DATE = '2022-01-25 11:45:18';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220125\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

View File

@ -48,7 +48,9 @@ final class ConfigurationFactory
$isParallel = $this->parameterProvider->provideBoolParameter(\Rector\Core\Configuration\Option::PARALLEL);
$parallelPort = (string) $input->getOption(\Rector\Core\Configuration\Option::PARALLEL_PORT);
$parallelIdentifier = (string) $input->getOption(\Rector\Core\Configuration\Option::PARALLEL_IDENTIFIER);
return new \Rector\Core\ValueObject\Configuration($isDryRun, $showProgressBar, $shouldClearCache, $outputFormat, $fileExtensions, $paths, $showDiffs, $parallelPort, $parallelIdentifier, $isParallel);
/** @var string|null $memoryLimit */
$memoryLimit = $input->getOption(\Rector\Core\Configuration\Option::MEMORY_LIMIT);
return new \Rector\Core\ValueObject\Configuration($isDryRun, $showProgressBar, $shouldClearCache, $outputFormat, $fileExtensions, $paths, $showDiffs, $parallelPort, $parallelIdentifier, $isParallel, $memoryLimit);
}
private function shouldShowProgressBar(\RectorPrefix20220125\Symfony\Component\Console\Input\InputInterface $input, string $outputFormat) : bool
{

View File

@ -174,4 +174,8 @@ final class Option
* @var string
*/
public const FOLLOW_SYMLINKS = 'follow-symlinks';
/**
* @var string
*/
public const MEMORY_LIMIT = 'memory-limit';
}

View File

@ -31,6 +31,7 @@ abstract class AbstractProcessCommand extends \RectorPrefix20220125\Symfony\Comp
$this->addOption(\Rector\Core\Configuration\Option::NO_PROGRESS_BAR, null, \RectorPrefix20220125\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Hide progress bar. Useful e.g. for nicer CI output.');
$this->addOption(\Rector\Core\Configuration\Option::NO_DIFFS, null, \RectorPrefix20220125\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Hide diffs of changed files. Useful e.g. for nicer CI output.');
$this->addOption(\Rector\Core\Configuration\Option::OUTPUT_FORMAT, null, \RectorPrefix20220125\Symfony\Component\Console\Input\InputOption::VALUE_REQUIRED, 'Select output format', \Rector\ChangesReporting\Output\ConsoleOutputFormatter::NAME);
$this->addOption(\Rector\Core\Configuration\Option::MEMORY_LIMIT, null, \RectorPrefix20220125\Symfony\Component\Console\Input\InputOption::VALUE_REQUIRED, 'Memory limit for process');
$this->addOption(\Rector\Core\Configuration\Option::CLEAR_CACHE, null, \RectorPrefix20220125\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Clear unchaged files cache');
$this->addOption(\Rector\Core\Configuration\Option::PARALLEL_PORT, null, \RectorPrefix20220125\Symfony\Component\Console\Input\InputOption::VALUE_REQUIRED);
$this->addOption(\Rector\Core\Configuration\Option::PARALLEL_IDENTIFIER, null, \RectorPrefix20220125\Symfony\Component\Console\Input\InputOption::VALUE_REQUIRED);

View File

@ -14,6 +14,7 @@ use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Reporting\MissingRectorRulesReporter;
use Rector\Core\StaticReflection\DynamicSourceLocatorDecorator;
use Rector\Core\Util\MemoryLimiter;
use Rector\Core\Validation\EmptyConfigurableRectorChecker;
use Rector\Core\ValueObject\Configuration;
use Rector\Core\ValueObject\ProcessResult;
@ -82,6 +83,11 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
* @var \Symfony\Component\Console\Style\SymfonyStyle
*/
private $symfonyStyle;
/**
* @readonly
* @var \Rector\Core\Util\MemoryLimiter
*/
private $memoryLimiter;
/**
* @var RectorInterface[]
* @readonly
@ -90,7 +96,7 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
/**
* @param RectorInterface[] $rectors
*/
public function __construct(\Rector\Core\Autoloading\AdditionalAutoloader $additionalAutoloader, \Rector\Caching\Detector\ChangedFilesDetector $changedFilesDetector, \Rector\Core\Reporting\MissingRectorRulesReporter $missingRectorRulesReporter, \Rector\Core\Application\ApplicationFileProcessor $applicationFileProcessor, \Rector\Core\Autoloading\BootstrapFilesIncluder $bootstrapFilesIncluder, \Rector\Core\ValueObjectFactory\ProcessResultFactory $processResultFactory, \Rector\Core\StaticReflection\DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, \Rector\VersionBonding\Application\MissedRectorDueVersionChecker $missedRectorDueVersionChecker, \Rector\Core\Validation\EmptyConfigurableRectorChecker $emptyConfigurableRectorChecker, \Rector\Core\Console\Output\OutputFormatterCollector $outputFormatterCollector, \RectorPrefix20220125\Symfony\Component\Console\Style\SymfonyStyle $symfonyStyle, array $rectors)
public function __construct(\Rector\Core\Autoloading\AdditionalAutoloader $additionalAutoloader, \Rector\Caching\Detector\ChangedFilesDetector $changedFilesDetector, \Rector\Core\Reporting\MissingRectorRulesReporter $missingRectorRulesReporter, \Rector\Core\Application\ApplicationFileProcessor $applicationFileProcessor, \Rector\Core\Autoloading\BootstrapFilesIncluder $bootstrapFilesIncluder, \Rector\Core\ValueObjectFactory\ProcessResultFactory $processResultFactory, \Rector\Core\StaticReflection\DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator, \Rector\VersionBonding\Application\MissedRectorDueVersionChecker $missedRectorDueVersionChecker, \Rector\Core\Validation\EmptyConfigurableRectorChecker $emptyConfigurableRectorChecker, \Rector\Core\Console\Output\OutputFormatterCollector $outputFormatterCollector, \RectorPrefix20220125\Symfony\Component\Console\Style\SymfonyStyle $symfonyStyle, \Rector\Core\Util\MemoryLimiter $memoryLimiter, array $rectors)
{
$this->additionalAutoloader = $additionalAutoloader;
$this->changedFilesDetector = $changedFilesDetector;
@ -103,6 +109,7 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
$this->emptyConfigurableRectorChecker = $emptyConfigurableRectorChecker;
$this->outputFormatterCollector = $outputFormatterCollector;
$this->symfonyStyle = $symfonyStyle;
$this->memoryLimiter = $memoryLimiter;
$this->rectors = $rectors;
parent::__construct();
}
@ -119,6 +126,7 @@ final class ProcessCommand extends \Rector\Core\Console\Command\AbstractProcessC
return $exitCode;
}
$configuration = $this->configurationFactory->createFromInput($input);
$this->memoryLimiter->adjust($configuration);
// disable console output in case of json output formatter
if ($configuration->getOutputFormat() === \Rector\ChangesReporting\Output\JsonOutputFormatter::NAME) {
$this->symfonyStyle->setVerbosity(\RectorPrefix20220125\Symfony\Component\Console\Output\OutputInterface::VERBOSITY_QUIET);

View File

@ -8,6 +8,7 @@ use RectorPrefix20220125\Clue\React\NDJson\Encoder;
use RectorPrefix20220125\React\EventLoop\StreamSelectLoop;
use RectorPrefix20220125\React\Socket\ConnectionInterface;
use RectorPrefix20220125\React\Socket\TcpConnector;
use Rector\Core\Util\MemoryLimiter;
use Rector\Parallel\WorkerRunner;
use RectorPrefix20220125\Symfony\Component\Console\Input\InputInterface;
use RectorPrefix20220125\Symfony\Component\Console\Output\OutputInterface;
@ -28,9 +29,15 @@ final class WorkerCommand extends \Rector\Core\Console\Command\AbstractProcessCo
* @var \Rector\Parallel\WorkerRunner
*/
private $workerRunner;
public function __construct(\Rector\Parallel\WorkerRunner $workerRunner)
/**
* @readonly
* @var \Rector\Core\Util\MemoryLimiter
*/
private $memoryLimiter;
public function __construct(\Rector\Parallel\WorkerRunner $workerRunner, \Rector\Core\Util\MemoryLimiter $memoryLimiter)
{
$this->workerRunner = $workerRunner;
$this->memoryLimiter = $memoryLimiter;
parent::__construct();
}
protected function configure() : void
@ -42,6 +49,7 @@ final class WorkerCommand extends \Rector\Core\Console\Command\AbstractProcessCo
protected function execute(\RectorPrefix20220125\Symfony\Component\Console\Input\InputInterface $input, \RectorPrefix20220125\Symfony\Component\Console\Output\OutputInterface $output) : int
{
$configuration = $this->configurationFactory->createFromInput($input);
$this->memoryLimiter->adjust($configuration);
$streamSelectLoop = new \RectorPrefix20220125\React\EventLoop\StreamSelectLoop();
$parallelIdentifier = $configuration->getParallelIdentifier();
$tcpConnector = new \RectorPrefix20220125\React\Socket\TcpConnector($streamSelectLoop);

View File

@ -0,0 +1,41 @@
<?php
declare (strict_types=1);
namespace Rector\Core\Util;
use RectorPrefix20220125\Nette\Utils\Strings;
use Rector\Core\ValueObject\Configuration;
use Rector\RectorGenerator\Exception\ConfigurationException;
/**
* @inspiration https://github.com/phpstan/phpstan-src/commit/ccc046ca473dcdb5ce9225cc05d7808f2e327f40
*/
final class MemoryLimiter
{
/**
* @var string
* @see https://regex101.com/r/pmiGUM/1
*/
private const VALID_MEMORY_LIMIT_REGEX = '#^-?\\d+[kMG]?$#i';
public function adjust(\Rector\Core\ValueObject\Configuration $configuration) : void
{
$memoryLimit = $configuration->getMemoryLimit();
if ($memoryLimit === null) {
return;
}
$this->validateMemoryLimitFormat($memoryLimit);
$memorySetResult = \ini_set('memory_limit', $memoryLimit);
if ($memorySetResult === \false) {
$errorMessage = \sprintf('Memory limit "%s" cannot be set.', $memoryLimit);
throw new \Rector\RectorGenerator\Exception\ConfigurationException($errorMessage);
}
}
private function validateMemoryLimitFormat(string $memoryLimit) : void
{
$memoryLimitFormatMatch = \RectorPrefix20220125\Nette\Utils\Strings::match($memoryLimit, self::VALID_MEMORY_LIMIT_REGEX);
if ($memoryLimitFormatMatch !== null) {
return;
}
$errorMessage = \sprintf('Invalid memory limit format "%s".', $memoryLimit);
throw new \Rector\RectorGenerator\Exception\ConfigurationException($errorMessage);
}
}

View File

@ -58,13 +58,19 @@ final class Configuration
* @var bool
*/
private $isParallel = \false;
/**
* @readonly
* @var string|null
*/
private $memoryLimit = null;
/**
* @param string[] $fileExtensions
* @param string[] $paths
* @param string|null $parallelPort
* @param string|null $parallelIdentifier
* @param string|null $memoryLimit
*/
public function __construct(bool $isDryRun = \false, bool $showProgressBar = \true, bool $shouldClearCache = \false, string $outputFormat = \Rector\ChangesReporting\Output\ConsoleOutputFormatter::NAME, array $fileExtensions = ['php'], array $paths = [], bool $showDiffs = \true, $parallelPort = null, $parallelIdentifier = null, bool $isParallel = \false)
public function __construct(bool $isDryRun = \false, bool $showProgressBar = \true, bool $shouldClearCache = \false, string $outputFormat = \Rector\ChangesReporting\Output\ConsoleOutputFormatter::NAME, array $fileExtensions = ['php'], array $paths = [], bool $showDiffs = \true, $parallelPort = null, $parallelIdentifier = null, bool $isParallel = \false, $memoryLimit = null)
{
$this->isDryRun = $isDryRun;
$this->showProgressBar = $showProgressBar;
@ -76,6 +82,7 @@ final class Configuration
$this->parallelPort = $parallelPort;
$this->parallelIdentifier = $parallelIdentifier;
$this->isParallel = $isParallel;
$this->memoryLimit = $memoryLimit;
}
public function isDryRun() : bool
{
@ -123,4 +130,8 @@ final class Configuration
{
return $this->isParallel;
}
public function getMemoryLimit() : ?string
{
return $this->memoryLimit;
}
}

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862::getLoader();
return ComposerAutoloaderInit6a0f5e6211b82304a4250dfb190dadee::getLoader();

View File

@ -1770,6 +1770,7 @@ return array(
'Rector\\Core\\StaticReflection\\SourceLocator\\RenamedClassesSourceLocator' => $baseDir . '/src/StaticReflection/SourceLocator/RenamedClassesSourceLocator.php',
'Rector\\Core\\Stubs\\PHPStanStubLoader' => $baseDir . '/src/Stubs/PHPStanStubLoader.php',
'Rector\\Core\\Template\\DefaultResolver' => $baseDir . '/src/Template/DefaultResolver.php',
'Rector\\Core\\Util\\MemoryLimiter' => $baseDir . '/src/Util/MemoryLimiter.php',
'Rector\\Core\\Util\\PhpVersionFactory' => $baseDir . '/src/Util/PhpVersionFactory.php',
'Rector\\Core\\Util\\StaticRectorStrings' => $baseDir . '/src/Util/StaticRectorStrings.php',
'Rector\\Core\\Util\\StringUtils' => $baseDir . '/src/Util/StringUtils.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862
class ComposerAutoloaderInit6a0f5e6211b82304a4250dfb190dadee
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit6a0f5e6211b82304a4250dfb190dadee', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit6a0f5e6211b82304a4250dfb190dadee', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitd3faf3b21f2dcfec88f6af350c08c862::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit6a0f5e6211b82304a4250dfb190dadee::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitd3faf3b21f2dcfec88f6af350c08c862::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit6a0f5e6211b82304a4250dfb190dadee::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequired3faf3b21f2dcfec88f6af350c08c862($fileIdentifier, $file);
composerRequire6a0f5e6211b82304a4250dfb190dadee($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862
* @param string $file
* @return void
*/
function composerRequired3faf3b21f2dcfec88f6af350c08c862($fileIdentifier, $file)
function composerRequire6a0f5e6211b82304a4250dfb190dadee($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitd3faf3b21f2dcfec88f6af350c08c862
class ComposerStaticInit6a0f5e6211b82304a4250dfb190dadee
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -2165,6 +2165,7 @@ class ComposerStaticInitd3faf3b21f2dcfec88f6af350c08c862
'Rector\\Core\\StaticReflection\\SourceLocator\\RenamedClassesSourceLocator' => __DIR__ . '/../..' . '/src/StaticReflection/SourceLocator/RenamedClassesSourceLocator.php',
'Rector\\Core\\Stubs\\PHPStanStubLoader' => __DIR__ . '/../..' . '/src/Stubs/PHPStanStubLoader.php',
'Rector\\Core\\Template\\DefaultResolver' => __DIR__ . '/../..' . '/src/Template/DefaultResolver.php',
'Rector\\Core\\Util\\MemoryLimiter' => __DIR__ . '/../..' . '/src/Util/MemoryLimiter.php',
'Rector\\Core\\Util\\PhpVersionFactory' => __DIR__ . '/../..' . '/src/Util/PhpVersionFactory.php',
'Rector\\Core\\Util\\StaticRectorStrings' => __DIR__ . '/../..' . '/src/Util/StaticRectorStrings.php',
'Rector\\Core\\Util\\StringUtils' => __DIR__ . '/../..' . '/src/Util/StringUtils.php',
@ -3878,9 +3879,9 @@ class ComposerStaticInitd3faf3b21f2dcfec88f6af350c08c862
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitd3faf3b21f2dcfec88f6af350c08c862::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd3faf3b21f2dcfec88f6af350c08c862::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitd3faf3b21f2dcfec88f6af350c08c862::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit6a0f5e6211b82304a4250dfb190dadee::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6a0f5e6211b82304a4250dfb190dadee::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6a0f5e6211b82304a4250dfb190dadee::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220125\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862', false) && !interface_exists('ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862', false) && !trait_exists('ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862', false)) {
spl_autoload_call('RectorPrefix20220125\ComposerAutoloaderInitd3faf3b21f2dcfec88f6af350c08c862');
if (!class_exists('ComposerAutoloaderInit6a0f5e6211b82304a4250dfb190dadee', false) && !interface_exists('ComposerAutoloaderInit6a0f5e6211b82304a4250dfb190dadee', false) && !trait_exists('ComposerAutoloaderInit6a0f5e6211b82304a4250dfb190dadee', false)) {
spl_autoload_call('RectorPrefix20220125\ComposerAutoloaderInit6a0f5e6211b82304a4250dfb190dadee');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20220125\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -71,9 +71,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220125\print_node(...func_get_args());
}
}
if (!function_exists('composerRequired3faf3b21f2dcfec88f6af350c08c862')) {
function composerRequired3faf3b21f2dcfec88f6af350c08c862() {
return \RectorPrefix20220125\composerRequired3faf3b21f2dcfec88f6af350c08c862(...func_get_args());
if (!function_exists('composerRequire6a0f5e6211b82304a4250dfb190dadee')) {
function composerRequire6a0f5e6211b82304a4250dfb190dadee() {
return \RectorPrefix20220125\composerRequire6a0f5e6211b82304a4250dfb190dadee(...func_get_args());
}
}
if (!function_exists('scanPath')) {