diff options
Diffstat (limited to 'lib/rake')
-rw-r--r-- | lib/rake/cpu_counter.rb | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/rake/cpu_counter.rb b/lib/rake/cpu_counter.rb index 6d0b878b19..f29778ed5d 100644 --- a/lib/rake/cpu_counter.rb +++ b/lib/rake/cpu_counter.rb @@ -1,8 +1,3 @@ -require 'rbconfig' - -# TODO: replace with IO.popen using array-style arguments in Rake 11 -require 'open3' - module Rake # Based on a script at: @@ -18,6 +13,26 @@ module Rake default end + begin + require 'etc' + rescue LoadError + else + if Etc.respond_to?(:nprocessors) + def count + return Etc.nprocessors + end + end + end + end +end + +unless Rake::CpuCounter.method_defined?(:count) + Rake::CpuCounter.class_eval <<-'end;', __FILE__, __LINE__+1 + require 'rbconfig' + + # TODO: replace with IO.popen using array-style arguments in Rake 11 + require 'open3' + def count if defined?(Java::Java) count_via_java_runtime @@ -44,18 +59,6 @@ module Rake end end - begin - require 'etc' - rescue LoadError - else - if Etc.respond_to?(:nprocessors) - undef count - def count - return Etc.nprocessors - end - end - end - def count_via_java_runtime Java::Java.lang.Runtime.getRuntime.availableProcessors rescue StandardError @@ -118,5 +121,5 @@ module Rake out.eof? ? nil : command end end - end + end; end |