Module: Rscons::Builders::Mixins::Object

Includes:
Depfile
Included in:
Object, SharedObject
Defined in:
lib/rscons/builders/mixins/object.rb

Overview

Mixin for builders needing to build object files.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Depfile

#finalize_command_with_depfile

Class Method Details

.included(klass) ⇒ Object

Hook called by Ruby when this module is included by a class (klass).



18
19
20
# File 'lib/rscons/builders/mixins/object.rb', line 18

def included(klass)
  klass.__send__(:extend, ClassMethods)
end

Instance Method Details

#initialize(params) ⇒ Object

Construct a builder conforming to the Object interface.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rscons/builders/mixins/object.rb', line 51

def initialize(params)
  super
  build_params = self.class.providers.find do |build_params|
    @sources.first.end_with?(*@env.expand_varref(build_params[:suffix], @vars))
  end
  unless build_params
    raise "Unknown input file type: #{@sources.first.inspect}"
  end
  @command_template =
    if @vars[:direct]
      build_params[:direct_command]
    else
      build_params[:command]
    end
  @short_description = build_params[:short_description] || "Compiling"
  @preferred_ld = build_params[:preferred_ld]
end

#run(params) ⇒ Object

Run the builder to produce a build target.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rscons/builders/mixins/object.rb', line 70

def run(params)
  if @command
    finalize_command_with_depfile
  else
    @vars["_TARGET"] = @target
    @vars["_SOURCES"] = @sources
    depfilesuffix = @env.expand_varref("${DEPFILESUFFIX}", vars)
    @vars["_DEPFILE"] =
      if @vars[:direct]
        @env.get_build_fname(target, depfilesuffix, self.class)
      else
        "#{target}#{depfilesuffix}"
      end
    @cache.mkdir_p(File.dirname(@vars["_DEPFILE"]))
    command = @env.build_command(@command_template, @vars)
    self.produces(@vars["_DEPFILE"])
    if @vars[:direct]
      message = "#{@short_description}/Linking <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>"
    else
      message = "#{@short_description} <source>#{Util.short_format_paths(@sources)}<reset>"
    end
    standard_command(message, command)
  end
end