diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 05e5ad3..dfe798f 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -427,6 +427,8 @@ module Rscons # # This method is used internally by Rscons builders. # + # @deprecated Use {#register_builds} instead. + # # @param sources [Array] List of source files to build. # @param suffixes [Array] # List of suffixes to try to convert source files into. @@ -454,6 +456,43 @@ module Rscons end end + # Find and register builders to build source files into files containing + # one of the suffixes given by suffixes. + # + # This method is used internally by Rscons builders. It should be called + # from the builder's #setup method. + # + # @param sources [Array] + # List of source file(s) to build. + # @param suffixes [Array] + # List of suffixes to try to convert source files into. + # @param vars [Hash] + # Extra variables to pass to the builders. + # + # @return [Array] + # List of the output file name(s). + def register_builds(sources, suffixes, vars) + sources.map do |source| + if source.end_with?(*suffixes) + source + else + output_fname = nil + suffixes.each do |suffix| + attempt_output_fname = get_build_fname(source, suffix) + builder = @builders.values.find do |builder| + builder.produces?(attempt_output_fname, source, self) + end + if builder + output_fname = attempt_output_fname + self.__send__(builder.name, output_fname, source, vars) + break + end + end + output_fname or raise "Could not find a builder for #{source.inspect}." + end + end + end + # Invoke a builder to build the given target based on the given sources. # # @param builder [Builder] The Builder to use.