add build test for custom builders

This commit is contained in:
Josh Holtrop 2013-07-15 20:46:00 -04:00
parent 2cb584312e
commit 5dee51b21c
4 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,16 @@
class MySource < Rscons::Builder
def run(target, sources, cache)
File.open(target, 'w') do |fh|
fh.puts <<EOF
#define THE_VALUE 5678
EOF
end
target
end
end
Rscons::Environment.new(echo: :short) do |env|
env.add_builder(MySource.new(env))
env.MySource('inc.h', [])
env.Program('program', Dir['*.c'])
end

View File

@ -0,0 +1,7 @@
#include <stdio.h>
#include "inc.h"
int main(int argc, char *argv[])
{
printf("The value is %d\n", THE_VALUE);
}

View File

@ -88,7 +88,10 @@ module Rscons
end
@targets.each do |target, info|
next if targets_processed.include?(target)
break unless process_target.call(target)
unless process_target.call(target)
$stderr.puts "Error: failed to build #{target}"
break
end
end
cache.write
end

View File

@ -119,4 +119,11 @@ describe Rscons do
File.exists?('build/one/one.o').should be_true
File.exists?('build/two/two.o').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']
File.exists?('inc.h').should be_true
`./program`.should == "The value is 5678\n"
end
end