Add ability to record side-effect file production - close #43
This commit is contained in:
parent
45e30662d2
commit
6d04500c13
14
build_tests/custom_builder/produces.rb
Normal file
14
build_tests/custom_builder/produces.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env["build_root"] = env.build_root
|
||||||
|
env["inc_h"] = "inc.h"
|
||||||
|
|
||||||
|
env.Copy("copy_inc.h", "${inc_h}")
|
||||||
|
env.depends("${build_root}/program.o", "${inc_h}")
|
||||||
|
env.Program("program.exe", ["program.c", "inc.c"])
|
||||||
|
|
||||||
|
env.Command("inc.c",
|
||||||
|
[],
|
||||||
|
"CMD" => %w[ruby gen.rb ${_TARGET}],
|
||||||
|
"CMD_DESC" => "Generating")
|
||||||
|
env.produces("inc.c", "inc.h")
|
||||||
|
end
|
@ -45,8 +45,9 @@ module Rscons
|
|||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@threaded_commands = Set.new
|
@threaded_commands = Set.new
|
||||||
@registered_build_dependencies = {}
|
@registered_build_dependencies = {}
|
||||||
|
@side_effects = {}
|
||||||
@varset = VarSet.new
|
@varset = VarSet.new
|
||||||
@job_set = JobSet.new(@registered_build_dependencies)
|
@job_set = JobSet.new(@registered_build_dependencies, @side_effects)
|
||||||
@user_deps = {}
|
@user_deps = {}
|
||||||
@builders = {}
|
@builders = {}
|
||||||
@build_dirs = []
|
@build_dirs = []
|
||||||
@ -502,6 +503,26 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Manually record the given side effect file(s) as being produced when the
|
||||||
|
# named target is produced.
|
||||||
|
#
|
||||||
|
# @since 1.13.0
|
||||||
|
#
|
||||||
|
# @param target [String]
|
||||||
|
# Target of a build operation.
|
||||||
|
# @param side_effects [Array<String>]
|
||||||
|
# File(s) produced when the target file is produced.
|
||||||
|
#
|
||||||
|
# @return [void]
|
||||||
|
def produces(target, *side_effects)
|
||||||
|
target = expand_path(expand_varref(target))
|
||||||
|
side_effects = Array(side_effects).map do |side_effect|
|
||||||
|
expand_path(expand_varref(side_effect))
|
||||||
|
end.flatten
|
||||||
|
@side_effects[target] ||= []
|
||||||
|
@side_effects[target] += side_effects
|
||||||
|
end
|
||||||
|
|
||||||
# Return the list of user dependencies for a given target.
|
# Return the list of user dependencies for a given target.
|
||||||
#
|
#
|
||||||
# @param target [String] Target file name.
|
# @param target [String] Target file name.
|
||||||
|
@ -9,9 +9,14 @@ module Rscons
|
|||||||
# @param build_dependencies [Hash]
|
# @param build_dependencies [Hash]
|
||||||
# Hash mapping targets to a set of build dependencies. A job will not be
|
# Hash mapping targets to a set of build dependencies. A job will not be
|
||||||
# returned as ready to run if any of its dependencies are still building.
|
# returned as ready to run if any of its dependencies are still building.
|
||||||
def initialize(build_dependencies)
|
# @param side_effects [Hash]
|
||||||
|
# Hash mapping targets to a set of side-effect files. A job will not be
|
||||||
|
# returned as ready to run if any of its dependencies is a side-effect
|
||||||
|
# of another target that has not yet been built.
|
||||||
|
def initialize(build_dependencies, side_effects)
|
||||||
@jobs = {}
|
@jobs = {}
|
||||||
@build_dependencies = build_dependencies
|
@build_dependencies = build_dependencies
|
||||||
|
@side_effects = side_effects
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a job to the JobSet.
|
# Add a job to the JobSet.
|
||||||
@ -47,18 +52,16 @@ module Rscons
|
|||||||
# @return [nil, Hash]
|
# @return [nil, Hash]
|
||||||
# The next job to run.
|
# The next job to run.
|
||||||
def get_next_job_to_run(targets_still_building)
|
def get_next_job_to_run(targets_still_building)
|
||||||
|
targets_not_built_yet = targets_still_building + @jobs.keys
|
||||||
|
side_effects = targets_not_built_yet.map do |target|
|
||||||
|
@side_effects[target] || []
|
||||||
|
end.flatten
|
||||||
|
targets_not_built_yet += side_effects
|
||||||
|
|
||||||
@jobs.keys.each do |target|
|
@jobs.keys.each do |target|
|
||||||
skip = false
|
skip = false
|
||||||
(@jobs[target][0][:sources] + (@build_dependencies[target] || []).to_a).each do |src|
|
(@jobs[target][0][:sources] + (@build_dependencies[target] || []).to_a).each do |src|
|
||||||
if @jobs.include?(src)
|
if targets_not_built_yet.include?(src)
|
||||||
# Skip this target because it depends on another target not yet
|
|
||||||
# built.
|
|
||||||
skip = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
if targets_still_building.include?(src)
|
|
||||||
# Skip this target because it depends on another target that is
|
|
||||||
# currently being built.
|
|
||||||
skip = true
|
skip = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -1306,6 +1306,13 @@ EOF
|
|||||||
result = run_test(rsconsfile: "build_after.rb", rscons_args: %w[-j 4])
|
result = run_test(rsconsfile: "build_after.rb", rscons_args: %w[-j 4])
|
||||||
expect(result.stderr).to eq ""
|
expect(result.stderr).to eq ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allows the user to specify side-effect files produced by another builder" do
|
||||||
|
test_dir("custom_builder")
|
||||||
|
result = run_test(rsconsfile: "produces.rb", rscons_args: %w[-j 4])
|
||||||
|
expect(result.stderr).to eq ""
|
||||||
|
expect(File.exists?("copy_inc.h")).to be_truthy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "CLI" do
|
context "CLI" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user