allow build hooks to register new build targets - close #15

This commit is contained in:
Josh Holtrop 2014-09-19 11:10:59 -04:00
parent b186b3102c
commit dee2b98f6e
2 changed files with 27 additions and 9 deletions

View File

@ -216,23 +216,25 @@ module Rscons
#
# @return [void]
def process
unless @targets.empty?
expand_paths!
while @targets.size > 0
targets = @targets
@targets = {}
cache = Cache.instance
cache.clear_checksum_cache!
targets_processed = {}
process_target = proc do |target|
targets_processed[target] ||= begin
@targets[target][:sources].each do |src|
if @targets.include?(src) and not targets_processed.include?(src)
targets[target][:sources].each do |src|
if targets.include?(src) and not targets_processed.include?(src)
process_target.call(src)
end
end
result = run_builder(@targets[target][:builder],
result = run_builder(targets[target][:builder],
target,
@targets[target][:sources],
targets[target][:sources],
cache,
@targets[target][:vars] || {})
targets[target][:vars] || {})
unless result
raise BuildError.new("Failed to build #{target}")
end
@ -240,14 +242,13 @@ module Rscons
end
end
begin
@targets.each do |target, target_params|
targets.each do |target, target_params|
process_target.call(target)
end
ensure
cache.write
end
end
clear_targets
end
# Clear all targets registered for the Environment.

View File

@ -10,6 +10,7 @@ class Dir
end
describe Rscons do
BUILD_TEST_RUN_DIR = "build_test_run"
def rm_rf(dir)
@ -574,4 +575,20 @@ EOF
expect(e2.expand_varref("${computed}")).to eq("-H38xyz")
expect(env.expand_varref("${lambda_recurse}")).to eq("-Hello")
end
it "supports registering build targets from within a build hook" do
test_dir("simple")
Rscons::Environment.new do |env|
env.Program("simple", Dir["*.c"])
env.add_build_hook do |build_op|
if build_op[:target].end_with?(".o")
env.Disassemble("#{build_op[:target]}.txt", build_op[:target])
end
end
end
expect(File.exists?("simple.o")).to be_truthy
expect(File.exists?("simple.o.txt")).to be_truthy
expect(`./simple`).to eq "This is a simple C program\n"
end
end