clear build targets after processing an Environment - close #17

This commit is contained in:
Josh Holtrop 2014-09-19 10:45:49 -04:00
parent 23c94f7841
commit b186b3102c
2 changed files with 27 additions and 14 deletions

View File

@ -247,6 +247,7 @@ module Rscons
cache.write cache.write
end end
end end
clear_targets
end end
# Clear all targets registered for the Environment. # Clear all targets registered for the Environment.

View File

@ -120,34 +120,43 @@ describe Rscons do
it 'rebuilds a C module when a header it depends on changes' do it 'rebuilds a C module when a header it depends on changes' do
test_dir('header') test_dir('header')
env = Rscons::Environment.new do |env| make_env = lambda do
env.Program('header', Dir['*.c']) Rscons::Environment.new do |env|
env.Program('header', Dir['*.c'])
end
end end
make_env[]
expect(`./header`).to eq "The value is 2\n" expect(`./header`).to eq "The value is 2\n"
file_sub('header.h') {|line| line.sub(/2/, '5')} file_sub('header.h') {|line| line.sub(/2/, '5')}
env.process make_env[]
expect(`./header`).to eq "The value is 5\n" expect(`./header`).to eq "The value is 5\n"
end end
it 'does not rebuild a C module when its dependencies have not changed' do it 'does not rebuild a C module when its dependencies have not changed' do
test_dir('header') test_dir('header')
env = Rscons::Environment.new do |env| make_env = lambda do
env.Program('header', Dir['*.c']) Rscons::Environment.new do |env|
env.Program('header', Dir['*.c'])
end
end end
env = make_env[]
expect(`./header`).to eq "The value is 2\n" expect(`./header`).to eq "The value is 2\n"
expect(lines).to eq [ expect(lines).to eq [
'CC header.o', 'CC header.o',
"LD header#{env["PROGSUFFIX"]}", "LD header#{env["PROGSUFFIX"]}",
] ]
env.process make_env[]
expect(lines).to eq [] expect(lines).to eq []
end end
it "does not rebuild a C module when only the file's timestamp has changed" do it "does not rebuild a C module when only the file's timestamp has changed" do
test_dir('header') test_dir('header')
env = Rscons::Environment.new do |env| make_env = lambda do
env.Program('header', Dir['*.c']) Rscons::Environment.new do |env|
env.Program('header', Dir['*.c'])
end
end end
env = make_env[]
expect(`./header`).to eq "The value is 2\n" expect(`./header`).to eq "The value is 2\n"
expect(lines).to eq [ expect(lines).to eq [
'CC header.o', 'CC header.o',
@ -155,7 +164,7 @@ describe Rscons do
] ]
sleep 0.05 sleep 0.05
file_sub('header.c') {|line| line} file_sub('header.c') {|line| line}
env.process make_env[]
expect(lines).to eq [] expect(lines).to eq []
end end
@ -303,11 +312,14 @@ EOF
end end
end end
env = Rscons::Environment.new do |env| make_env = lambda do
env.add_builder(CHGen.new) Rscons::Environment.new do |env|
env.CHGen("inc.c", ["program.c"]) env.add_builder(CHGen.new)
env.Program("program", Dir["*.c"] + ["inc.c"]) env.CHGen("inc.c", ["program.c"])
env.Program("program", %w[program.c inc.c])
end
end end
env = make_env[]
expect(lines).to eq ["CHGen inc.c", "CC program.o", "CC inc.o", "LD program#{env["PROGSUFFIX"]}"] expect(lines).to eq ["CHGen inc.c", "CC program.o", "CC inc.o", "LD program#{env["PROGSUFFIX"]}"]
expect(File.exists?("inc.c")).to be_truthy expect(File.exists?("inc.c")).to be_truthy
@ -315,7 +327,7 @@ EOF
expect(`./program`).to eq "The value is 42\n" expect(`./program`).to eq "The value is 42\n"
File.open("inc.c", "w") {|fh| fh.puts "int THE_VALUE = 33;"} File.open("inc.c", "w") {|fh| fh.puts "int THE_VALUE = 33;"}
env.process make_env[]
expect(lines).to eq ["CHGen inc.c"] expect(lines).to eq ["CHGen inc.c"]
expect(`./program`).to eq "The value is 42\n" expect(`./program`).to eq "The value is 42\n"
end end