add Builder#standard_threaded_build, #standard_finalize
parallelize Program builder command
This commit is contained in:
parent
1af3c5c9a4
commit
f815952ab3
@ -148,6 +148,8 @@ module Rscons
|
||||
# This method is called after the {#run} method if the {#run} method
|
||||
# returns a {ThreadedCommand} object.
|
||||
#
|
||||
# @since 1.10.0
|
||||
#
|
||||
# @param options [Hash]
|
||||
# Options.
|
||||
# @option options [String] :target
|
||||
@ -175,7 +177,7 @@ module Rscons
|
||||
end
|
||||
|
||||
# Check if the cache is up to date for the target and if not execute the
|
||||
# build command.
|
||||
# build command. This method does not support parallelization.
|
||||
#
|
||||
# @param short_cmd_string [String]
|
||||
# Short description of build action to be printed when env.echo ==
|
||||
@ -200,5 +202,54 @@ module Rscons
|
||||
end
|
||||
target
|
||||
end
|
||||
|
||||
# Check if the cache is up to date for the target and if not create a
|
||||
# {ThreadedCommand} object to execute the build command in a thread.
|
||||
#
|
||||
# @since 1.10.0
|
||||
#
|
||||
# @param short_cmd_string [String]
|
||||
# Short description of build action to be printed when env.echo ==
|
||||
# :short.
|
||||
# @param target [String] Name of the target file.
|
||||
# @param command [Array<String>]
|
||||
# The command to execute to build the target.
|
||||
# @param sources [Array<String>] Source file name(s).
|
||||
# @param env [Environment] The Environment executing the builder.
|
||||
# @param cache [Cache] The Cache object.
|
||||
#
|
||||
# @return [String,ThreadedCommand]
|
||||
# The name of the target if it is already up to date or the
|
||||
# {ThreadedCommand} object created to update it.
|
||||
def standard_threaded_build(short_cmd_string, target, command, sources, env, cache)
|
||||
if cache.up_to_date?(target, command, sources, env)
|
||||
target
|
||||
else
|
||||
unless Rscons.phony_target?(target)
|
||||
cache.mkdir_p(File.dirname(target))
|
||||
FileUtils.rm_f(target)
|
||||
end
|
||||
ThreadedCommand.new(
|
||||
command,
|
||||
short_description: short_cmd_string)
|
||||
end
|
||||
end
|
||||
|
||||
# Register build results from a {ThreadedCommand} with the cache.
|
||||
#
|
||||
# @since 1.10.0
|
||||
#
|
||||
# @param options [Hash]
|
||||
# Builder finalize options.
|
||||
#
|
||||
# @return [String, nil]
|
||||
# The target name on success or nil on failure.
|
||||
def standard_finalize(options)
|
||||
if options[:command_status]
|
||||
target, sources, cache, env = options.values_at(:target, :sources, :cache, :env)
|
||||
cache.register_build(target, options[:tc].command, sources, env)
|
||||
target
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -96,15 +96,7 @@ module Rscons
|
||||
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
||||
end.first
|
||||
command = env.build_command("${#{com_prefix}CMD}", vars)
|
||||
if cache.up_to_date?(target, command, sources, env)
|
||||
target
|
||||
else
|
||||
cache.mkdir_p(File.dirname(target))
|
||||
FileUtils.rm_f(target)
|
||||
ThreadedCommand.new(
|
||||
command,
|
||||
short_description: "#{com_prefix} #{target}")
|
||||
end
|
||||
standard_threaded_build("#{com_prefix} #{target}", target, command, sources, env, cache)
|
||||
end
|
||||
|
||||
# Finalize the build operation.
|
||||
|
@ -83,8 +83,20 @@ module Rscons
|
||||
'_SOURCES' => objects,
|
||||
'LD' => ld,
|
||||
})
|
||||
options[:sources] = objects
|
||||
command = env.build_command("${LDCMD}", vars)
|
||||
standard_build("LD #{target}", target, command, objects, env, cache)
|
||||
standard_threaded_build("LD #{target}", target, command, objects, env, cache)
|
||||
end
|
||||
|
||||
# Finalize a build.
|
||||
#
|
||||
# @param options [Hash]
|
||||
# Finalize options.
|
||||
#
|
||||
# @return [String, nil]
|
||||
# The target name on success or nil on failure.
|
||||
def finalize(options)
|
||||
standard_finalize(options)
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user