This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
forked from jricketson/fast_rake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast_rake.rb
54 lines (49 loc) · 1.61 KB
/
fast_rake.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true
require 'fast_rake/version'
require 'fast_rake/fast_runner'
module FastRake
extend Rake::DSL
def self.fast_runner_task(name, setup_tasks, run_tasks, fail_fast = true, processes = nil)
desc "Fast test runner for #{name}"
task name, %i[count list] => setup_tasks do |_t, args|
tasks_to_run = if !args[:list].nil?
args[:list].split(' ')
else
run_tasks
end
if !args[:count].nil? && (args[:count].to_i != 0)
processes = args[:count].to_i
elsif processes.nil?
processes = _processor_count
puts "#{processes} processors detected"
end
FastRunner.new(tasks_to_run, processes, fail_fast).run
end
end
# stolen from https://github.com/grosser/parallel
def self._processor_count
case RbConfig::CONFIG['host_os']
when /darwin9/
`hwprefs cpu_count`.to_i
when /darwin/
(_hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
when /linux|cygwin/
`grep -c processor /proc/cpuinfo`.to_i
when /(open|free)bsd/
`sysctl -n hw.ncpu`.to_i
when /mswin|mingw/
require 'win32ole'
wmi = WIN32OLE.connect('winmgmts://')
cpu = wmi.ExecQuery('select NumberOfLogicalProcessors from Win32_Processor')
cpu.to_enum.first.NumberOfLogicalProcessors
when /solaris2/
`psrinfo -p`.to_i # this is physical cpus afaik
else
warn "Unknown architecture ( #{RbConfig::CONFIG['host_os']} ) assuming one processor."
1
end
end
def self._hwprefs_available?
`which hwprefs` != ''
end
end