add build test using a build directory

This commit is contained in:
Josh Holtrop 2013-07-15 19:14:52 -04:00
parent 741f5cfe5e
commit 2cb584312e
7 changed files with 46 additions and 13 deletions

View File

@ -0,0 +1,5 @@
Rscons::Environment.new do |env|
env.append('CPPPATH' => Dir['src/**/*/'])
env.build_dir('src', 'build')
env.Program('build_dir', Dir['src/**/*.c'])
end

View File

@ -0,0 +1,6 @@
#include "two.h"
int main(int argc, char *argv[])
{
two();
}

View File

@ -0,0 +1,7 @@
#include <stdio.h>
#include "two.h"
void two(void)
{
printf("Hello from two()\n");
}

View File

@ -0,0 +1,6 @@
#ifndef TWO_H
#define TWO_H
void two(void);
#endif

View File

@ -18,23 +18,25 @@ module Rscons
if source.has_suffix?([@env['OBJSUFFIX'], @env['LIBSUFFIX']]) if source.has_suffix?([@env['OBJSUFFIX'], @env['LIBSUFFIX']])
source source
else else
o_file = source.set_suffix(@env['OBJSUFFIX', :string]) o_file = @env.get_build_fname(source, @env['OBJSUFFIX', :string])
builder = @env.builders.values.find { |b| b.produces?(o_file, source) } builder = @env.builders.values.find { |b| b.produces?(o_file, source) }
builder or raise "No builder found to convert input source #{source.inspect} to an object file." builder or raise "No builder found to convert input source #{source.inspect} to an object file."
builder.run(o_file, [source], cache) builder.run(o_file, [source], cache) or break
end end
end end
vars = { if sources
'TARGET' => target, vars = {
'SOURCES' => sources, 'TARGET' => target,
'LD' => @env['LD'] || @env['CC'], # TODO: figure out whether to use CC or CXX 'SOURCES' => sources,
} 'LD' => @env['LD'] || @env['CC'], # TODO: figure out whether to use CC or CXX
command = @env.build_command(@env['LDCOM'], vars) }
unless cache.up_to_date?(target, command, sources) command = @env.build_command(@env['LDCOM'], vars)
return false unless @env.execute("LD #{target}", command) unless cache.up_to_date?(target, command, sources)
cache.register_build(target, command, sources) return false unless @env.execute("LD #{target}", command)
cache.register_build(target, command, sources)
end
target
end end
target
end end
end end
end end

View File

@ -99,7 +99,7 @@ module Rscons
def execute(short_desc, command) def execute(short_desc, command)
if @varset[:echo] == :command if @varset[:echo] == :command
puts command.map { |c| c =~ /\s/ ? "'#{c}'" : c }.join(' ') puts command.map { |c| c =~ /\s/ ? "'#{c}'" : c }.join(' ')
elsif @varset[:echo] == :short elsif @varset[:echo] == :short
puts short_desc puts short_desc
end end

View File

@ -112,4 +112,11 @@ describe Rscons do
lines = build_testdir lines = build_testdir
lines.should == ['gcc -o simple simple.o -lc'] lines.should == ['gcc -o simple simple.o -lc']
end end
it 'builds object files in a different build directory' 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
end
end end