add Environment#clone() and a build test for it

This commit is contained in:
Josh Holtrop 2013-07-15 21:44:07 -04:00
parent c9f6bdb2e2
commit b8acc74b5d
4 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,11 @@
debug = Rscons::Environment.new do |env|
env.build_dir('src', 'debug')
env['CFLAGS'] = '-O2'
env['CPPFLAGS'] = '-DSTRING="Debug Version"'
env.Program('program-debug', Dir['src/*.c'])
end
release = debug.clone('CPPFLAGS' => '-DSTRING="Release Version"') do |env|
env.build_dir('src', 'release')
env.Program('program-release', Dir['src/*.c'])
end

View File

@ -0,0 +1,6 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello, %s\n", STRING);
}

View File

@ -36,6 +36,24 @@ module Rscons
end
end
def clone(variables = {})
env = Environment.new()
@builders.each do |builder_name, builder|
env.add_builder(builder)
end
@build_dirs.each do |src_dir, obj_dir|
env.build_dir(src_dir, obj_dir)
end
env.append(@varset)
env.append(variables)
if block_given?
yield env
env.process
end
env
end
def add_builder(builder)
@builders[builder.class.short_name] = builder
var_defs = builder.default_variables(self)

View File

@ -126,4 +126,14 @@ describe Rscons do
File.exists?('inc.h').should be_true
`./program`.should == "The value is 5678\n"
end
it 'allows cloning Environment objects' do
lines = test_dir('clone_env')
lines.should == [
%q{gcc -c -o debug/program.o -MMD -MF debug/program.mf '-DSTRING="Debug Version"' -O2 src/program.c},
%q{gcc -o program-debug debug/program.o},
%q{gcc -c -o release/program.o -MMD -MF release/program.mf '-DSTRING="Release Version"' -O2 src/program.c},
%q{gcc -o program-release release/program.o},
]
end
end