Skip to content

Commit f047fbd

Browse files
authored
Display the correct number of processes used, when using '--debug'. (#5294)
1 parent b6c48a0 commit f047fbd

4 files changed

Lines changed: 38 additions & 22 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,21 @@ jobs:
436436
cd e2e/bug-14036
437437
composer install
438438
../../bin/phpstan analyze
439+
- script: |
440+
cd e2e/vvv-with-debug
441+
OUTPUT=$(../../bin/phpstan analyze -l 0 -vvv --debug test.php 2>&1)
442+
echo "$OUTPUT"
443+
../bashunit -a not_contains 'Parallel processing scheduler' "$OUTPUT"
444+
- script: |
445+
cd e2e/vvv-with-debug
446+
OUTPUT=$(../../bin/phpstan analyze -l 0 -vvv --debug --configuration parallel.neon test.php 2>&1)
447+
echo "$OUTPUT"
448+
../bashunit -a not_contains 'Parallel processing scheduler' "$OUTPUT"
449+
- script: |
450+
cd e2e/vvv-with-debug
451+
OUTPUT=$(../../bin/phpstan analyze -l 0 -vvv test.php 2>&1)
452+
echo "$OUTPUT"
453+
../bashunit -a contains 'Parallel processing scheduler' "$OUTPUT"
439454
440455
steps:
441456
- name: Harden the runner (Audit all outbound calls)

e2e/vvv-with-debug/parallel.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
parallel:
3+
maximumNumberOfProcesses: 2

e2e/vvv-with-debug/test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

src/Command/AnalyserRunner.php

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,27 @@ public function runAnalyser(
7171
);
7272
}
7373

74-
$schedule = $this->scheduler->scheduleWork($this->cpuCoreCounter->getNumberOfCpuCores(), $files);
75-
$mainScript = null;
76-
if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) {
77-
$mainScript = $_SERVER['argv'][0];
78-
}
74+
if (!$debug && $allowParallel && function_exists('proc_open')) {
75+
$schedule = $this->scheduler->scheduleWork($this->cpuCoreCounter->getNumberOfCpuCores(), $files);
76+
77+
$mainScript = null;
78+
if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) {
79+
$mainScript = $_SERVER['argv'][0];
80+
}
7981

80-
if (
81-
!$debug
82-
&& $allowParallel
83-
&& function_exists('proc_open')
84-
&& $mainScript !== null
85-
&& $schedule->getNumberOfProcesses() > 0
86-
) {
87-
$loop = new StreamSelectLoop();
88-
$result = null;
89-
$promise = $this->parallelAnalyser->analyse($loop, $schedule, $mainScript, $postFileCallback, $projectConfigFile, $tmpFile, $insteadOfFile, $input, null);
90-
$promise->then(static function (AnalyserResult $tmp) use (&$result): void {
91-
$result = $tmp;
92-
});
93-
$loop->run();
94-
if ($result === null) {
95-
throw new ShouldNotHappenException();
82+
if ($mainScript !== null && $schedule->getNumberOfProcesses() > 0) {
83+
$loop = new StreamSelectLoop();
84+
$result = null;
85+
$promise = $this->parallelAnalyser->analyse($loop, $schedule, $mainScript, $postFileCallback, $projectConfigFile, $tmpFile, $insteadOfFile, $input, null);
86+
$promise->then(static function (AnalyserResult $tmp) use (&$result): void {
87+
$result = $tmp;
88+
});
89+
$loop->run();
90+
if ($result === null) {
91+
throw new ShouldNotHappenException();
92+
}
93+
return $result;
9694
}
97-
return $result;
9895
}
9996

10097
return $this->analyser->analyse(

0 commit comments

Comments
 (0)