Change default :clone option to :all to clone all Environment attributes

This commit is contained in:
Josh Holtrop 2017-06-14 08:50:48 -04:00
parent 6d6319799a
commit 8deb1eb6f8
4 changed files with 14 additions and 13 deletions

View File

@ -230,14 +230,15 @@ An Environment consists of:
* a collection of user-defined build targets * a collection of user-defined build targets
* a collection of user-defined build hooks * a collection of user-defined build hooks
When cloning an environment, by default the construction variables and builders When cloning an environment, by default the construction variables, builders,
are cloned, but the new environment does not inherit any of the targets, build build hooks, build directories, and build root are cloned, but the new
hooks, build directories, or the build root from the source environment. environment does not inherit any of the registered build targets.
The set of environment attributes that are cloned is controllable via the The set of environment attributes that are cloned is controllable via the
`:clone` option to the `#clone` method. `:clone` option to the `#clone` method.
For example, `env.clone(clone: :all)` will include construction variables, For example, `env.clone(clone: [:variables, :builders])` will include
builders, build hooks, build directories, and the build root. construction variables, and builders but not build hooks, build directories, or
the build root.
The set of pending targets is never cloned. The set of pending targets is never cloned.

View File

@ -10,6 +10,6 @@ env1 = Rscons::Environment.new(echo: :command) do |env|
env.Program('program.exe', Dir['src/*.c']) env.Program('program.exe', Dir['src/*.c'])
end end
env2 = env1.clone(clone: :all) do |env| env2 = env1.clone do |env|
env.Program('program2.exe', Dir['src/*.c']) env.Program('program2.exe', Dir['src/*.c'])
end end

View File

@ -78,9 +78,9 @@ module Rscons
# following: # following:
# - :variables to clone construction variables (on by default) # - :variables to clone construction variables (on by default)
# - :builders to clone the builders (on by default) # - :builders to clone the builders (on by default)
# - :build_root to clone the build root (off by default) # - :build_root to clone the build root (on by default)
# - :build_dirs to clone the build directories (off by default) # - :build_dirs to clone the build directories (on by default)
# - :build_hooks to clone the build hooks (off 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 # If a block is given, the Environment object is yielded to the block and
# when the block returns, the {#process} method is automatically called. # when the block returns, the {#process} method is automatically called.
@ -89,7 +89,7 @@ module Rscons
# #
# @return [Environment] The newly created {Environment} object. # @return [Environment] The newly created {Environment} object.
def clone(options = {}) 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[:variables, :builders, :build_root, :build_dirs, :build_hooks] if clone == :all
clone = Set[] if clone == :none clone = Set[] if clone == :none
clone = Set.new(clone) if clone.is_a?(Array) clone = Set.new(clone) if clone.is_a?(Array)
@ -106,7 +106,7 @@ module Rscons
env.append(@varset) if clone.include?(:variables) env.append(@varset) if clone.include?(:variables)
env.build_root = @build_root if clone.include?(:build_root) env.build_root = @build_root if clone.include?(:build_root)
if clone.include?(:build_dirs) 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) env.build_dir(src_dir, obj_dir)
end end
end end
@ -227,7 +227,7 @@ module Rscons
if src_dir.is_a?(String) if src_dir.is_a?(String)
src_dir = src_dir.gsub("\\", "/").sub(%r{/*$}, "") src_dir = src_dir.gsub("\\", "/").sub(%r{/*$}, "")
end end
@build_dirs << [src_dir, obj_dir] @build_dirs.unshift([src_dir, obj_dir])
end end
# Return the file name to be built from +source_fname+ with suffix # Return the file name to be built from +source_fname+ with suffix

View File

@ -336,7 +336,7 @@ EOF
] ]
end end
it 'allows cloning all attributes of an Environment object' do it 'clones all attributes of an Environment object by default' do
test_dir('clone_env') test_dir('clone_env')
result = run_test(rsconsfile: "clone_all.rb") result = run_test(rsconsfile: "clone_all.rb")
expect(result.stderr).to eq "" expect(result.stderr).to eq ""