add build test for custom builders
This commit is contained in:
parent
2cb584312e
commit
5dee51b21c
16
build_tests/custom_builder/build.rb
Normal file
16
build_tests/custom_builder/build.rb
Normal 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
|
7
build_tests/custom_builder/program.c
Normal file
7
build_tests/custom_builder/program.c
Normal 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);
|
||||||
|
}
|
@ -88,7 +88,10 @@ module Rscons
|
|||||||
end
|
end
|
||||||
@targets.each do |target, info|
|
@targets.each do |target, info|
|
||||||
next if targets_processed.include?(target)
|
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
|
end
|
||||||
cache.write
|
cache.write
|
||||||
end
|
end
|
||||||
|
@ -119,4 +119,11 @@ describe Rscons do
|
|||||||
File.exists?('build/one/one.o').should be_true
|
File.exists?('build/one/one.o').should be_true
|
||||||
File.exists?('build/two/two.o').should be_true
|
File.exists?('build/two/two.o').should be_true
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user