lib/rscons/environment.rb in rscons-1.10.0 vs lib/rscons/environment.rb in rscons-1.11.0
- old
+ new
@@ -15,10 +15,15 @@
attr_accessor :echo
# @return [String] The build root.
attr_reader :build_root
+ # @return [Integer]
+ # The number of threads to use for this Environment. If nil (the
+ # default), the global Rscons.n_threads default value will be used.
+ attr_writer :n_threads
+
# Set the build root.
#
# @param build_root [String] The build root.
def build_root=(build_root)
raise "build_root must be non-nil" unless build_root
@@ -71,22 +76,22 @@
# Exactly which items are cloned are controllable via the optional :clone
# parameter, which can be :none, :all, or a set or array of any of the
# following:
# - :variables to clone construction variables (on by default)
# - :builders to clone the builders (on by default)
- # - :build_root to clone the build root (off by default)
- # - :build_dirs to clone the build directories (off by default)
- # - :build_hooks to clone the build hooks (off by default)
+ # - :build_root to clone the build root (on by default)
+ # - :build_dirs to clone the build directories (on by default)
+ # - :build_hooks to clone the build hooks (on by default)
#
# If a block is given, the Environment object is yielded to the block and
# when the block returns, the {#process} method is automatically called.
#
# Any options that #initialize receives can also be specified here.
#
# @return [Environment] The newly created {Environment} object.
def clone(options = {})
- clone = options[:clone] || Set[:variables, :builders]
+ clone = options[:clone] || :all
clone = Set[:variables, :builders, :build_root, :build_dirs, :build_hooks] if clone == :all
clone = Set[] if clone == :none
clone = Set.new(clone) if clone.is_a?(Array)
clone.delete(:builders) if options[:exclude_builders]
env = self.class.new(
@@ -99,11 +104,11 @@
end
end
env.append(@varset) if clone.include?(:variables)
env.build_root = @build_root if clone.include?(:build_root)
if clone.include?(:build_dirs)
- @build_dirs.each do |src_dir, obj_dir|
+ @build_dirs.reverse.each do |src_dir, obj_dir|
env.build_dir(src_dir, obj_dir)
end
end
if clone.include?(:build_hooks)
@build_hooks[:pre].each do |build_hook_block|
@@ -220,11 +225,11 @@
# @return [void]
def build_dir(src_dir, obj_dir)
if src_dir.is_a?(String)
src_dir = src_dir.gsub("\\", "/").sub(%r{/*$}, "")
end
- @build_dirs << [src_dir, obj_dir]
+ @build_dirs.unshift([src_dir, obj_dir])
end
# Return the file name to be built from +source_fname+ with suffix
# +suffix+.
#
@@ -328,11 +333,12 @@
while tc = wait_for_threaded_commands(nonblock: true)
completed_tcs << tc
end
# If needed, do a blocking wait.
- if (completed_tcs.empty? and job.nil?) or @threaded_commands.size >= Rscons.n_threads
+ if (@threaded_commands.size > 0) and
+ ((completed_tcs.empty? and job.nil?) or (@threaded_commands.size >= n_threads))
completed_tcs << wait_for_threaded_commands
end
# Process all completed {ThreadedCommand} objects.
completed_tcs.each do |tc|
@@ -474,12 +480,14 @@
# @return [void]
def build_after(targets, prerequisites)
targets = Array(targets)
prerequisites = Array(prerequisites)
targets.each do |target|
+ target = expand_path(expand_varref(target))
@registered_build_dependencies[target] ||= Set.new
prerequisites.each do |prerequisite|
+ prerequisite = expand_path(expand_varref(prerequisite))
@registered_build_dependencies[target] << prerequisite
end
end
end
@@ -821,9 +829,18 @@
varset_hash = @varset.to_h
varset_hash.keys.sort_by(&:to_s).each do |var|
var_str = var.is_a?(Symbol) ? var.inspect : var
puts "#{var_str} => #{varset_hash[var].inspect}"
end
+ end
+
+ # Get the number of threads to use for parallelized builds in this
+ # Environment.
+ #
+ # @return [Integer]
+ # Number of threads to use for parallelized builds in this Environment.
+ def n_threads
+ @n_threads || Rscons.n_threads
end
private
# Add a build target.