diff --git a/build_tests/simple/distclean.rb b/build_tests/simple/distclean.rb new file mode 100644 index 0000000..7cdfc1c --- /dev/null +++ b/build_tests/simple/distclean.rb @@ -0,0 +1,5 @@ +build do + Environment.new do |env| + env.Object("simple.o", "simple.c") + end +end diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 41f574a..e61c0e1 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -51,6 +51,8 @@ module Rscons clean when "configure" configure(operation_options) + when "distclean" + distclean else $stderr.puts "Unknown operation: #{operation}" 1 @@ -100,6 +102,19 @@ module Rscons 0 end + # Remove the build directory and clear the cache. + # + # @return [Integer] + # Exit code. + def distclean + cache = Cache.instance + build_dir = cache.configuration_data["build_dir"] + clean + FileUtils.rm_rf(build_dir) + cache.clear + 0 + end + # Configure the project. # # @param options [Hash] diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 2775473..3796cf6 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1895,4 +1895,21 @@ EOF end end + context "distclean" do + it "removes built files and the build directory" do + test_dir "simple" + result = run_rscons(rsconscript: "distclean.rb") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(File.exists?("simple.o")).to be_truthy + expect(File.exists?("build")).to be_truthy + result = run_rscons(rsconscript: "distclean.rb", op: "distclean") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(File.exists?("simple.o")).to be_falsey + expect(File.exists?("build")).to be_falsey + expect(File.exists?(Rscons::Cache::CACHE_FILE)).to be_falsey + end + end + end