1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Merge pull request #7633 from M1ke/4x/config-threads

Allow config to define thread count (4.x)
This commit is contained in:
orklah 2022-02-11 13:46:38 +01:00 committed by GitHub
commit 6e2efffa0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -416,6 +416,13 @@ Whether or not to allow `require`/`include` calls in your PHP. Defaults to `true
```
Allows you to hard-code a serializer for Psalm to use when caching data. By default, Psalm uses `ext-igbinary` *if* the version is greater than or equal to 2.0.5, otherwise it defaults to PHP's built-in serializer.
#### threads
```xml
<psalm
threads="[int]"
>
```
Allows you to hard-code the number of threads Psalm will use (similar to `--threads` on the command line). This value will be used in place of detecting threads from the host machine, but will be overridden by using `--threads` or `--debug` (which sets threads to 1) on the command line
## Project settings

View File

@ -584,6 +584,9 @@ class Config
*/
public $internal_stubs = [];
/** @var ?int */
public $threads;
protected function __construct()
{
self::$instance = $this;
@ -1241,6 +1244,10 @@ class Config
}
}
if (isset($config_xml->threads)) {
$config->threads = (int)$config_xml->threads;
}
return $config;
}

View File

@ -246,7 +246,7 @@ final class Psalm
$options['long-progress'] = true;
}
$threads = self::detectThreads($options, $in_ci);
$threads = self::detectThreads($options, $config, $in_ci);
self::emitMacPcreWarning($options, $threads);
@ -909,12 +909,14 @@ final class Psalm
}
}
private static function detectThreads(array $options, bool $in_ci): int
private static function detectThreads(array $options, Config $config, bool $in_ci): int
{
if (isset($options['threads'])) {
$threads = (int)$options['threads'];
} elseif (isset($options['debug']) || $in_ci) {
$threads = 1;
} elseif ($config->threads) {
$threads = $config->threads;
} else {
$threads = max(1, ProjectAnalyzer::getCpuCount() - 1);
}