fast_rake 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ class FastRake::FastRunner
24
24
  clean_previous_results
25
25
  @start = Time.now
26
26
 
27
- put_w_time %{Started at #{Time.now.strftime("%H:%M:%S")}}
27
+ put_w_time %{Started at #{Time.now.strftime("%H:%M:%S")}, (will run #{@process_count} parallel processes)}
28
28
  at_exit { kill_remaining_children }
29
29
 
30
30
  start_some_children
@@ -1,6 +1,6 @@
1
1
  module FastRake
2
2
  VERSION_MAJOR = 0
3
- VERSION_MINOR = 1
3
+ VERSION_MINOR = 2
4
4
  VERSION_PATCH = 0
5
5
  VERSION = [VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH].join('.')
6
6
  end
data/lib/fast_rake.rb CHANGED
@@ -4,22 +4,45 @@ require 'fast_rake/fast_runner'
4
4
  module FastRake
5
5
  extend Rake::DSL
6
6
 
7
- def self.fast_runner(setup_tasks, run_tasks, fail_fast=true)
8
- fast_runner_task(:two, 2, setup_tasks, run_tasks, fail_fast)
9
- fast_runner_task(:four, 4, setup_tasks, run_tasks, fail_fast)
10
- fast_runner_task(:eight, 8, setup_tasks, run_tasks, fail_fast)
11
- end
12
-
13
- def self.fast_runner_task(name, processes, setup_tasks, run_tasks, fail_fast=true)
14
- desc "Fast test runner for #{processes} cpus"
15
- task name, [:list] => setup_tasks do |t, args|
7
+ def self.fast_runner_task(name, setup_tasks, run_tasks, fail_fast=true, processes=nil)
8
+ desc "Fast test runner for #{name.to_s}"
9
+ task name, [:count, :list] => setup_tasks do |t, args|
16
10
  tasks_to_run = if !args[:list].nil?
17
11
  args[:list].split(' ')
18
12
  else
19
13
  run_tasks
20
14
  end
15
+ if !args[:count].nil? and args[:count].to_i != 0
16
+ processes = args[:count].to_i
17
+ elsif processes.nil?
18
+ processes = _processor_count
19
+ puts "#{processes} processors detected"
20
+ end
21
21
  FastRunner.new(tasks_to_run, processes, fail_fast).run
22
22
  end
23
23
  end
24
24
 
25
+ #stolen from https://github.com/grosser/parallel
26
+ def self._processor_count
27
+ case RbConfig::CONFIG['host_os']
28
+ when /darwin9/
29
+ `hwprefs cpu_count`.to_i
30
+ when /darwin/
31
+ (hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
32
+ when /linux|cygwin/
33
+ `grep -c processor /proc/cpuinfo`.to_i
34
+ when /(open|free)bsd/
35
+ `sysctl -n hw.ncpu`.to_i
36
+ when /mswin|mingw/
37
+ require 'win32ole'
38
+ wmi = WIN32OLE.connect("winmgmts://")
39
+ cpu = wmi.ExecQuery("select NumberOfLogicalProcessors from Win32_Processor")
40
+ cpu.to_enum.first.NumberOfLogicalProcessors
41
+ when /solaris2/
42
+ `psrinfo -p`.to_i # this is physical cpus afaik
43
+ else
44
+ $stderr.puts "Unknown architecture ( #{RbConfig::CONFIG["host_os"]} ) assuming one processor."
45
+ 1
46
+ end
47
+ end
25
48
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_rake
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan Ricketson
@@ -52,7 +52,7 @@ licenses: []
52
52
  post_install_message:
53
53
  rdoc_options:
54
54
  - --title
55
- - fast_rake-0.1.0 Documentation
55
+ - fast_rake-0.2.0 Documentation
56
56
  require_paths:
57
57
  - lib
58
58
  required_ruby_version: !ruby/object:Gem::Requirement