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 hooks
When cloning an environment, by default the construction variables and builders
are cloned, but the new environment does not inherit any of the targets, build
hooks, build directories, or the build root from the source environment.
When cloning an environment, by default the construction variables, builders,
build hooks, build directories, and build root are cloned, but the new
environment does not inherit any of the registered build targets.
The set of environment attributes that are cloned is controllable via the
`:clone` option to the `#clone` method.
For example, `env.clone(clone: :all)` will include construction variables,
builders, build hooks, build directories, and the build root.
For example, `env.clone(clone: [:variables, :builders])` will include
construction variables, and builders but not build hooks, build directories, or
the build root.
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'])
end
env2 = env1.clone(clone: :all) do |env|
env2 = env1.clone do |env|
env.Program('program2.exe', Dir['src/*.c'])
end

View File

@ -78,9 +78,9 @@ module Rscons
# 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.
@ -89,7 +89,7 @@ module Rscons
#
# @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)
@ -106,7 +106,7 @@ module Rscons
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
@ -227,7 +227,7 @@ module Rscons
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

View File

@ -336,7 +336,7 @@ EOF
]
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')
result = run_test(rsconsfile: "clone_all.rb")
expect(result.stderr).to eq ""