add Rscons.clear() class method

This commit is contained in:
Josh Holtrop 2013-09-17 21:48:50 -04:00
parent 983cb7cf21
commit 770a22250a
3 changed files with 25 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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']