lib/rscons.rb in rscons-1.9.3 vs lib/rscons.rb in rscons-1.10.0
- old
+ new
@@ -1,9 +1,11 @@
require_relative "rscons/build_target"
require_relative "rscons/builder"
require_relative "rscons/cache"
require_relative "rscons/environment"
+require_relative "rscons/job_set"
+require_relative "rscons/threaded_command"
require_relative "rscons/varset"
require_relative "rscons/version"
# default builders
require_relative "rscons/builders/cfile"
@@ -13,10 +15,12 @@
require_relative "rscons/builders/install"
require_relative "rscons/builders/library"
require_relative "rscons/builders/object"
require_relative "rscons/builders/preprocess"
require_relative "rscons/builders/program"
+require_relative "rscons/builders/shared_library"
+require_relative "rscons/builders/shared_object"
require_relative "rscons/builders/simple_builder"
# Namespace module for rscons classes
module Rscons
@@ -31,17 +35,23 @@
:Install,
:Library,
:Object,
:Preprocess,
:Program,
+ :SharedLibrary,
+ :SharedObject,
]
# Class to represent a fatal error while building a target.
class BuildError < RuntimeError; end
class << self
+ # @return [Integer]
+ # The number of threads to use when scheduling subprocesses.
+ attr_accessor :n_threads
+
# Remove all generated files.
#
# @return [void]
def clean
cache = Cache.instance
@@ -63,11 +73,15 @@
#
# @param path [String] the path to examine.
#
# @return [Boolean] Whether the given path is an absolute filesystem path.
def absolute_path?(path)
- path =~ %r{^(/|\w:[\\/])}
+ if RUBY_PLATFORM =~ /mingw/
+ path =~ %r{^(?:\w:)?[\\/]}
+ else
+ path.start_with?("/")
+ end
end
# Return whether the given target is a phony target.
#
# @param target [Symbol, String] Target name.
@@ -144,10 +158,48 @@
# @return [Array<String>] Command used to execute commands.
def command_executer=(val)
@command_executer = val
end
+ private
+
+ # Determine the number of threads to use by default.
+ #
+ # @return [Integer]
+ # The number of threads to use by default.
+ def determine_n_threads
+ # If the user specifies the number of threads in the environment, then
+ # respect that.
+ if ENV["RSCONS_NTHREADS"] =~ /^(\d+)$/
+ return $1.to_i
+ end
+
+ # Otherwise try to figure out how many threads are available on the
+ # host hardware.
+ begin
+ case RbConfig::CONFIG["host_os"]
+ when /linux/
+ return File.read("/proc/cpuinfo").scan(/^processor\s*:/).size
+ when /mswin|mingw/
+ if `wmic cpu get NumberOfLogicalProcessors /value` =~ /NumberOfLogicalProcessors=(\d+)/
+ return $1.to_i
+ end
+ when /darwin/
+ if `sysctl -n hw.ncpu` =~ /(\d+)/
+ return $1.to_i
+ end
+ end
+ rescue
+ end
+
+ # If we can't figure it out, default to 1.
+ 1
+ end
+
end
+
+ @n_threads = determine_n_threads
+
end
# Unbuffer $stdout
$stdout.sync = true