From e9e3c6711f92eb1f7fae648dea79ded2862769d5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 20 Feb 2022 18:13:59 -0500 Subject: [PATCH] Add build_dir script method - close #155 --- build_tests/typical/build_dir.rb | 3 +++ lib/rscons/script.rb | 8 ++++++++ spec/build_tests_spec.rb | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 build_tests/typical/build_dir.rb diff --git a/build_tests/typical/build_dir.rb b/build_tests/typical/build_dir.rb new file mode 100644 index 0000000..9802276 --- /dev/null +++ b/build_tests/typical/build_dir.rb @@ -0,0 +1,3 @@ +default do + touch "#{build_dir}/a.file" +end diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index cf1ebf8..c359ee6 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -10,6 +10,14 @@ module Rscons @script = script end + # Get the Rscons build directory path. + # + # @return [String] + # Rscons build directory path. + def build_dir + Rscons.application.build_dir + end + # Return a list of paths matching the specified pattern(s). # # A pattern can contain a "/**" component to recurse through directories. diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index d9f96d8..6f23e3a 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -3187,4 +3187,22 @@ EOF end end + context "build_dir method" do + it "returns the top-level build directory path 1" do + test_dir "typical" + result = run_rscons(args: %w[-f build_dir.rb]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(File.exist?("build/a.file")).to be_truthy + end + + it "returns the top-level build directory path 2" do + test_dir "typical" + result = run_rscons(args: %w[-f build_dir.rb -b bb]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(File.exist?("bb/a.file")).to be_truthy + end + end + end