Skip to content

Commit 903b4da

Browse files
committed
Merge branch 'es/chainlint-ncores-fix' into maint-2.45
The chainlint script (invoked during "make test") did nothing when it failed to detect the number of available CPUs. It now falls back to 1 CPU to avoid the problem. * es/chainlint-ncores-fix: chainlint.pl: latch CPU count directly reported by /proc/cpuinfo chainlint.pl: fix incorrect CPU count on Linux SPARC chainlint.pl: make CPU count computation more robust
2 parents 2988b82 + 2e7e920 commit 903b4da

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

t/chainlint.pl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,25 @@ sub fd_colors {
716716

717717
sub ncores {
718718
# Windows
719-
return $ENV{NUMBER_OF_PROCESSORS} if exists($ENV{NUMBER_OF_PROCESSORS});
719+
if (exists($ENV{NUMBER_OF_PROCESSORS})) {
720+
my $ncpu = $ENV{NUMBER_OF_PROCESSORS};
721+
return $ncpu > 0 ? $ncpu : 1;
722+
}
720723
# Linux / MSYS2 / Cygwin / WSL
721-
do { local @ARGV='/proc/cpuinfo'; return scalar(grep(/^processor[\s\d]*:/, <>)); } if -r '/proc/cpuinfo';
724+
if (open my $fh, '<', '/proc/cpuinfo') {
725+
my $cpuinfo = do { local $/; <$fh> };
726+
close($fh);
727+
if ($cpuinfo =~ /^n?cpus active\s*:\s*(\d+)/m) {
728+
return $1 if $1 > 0;
729+
}
730+
my @matches = ($cpuinfo =~ /^(processor|CPU)[\s\d]*:/mg);
731+
return @matches ? scalar(@matches) : 1;
732+
}
722733
# macOS & BSD
723-
return qx/sysctl -n hw.ncpu/ if $^O =~ /(?:^darwin$|bsd)/;
734+
if ($^O =~ /(?:^darwin$|bsd)/) {
735+
my $ncpu = qx/sysctl -n hw.ncpu/;
736+
return $ncpu > 0 ? $ncpu : 1;
737+
}
724738
return 1;
725739
}
726740

0 commit comments

Comments
 (0)