diff --git a/lib/rscons.rb b/lib/rscons.rb index 042cfa9..859f381 100644 --- a/lib/rscons.rb +++ b/lib/rscons.rb @@ -22,4 +22,13 @@ module Rscons class BuildError < Exception end + + # Remove all generated files + def self.clean + cache = Cache.new + cache.targets.each do |target| + FileUtils.rm_f(target) + end + Cache.clear + end end diff --git a/lib/rscons/cache.rb b/lib/rscons/cache.rb index d289633..4eda621 100644 --- a/lib/rscons/cache.rb +++ b/lib/rscons/cache.rb @@ -132,6 +132,11 @@ module Rscons } end + # Return a list of targets that have been built + def targets + @cache[:targets].keys + end + # Private Instance Methods private diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 82c5179..96bd2ca 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -120,6 +120,17 @@ describe Rscons do File.exists?('build/two/two.o').should be_true end + it 'cleans built files' do + lines = test_dir('build_dir') + `./build_dir`.should == "Hello from two()\n" + File.exists?('build/one/one.o').should be_true + File.exists?('build/two/two.o').should be_true + Rscons.clean + File.exists?('build/one/one.o').should be_false + File.exists?('build/two/two.o').should be_false + File.exists?('src/one/one.c').should be_true + end + it 'allows Ruby classes as custom builders to be used to construct files' do lines = test_dir('custom_builder') lines.should == ['CC program.o', 'LD program']