add Environment#depends() to specify user dependencies for a build target
This commit is contained in:
parent
7330e74ab8
commit
295324eafd
@ -26,6 +26,7 @@ module Rscons
|
||||
def initialize(options = {})
|
||||
@varset = VarSet.new
|
||||
@targets = {}
|
||||
@user_deps = {}
|
||||
@builders = {}
|
||||
@build_dirs = []
|
||||
@build_hooks = []
|
||||
@ -147,7 +148,7 @@ module Rscons
|
||||
result = run_builder(@targets[target][:builder],
|
||||
target,
|
||||
@targets[target][:source],
|
||||
[],
|
||||
@user_deps[target] || [],
|
||||
cache,
|
||||
@targets[target][:vars] || {})
|
||||
unless result
|
||||
@ -221,6 +222,13 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Manually record a given target as depending on the specified
|
||||
# dependency files.
|
||||
def depends(target, *user_deps)
|
||||
@user_deps[target] ||= []
|
||||
@user_deps[target] = (@user_deps[target] + user_deps).uniq
|
||||
end
|
||||
|
||||
# Build a list of source files into files containing one of the suffixes
|
||||
# given by suffixes.
|
||||
# This method is used internally by RScons builders.
|
||||
|
@ -328,6 +328,37 @@ EOF
|
||||
]
|
||||
end
|
||||
|
||||
it 'rebuilds when user-specified dependencies change' do
|
||||
test_dir('simple')
|
||||
Rscons::Environment.new do |env|
|
||||
env.Program('simple', Dir['*.c'])
|
||||
File.open("file.ld", "w") do |fh|
|
||||
fh.puts("foo")
|
||||
end
|
||||
env.depends('simple', 'file.ld')
|
||||
end
|
||||
lines.should == ["CC simple.o", "LD simple"]
|
||||
File.exists?('simple.o').should be_true
|
||||
`./simple`.should == "This is a simple C program\n"
|
||||
Rscons::Environment.new do |env|
|
||||
env.Program('simple', Dir['*.c'])
|
||||
File.open("file.ld", "w") do |fh|
|
||||
fh.puts("bar")
|
||||
end
|
||||
env.depends('simple', 'file.ld')
|
||||
end
|
||||
lines.should == ["LD simple"]
|
||||
Rscons::Environment.new do |env|
|
||||
env.Program('simple', Dir['*.c'])
|
||||
File.unlink("file.ld")
|
||||
end
|
||||
lines.should == ["LD simple"]
|
||||
Rscons::Environment.new do |env|
|
||||
env.Program('simple', Dir['*.c'])
|
||||
end
|
||||
lines.should == []
|
||||
end
|
||||
|
||||
unless ENV["omit_gdc_tests"]
|
||||
it "supports building D sources" do
|
||||
test_dir("d")
|
||||
|
@ -230,6 +230,20 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
describe "#depends" do
|
||||
it "records the given dependencies in @user_deps" do
|
||||
env = Environment.new
|
||||
env.depends("foo", "bar", "baz")
|
||||
env.instance_variable_get(:@user_deps).should == {"foo" => ["bar", "baz"]}
|
||||
end
|
||||
it "records user dependencies only once" do
|
||||
env = Environment.new
|
||||
env.instance_variable_set(:@user_deps, {"foo" => ["bar"]})
|
||||
env.depends("foo", "bar", "baz")
|
||||
env.instance_variable_get(:@user_deps).should == {"foo" => ["bar", "baz"]}
|
||||
end
|
||||
end
|
||||
|
||||
describe "#build_sources" do
|
||||
class ABuilder < Builder
|
||||
def produces?(target, source, env)
|
||||
|
Loading…
x
Reference in New Issue
Block a user