fully parallelize the Preprocess builder
This commit is contained in:
parent
178940cd5d
commit
80a80a7cb0
@ -79,8 +79,9 @@ module Rscons
|
||||
#
|
||||
# @param options [Hash] Builder run options.
|
||||
#
|
||||
# @return [ThreadedCommand]
|
||||
# Threaded command to execute.
|
||||
# @return [String, ThreadedCommand]
|
||||
# Target file name if target is up to date or a {ThreadedCommand}
|
||||
# to execute to build the target.
|
||||
def run(options)
|
||||
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
||||
vars = vars.merge({
|
||||
@ -88,14 +89,14 @@ module Rscons
|
||||
'_SOURCES' => sources,
|
||||
'_DEPFILE' => Rscons.set_suffix(target, env.expand_varref("${DEPFILESUFFIX}", vars)),
|
||||
})
|
||||
# Store vars back into options so new keys are accessible in #finalize.
|
||||
options[:vars] = vars
|
||||
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
||||
sources.first.end_with?(*env.expand_varref("${#{suffix_var}}"))
|
||||
end.tap do |v|
|
||||
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
||||
end.first
|
||||
command = env.build_command("${#{com_prefix}CMD}", vars)
|
||||
# Store vars back into options so new keys are accessible in #finalize.
|
||||
options[:vars] = vars
|
||||
standard_threaded_build("#{com_prefix} #{target}", target, command, sources, env, cache)
|
||||
end
|
||||
|
||||
@ -103,7 +104,7 @@ module Rscons
|
||||
#
|
||||
# @param options [Hash] Builder finalize options.
|
||||
#
|
||||
# @return [String,nil]
|
||||
# @return [String, nil]
|
||||
# Name of the target file on success or nil on failure.
|
||||
def finalize(options)
|
||||
if options[:command_status]
|
||||
|
@ -20,15 +20,13 @@ module Rscons
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
#
|
||||
# @param target [String] Target file name.
|
||||
# @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.
|
||||
# @param options [Hash] Builder run options.
|
||||
#
|
||||
# @return [String,false]
|
||||
# Name of the target file on success or false on failure.
|
||||
def run(target, sources, cache, env, vars)
|
||||
# @return [String, ThreadedCommand]
|
||||
# Target file name if target is up to date or a {ThreadedCommand}
|
||||
# to execute to build the target.
|
||||
def run(options)
|
||||
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
||||
if sources.find {|s| s.end_with?(*env.expand_varref("${CXXSUFFIX}", vars))}
|
||||
pp_cc = "${CXX}"
|
||||
depgen = "${CXXDEPGEN}"
|
||||
@ -42,18 +40,28 @@ module Rscons
|
||||
"_SOURCES" => sources,
|
||||
"_DEPFILE" => Rscons.set_suffix(target, env.expand_varref("${DEPFILESUFFIX}", vars)))
|
||||
command = env.build_command("${CPP_CMD}", vars)
|
||||
unless cache.up_to_date?(target, command, sources, env)
|
||||
cache.mkdir_p(File.dirname(target))
|
||||
return false unless env.execute("Preprocess #{target}", command)
|
||||
deps = sources
|
||||
if File.exists?(vars["_DEPFILE"])
|
||||
deps += Environment.parse_makefile_deps(vars["_DEPFILE"], nil)
|
||||
FileUtils.rm_f(vars["_DEPFILE"])
|
||||
# Store vars back into options so new keys are accessible in #finalize.
|
||||
options[:vars] = vars
|
||||
standard_threaded_build("#{name} #{target}", target, command, sources, env, cache)
|
||||
end
|
||||
cache.register_build(target, command, deps.uniq, env)
|
||||
|
||||
# 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 = options.values_at(:target, :sources, :cache, :env, :vars)
|
||||
if File.exists?(vars['_DEPFILE'])
|
||||
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], nil)
|
||||
FileUtils.rm_f(vars['_DEPFILE'])
|
||||
end
|
||||
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
||||
target
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,48 +0,0 @@
|
||||
module Rscons
|
||||
module Builders
|
||||
describe Preprocess do
|
||||
|
||||
let(:env) {Environment.new}
|
||||
subject {Preprocess.new}
|
||||
|
||||
it "supports overriding CC construction variable" do
|
||||
cache = double(Cache)
|
||||
command = %w[my_cpp -E -MMD -MF module.mf -o module.pp module.c]
|
||||
expect(cache).to receive(:up_to_date?).with("module.pp", command, %w[module.c], env).and_return(false)
|
||||
expect(cache).to receive(:mkdir_p).with(".")
|
||||
expect(env).to receive(:execute).with("Preprocess module.pp", command).and_return(true)
|
||||
expect(File).to receive(:exists?).with("module.mf").and_return(true)
|
||||
expect(Environment).to receive(:parse_makefile_deps).with("module.mf", nil).and_return(%w[module.c one.h two.h])
|
||||
expect(FileUtils).to receive(:rm_f).with("module.mf")
|
||||
expect(cache).to receive(:register_build).with("module.pp", command, %w[module.c one.h two.h], env)
|
||||
|
||||
expect(subject.run("module.pp", ["module.c"], cache, env, "CC" => "my_cpp")).to eq("module.pp")
|
||||
end
|
||||
|
||||
it "supports overriding CPP_CMD construction variable" do
|
||||
cache = double(Cache)
|
||||
command = %w[my_cpp module.c]
|
||||
expect(cache).to receive(:up_to_date?).with("module.pp", command, %w[module.c], env).and_return(false)
|
||||
expect(cache).to receive(:mkdir_p).with(".")
|
||||
expect(env).to receive(:execute).with("Preprocess module.pp", command).and_return(true)
|
||||
expect(File).to receive(:exists?).with("module.mf").and_return(true)
|
||||
expect(Environment).to receive(:parse_makefile_deps).with("module.mf", nil).and_return(%w[module.c one.h two.h])
|
||||
expect(FileUtils).to receive(:rm_f).with("module.mf")
|
||||
expect(cache).to receive(:register_build).with("module.pp", command, %w[module.c one.h two.h], env)
|
||||
|
||||
expect(subject.run("module.pp", ["module.c"], cache, env, "CPP_CMD" => ["my_cpp", "${_SOURCES}"])).to eq("module.pp")
|
||||
end
|
||||
|
||||
it "returns false if executing the preprocessor fails" do
|
||||
cache = double(Cache)
|
||||
command = %w[gcc -E -MMD -MF module.mf -o module.pp module.c]
|
||||
expect(cache).to receive(:up_to_date?).with("module.pp", command, %w[module.c], env).and_return(false)
|
||||
expect(cache).to receive(:mkdir_p).with(".")
|
||||
expect(env).to receive(:execute).with("Preprocess module.pp", command).and_return(false)
|
||||
|
||||
expect(subject.run("module.pp", ["module.c"], cache, env, {})).to eq(false)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user