From 8deb1eb6f8704150039e084c77b611d8a06ce9d1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 14 Jun 2017 08:50:48 -0400 Subject: [PATCH] Change default :clone option to :all to clone all Environment attributes --- README.md | 11 ++++++----- build_tests/clone_env/clone_all.rb | 2 +- lib/rscons/environment.rb | 12 ++++++------ spec/build_tests_spec.rb | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2308e71..ffdbbe8 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/build_tests/clone_env/clone_all.rb b/build_tests/clone_env/clone_all.rb index eaeb542..90f957e 100644 --- a/build_tests/clone_env/clone_all.rb +++ b/build_tests/clone_env/clone_all.rb @@ -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 diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 9f39625..0239470 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -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 diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index c62069c..6b780cc 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -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 ""