From b0f2bbb7d51155270c0f31a16b4425e3c5364bc3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 17 Jan 2022 18:02:58 -0500 Subject: [PATCH] Support environment variable to set rscons build directory - close #145 --- lib/rscons/application.rb | 3 ++- spec/build_tests_spec.rb | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 9ddf3e0..d0050c0 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -27,7 +27,8 @@ module Rscons # Create Application instance. def initialize - @build_dir = "build" + @build_dir = ENV["RSCONS_BUILD_DIR"] || "build" + ENV.delete("RSCONS_BUILD_DIR") @n_threads = Util.determine_n_threads @vars = VarSet.new @operations = Set.new diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 3ee6e12..4bea9ff 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -208,13 +208,21 @@ EOF expect(nr(`./simple.exe`)).to eq "This is a simple C program\n" end - it "builds a C program with one source file in an alternate build directory" do + it "uses the build directory specified with -b" do test_dir("simple") result = run_rscons(rscons_args: %w[-b b]) expect(result.stderr).to eq "" expect(Dir.exist?("build")).to be_falsey expect(File.exists?("b/e.1/simple.c.o")).to be_truthy - expect(nr(`./simple.exe`)).to eq "This is a simple C program\n" + end + + it "uses the build directory specified by an environment variable" do + test_dir("simple") + passenv["RSCONS_BUILD_DIR"] = "b2" + result = run_rscons + expect(result.stderr).to eq "" + expect(Dir.exist?("build")).to be_falsey + expect(File.exists?("b2/e.1/simple.c.o")).to be_truthy end it "allows specifying a Builder object as the source to another build target" do @@ -2800,6 +2808,17 @@ EOF expect(result.status).to_not eq 0 expect(result.stdout).to_not match /top configure/ end + + it "does not pass RSCONS_BUILD_DIR to subsidiary scripts" do + test_dir "subsidiary" + passenv["RSCONS_BUILD_DIR"] = "buildit" + result = run_rscons(op: %W[configure]) + expect(result.stderr).to eq "" + expect(Dir.exist?("build")).to be_falsey + expect(Dir.exist?("buildit")).to be_truthy + expect(Dir.exist?("sub/build")).to be_truthy + expect(Dir.exist?("sub/buildit")).to be_falsey + end end context "sh method" do