update Object builder to support parallelization; update Program and Library builders to register object builds from #setup
This commit is contained in:
parent
267fc7124d
commit
6344692087
@ -2,6 +2,7 @@ module Rscons
|
|||||||
module Builders
|
module Builders
|
||||||
# A default Rscons builder that produces a static library archive.
|
# A default Rscons builder that produces a static library archive.
|
||||||
class Library < Builder
|
class Library < Builder
|
||||||
|
|
||||||
# Return default construction variables for the builder.
|
# Return default construction variables for the builder.
|
||||||
#
|
#
|
||||||
# @param env [Environment] The Environment using the builder.
|
# @param env [Environment] The Environment using the builder.
|
||||||
@ -16,28 +17,36 @@ module Rscons
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set up a build operation using this builder.
|
||||||
|
#
|
||||||
|
# @param options [Hash] Builder setup options.
|
||||||
|
#
|
||||||
|
# @return [Object]
|
||||||
|
# Any object that the builder author wishes to be saved and passed back
|
||||||
|
# in to the {#run} method.
|
||||||
|
def setup(options)
|
||||||
|
target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
|
||||||
|
suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
|
||||||
|
# Register builders to build each source to an object file or library.
|
||||||
|
env.register_builds(target, sources, suffixes, vars)
|
||||||
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
#
|
#
|
||||||
# @param target [String] Target file name.
|
# @param options [Hash] Builder run options.
|
||||||
# @param sources [Array<String>] Source file name(s).
|
|
||||||
# @param cache [Cache] The Cache object.
|
|
||||||
# @param env [Environment] The Environment executing the builder.
|
|
||||||
# @param vars [Hash,VarSet] Extra construction variables.
|
|
||||||
#
|
#
|
||||||
# @return [String,false]
|
# @return [String,false]
|
||||||
# Name of the target file on success or false on failure.
|
# Name of the target file on success or false on failure.
|
||||||
def run(target, sources, cache, env, vars)
|
def run(options)
|
||||||
# build sources to linkable objects
|
target, sources, cache, env, vars, objects = options.values_at(:target, :sources, :cache, :env, :vars, :setup_info)
|
||||||
objects = env.build_sources(sources, env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars).flatten, cache, vars)
|
vars = vars.merge({
|
||||||
if objects
|
'_TARGET' => target,
|
||||||
vars = vars.merge({
|
'_SOURCES' => objects,
|
||||||
'_TARGET' => target,
|
})
|
||||||
'_SOURCES' => objects,
|
command = env.build_command("${ARCMD}", vars)
|
||||||
})
|
standard_build("AR #{target}", target, command, objects, env, cache)
|
||||||
command = env.build_command("${ARCMD}", vars)
|
|
||||||
standard_build("AR #{target}", target, command, objects, env, cache)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ module Rscons
|
|||||||
# A default Rscons builder which knows how to produce an object file from
|
# A default Rscons builder which knows how to produce an object file from
|
||||||
# various types of source files.
|
# various types of source files.
|
||||||
class Object < Builder
|
class Object < Builder
|
||||||
|
|
||||||
# Mapping of known sources from which to build object files.
|
# Mapping of known sources from which to build object files.
|
||||||
KNOWN_SUFFIXES = {
|
KNOWN_SUFFIXES = {
|
||||||
"AS" => "ASSUFFIX",
|
"AS" => "ASSUFFIX",
|
||||||
@ -76,15 +77,12 @@ module Rscons
|
|||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
#
|
#
|
||||||
# @param target [String] Target file name.
|
# @param options [Hash] Builder run options.
|
||||||
# @param sources [Array<String>] Source file name(s).
|
|
||||||
# @param cache [Cache] The Cache object.
|
|
||||||
# @param env [Environment] The Environment executing the builder.
|
|
||||||
# @param vars [Hash,VarSet] Extra construction variables.
|
|
||||||
#
|
#
|
||||||
# @return [String,false]
|
# @return [ThreadedCommand]
|
||||||
# Name of the target file on success or false on failure.
|
# Threaded command to execute.
|
||||||
def run(target, sources, cache, env, vars)
|
def run(options)
|
||||||
|
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
||||||
vars = vars.merge({
|
vars = vars.merge({
|
||||||
'_TARGET' => target,
|
'_TARGET' => target,
|
||||||
'_SOURCES' => sources,
|
'_SOURCES' => sources,
|
||||||
@ -96,19 +94,36 @@ module Rscons
|
|||||||
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
||||||
end.first
|
end.first
|
||||||
command = env.build_command("${#{com_prefix}CMD}", vars)
|
command = env.build_command("${#{com_prefix}CMD}", vars)
|
||||||
unless cache.up_to_date?(target, command, sources, env)
|
if cache.up_to_date?(target, command, sources, env)
|
||||||
|
target
|
||||||
|
else
|
||||||
cache.mkdir_p(File.dirname(target))
|
cache.mkdir_p(File.dirname(target))
|
||||||
FileUtils.rm_f(target)
|
FileUtils.rm_f(target)
|
||||||
return false unless env.execute("#{com_prefix} #{target}", command)
|
ThreadedCommand.new(
|
||||||
deps = sources
|
command,
|
||||||
|
short_description: "#{com_prefix} #{target}",
|
||||||
|
builder_info: options.merge(vars: vars, command: command))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Finalize the build operation.
|
||||||
|
#
|
||||||
|
# @param options [Hash] Builder finalize options.
|
||||||
|
#
|
||||||
|
# @return [String,nil]
|
||||||
|
# Name of the target file on success or nil on failure.
|
||||||
|
def finalize(options)
|
||||||
|
if options[:command_status]
|
||||||
|
target, deps, cache, env, vars, command = options[:builder_info].values_at(:target, :sources, :cache, :env, :vars, :command)
|
||||||
if File.exists?(vars['_DEPFILE'])
|
if File.exists?(vars['_DEPFILE'])
|
||||||
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
|
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
|
||||||
FileUtils.rm_f(vars['_DEPFILE'])
|
FileUtils.rm_f(vars['_DEPFILE'])
|
||||||
end
|
end
|
||||||
cache.register_build(target, command, deps.uniq, env)
|
cache.register_build(target, command, deps.uniq, env)
|
||||||
|
target
|
||||||
end
|
end
|
||||||
target
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ module Rscons
|
|||||||
# A default Rscons builder that knows how to link object files into an
|
# A default Rscons builder that knows how to link object files into an
|
||||||
# executable program.
|
# executable program.
|
||||||
class Program < Builder
|
class Program < Builder
|
||||||
|
|
||||||
# Return default construction variables for the builder.
|
# Return default construction variables for the builder.
|
||||||
#
|
#
|
||||||
# @param env [Environment] The Environment using the builder.
|
# @param env [Environment] The Environment using the builder.
|
||||||
@ -45,20 +46,28 @@ module Rscons
|
|||||||
super(my_options)
|
super(my_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set up a build operation using this builder.
|
||||||
|
#
|
||||||
|
# @param options [Hash] Builder setup options.
|
||||||
|
#
|
||||||
|
# @return [Object]
|
||||||
|
# Any object that the builder author wishes to be saved and passed back
|
||||||
|
# in to the {#run} method.
|
||||||
|
def setup(options)
|
||||||
|
target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
|
||||||
|
suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
|
||||||
|
# Register builders to build each source to an object file or library.
|
||||||
|
env.register_builds(target, sources, suffixes, vars)
|
||||||
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
#
|
#
|
||||||
# @param target [String] Target file name.
|
# @param options [Hash] Builder run options.
|
||||||
# @param sources [Array<String>] Source file name(s).
|
|
||||||
# @param cache [Cache] The Cache object.
|
|
||||||
# @param env [Environment] The Environment executing the builder.
|
|
||||||
# @param vars [Hash,VarSet] Extra construction variables.
|
|
||||||
#
|
#
|
||||||
# @return [String,false]
|
# @return [String,false]
|
||||||
# Name of the target file on success or false on failure.
|
# Name of the target file on success or false on failure.
|
||||||
def run(target, sources, cache, env, vars)
|
def run(options)
|
||||||
# build sources to linkable objects
|
target, sources, cache, env, vars, objects = options.values_at(:target, :sources, :cache, :env, :vars, :setup_info)
|
||||||
objects = env.build_sources(sources, env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars).flatten, cache, vars)
|
|
||||||
return false unless objects
|
|
||||||
ld = env.expand_varref("${LD}", vars)
|
ld = env.expand_varref("${LD}", vars)
|
||||||
ld = if ld != ""
|
ld = if ld != ""
|
||||||
ld
|
ld
|
||||||
@ -77,6 +86,7 @@ module Rscons
|
|||||||
command = env.build_command("${LDCMD}", vars)
|
command = env.build_command("${LDCMD}", vars)
|
||||||
standard_build("LD #{target}", target, command, objects, env, cache)
|
standard_build("LD #{target}", target, command, objects, env, cache)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -806,28 +806,27 @@ EOF
|
|||||||
end
|
end
|
||||||
expect do
|
expect do
|
||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
env.Program("simple", %w[simple.c two.c])
|
env.Program("simple.exe", %w[simple.c two.c])
|
||||||
end
|
end
|
||||||
end.to raise_error /Failed to build simple/
|
end.to raise_error /Failed to build two\.o/
|
||||||
result = lines
|
result = lines
|
||||||
expect(result.size).to be > 2
|
expect(Set[*result]).to eq Set[
|
||||||
expect(result[0, 2]).to eq [
|
|
||||||
"CC simple.o",
|
"CC simple.o",
|
||||||
"CC two.o",
|
"CC two.o",
|
||||||
]
|
]
|
||||||
expect(File.exists?("simple.o")).to be_truthy
|
expect(File.exists?("simple.o")).to be_truthy
|
||||||
expect(File.exists?("two.o")).to be_falsey
|
expect(File.exists?("two.o")).to be_falsey
|
||||||
expect(File.exists?("two_sources#{Rscons::Environment.new["PROGSUFFIX"]}")).to be_falsey
|
expect(File.exists?("simple.exe")).to be_falsey
|
||||||
|
|
||||||
Rscons::Cache.reset!
|
Rscons::Cache.reset!
|
||||||
|
|
||||||
File.open("two.c", "w") {|fh|}
|
File.open("two.c", "w") {|fh|}
|
||||||
Rscons::Environment.new do |env|
|
Rscons::Environment.new do |env|
|
||||||
env.Program("simple", %w[simple.c two.c])
|
env.Program("simple.exe", %w[simple.c two.c])
|
||||||
end
|
end
|
||||||
expect(lines).to eq [
|
expect(lines).to eq [
|
||||||
"CC two.o",
|
"CC two.o",
|
||||||
"LD simple",
|
"LD simple.exe",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user