From 775363ddbd6b4e2f2784493b2ec897c824c62f71 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 11 Jul 2017 10:29:25 -0400 Subject: [PATCH] cloned Environments should inherit n_threads - close #42 --- build_tests/simple/clone_n_threads.rb | 7 +++++++ lib/rscons/environment.rb | 1 + spec/build_tests_spec.rb | 7 +++++++ 3 files changed, 15 insertions(+) create mode 100644 build_tests/simple/clone_n_threads.rb diff --git a/build_tests/simple/clone_n_threads.rb b/build_tests/simple/clone_n_threads.rb new file mode 100644 index 0000000..ec422cb --- /dev/null +++ b/build_tests/simple/clone_n_threads.rb @@ -0,0 +1,7 @@ +base_env = Rscons::Environment.new do |env| + env.n_threads = 165 +end + +my_env = base_env.clone + +puts my_env.n_threads diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 6fef4c4..3df43ad 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -118,6 +118,7 @@ module Rscons env.add_post_build_hook(&build_hook_block) end end + env.instance_variable_set(:@n_threads, @n_threads) if block_given? yield env diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 0f80eb7..e3372de 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -762,6 +762,13 @@ EOF expect(result.stderr).to match /Failed to build foo_4/ end + it "clones n_threads attribute when cloning an Environment" do + test_dir("simple") + result = run_test(rsconsfile: "clone_n_threads.rb") + expect(result.stderr).to eq "" + expect(lines(result.stdout)).to eq ["165"] + end + context "backward compatibility" do it "allows a builder to call Environment#run_builder in a non-threaded manner" do test_dir("simple")