Support environment variable to set rscons build directory - close #145

This commit is contained in:
Josh Holtrop 2022-01-17 18:02:58 -05:00
parent c1dcfa297f
commit b0f2bbb7d5
2 changed files with 23 additions and 3 deletions

View File

@ -27,7 +27,8 @@ module Rscons
# Create Application instance. # Create Application instance.
def initialize def initialize
@build_dir = "build" @build_dir = ENV["RSCONS_BUILD_DIR"] || "build"
ENV.delete("RSCONS_BUILD_DIR")
@n_threads = Util.determine_n_threads @n_threads = Util.determine_n_threads
@vars = VarSet.new @vars = VarSet.new
@operations = Set.new @operations = Set.new

View File

@ -208,13 +208,21 @@ EOF
expect(nr(`./simple.exe`)).to eq "This is a simple C program\n" expect(nr(`./simple.exe`)).to eq "This is a simple C program\n"
end 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") test_dir("simple")
result = run_rscons(rscons_args: %w[-b b]) result = run_rscons(rscons_args: %w[-b b])
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(Dir.exist?("build")).to be_falsey expect(Dir.exist?("build")).to be_falsey
expect(File.exists?("b/e.1/simple.c.o")).to be_truthy 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 end
it "allows specifying a Builder object as the source to another build target" do 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.status).to_not eq 0
expect(result.stdout).to_not match /top configure/ expect(result.stdout).to_not match /top configure/
end 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 end
context "sh method" do context "sh method" do