lib/rscons/builders/object.rb in rscons-1.9.3 vs lib/rscons/builders/object.rb in rscons-1.10.0

- old
+ new

@@ -1,10 +1,11 @@ module Rscons module Builders # A default Rscons builder which knows how to produce an object file from # various types of source files. class Object < Builder + # Mapping of known sources from which to build object files. KNOWN_SUFFIXES = { "AS" => "ASSUFFIX", "CC" => "CSUFFIX", "CXX" => "CXXSUFFIX", @@ -59,56 +60,68 @@ end # Return whether this builder object is capable of producing a given target # file name from a given source file name. # - # @param target [String] The target file name. - # @param source [String] The source file name. - # @param env [Environment] The Environment. + # @param target [String] + # The target file name. + # @param source [String] + # The source file name. + # @param env [Environment] + # The Environment. # # @return [Boolean] # Whether this builder object is capable of producing a given target # file name from a given source file name. def produces?(target, source, env) - target.end_with?(*env['OBJSUFFIX']) and KNOWN_SUFFIXES.find do |compiler, suffix_var| - source.end_with?(*env[suffix_var]) - end + target.end_with?(*env['OBJSUFFIX']) and + KNOWN_SUFFIXES.find do |compiler, suffix_var| + source.end_with?(*env[suffix_var]) + end end # 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) vars = vars.merge({ '_TARGET' => target, '_SOURCES' => sources, '_DEPFILE' => Rscons.set_suffix(target, env.expand_varref("${DEPFILESUFFIX}", vars)), }) com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var| - sources.first.end_with?(*env.expand_varref("${#{suffix_var}}")) + sources.first.end_with?(*env.expand_varref("${#{suffix_var}}", vars)) 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) - unless cache.up_to_date?(target, command, sources, env) - cache.mkdir_p(File.dirname(target)) - FileUtils.rm_f(target) - return false unless env.execute("#{com_prefix} #{target}", command) - deps = sources + # 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 + + # 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'], target) FileUtils.rm_f(vars['_DEPFILE']) end - cache.register_build(target, command, deps.uniq, env) + cache.register_build(target, options[:tc].command, deps.uniq, env) + target end - target end + end end end