class Daedalus::Compiler

Attributes

cc[R]
cflags[R]
cxx[R]
cxxflags[R]
ldflags[R]
ldshared[R]
ldsharedxx[R]
log[R]
mtime_only[RW]
path[R]

Public Class Methods

new(cc, cxx, ldshared, ldsharedxx, logger, blueprint) click to toggle source
    # File lib/daedalus.rb
140 def initialize(cc, cxx, ldshared, ldsharedxx, logger, blueprint)
141   @cc = cc
142   @cxx = cxx
143   @ldshared = ldshared
144   @ldsharedxx = ldsharedxx
145   @cflags = []
146   @cxxflags = []
147   @ldflags = []
148   @libraries = []
149   @pre_link_cmds = []
150   @log = logger
151   @blueprint = blueprint
152 
153   @mod_times = Hash.new do |h,k|
154     h[k] = (File.exist?(k) ? File.mtime(k) : Time.at(0))
155   end
156 
157   @sha1_mtimes = {}
158   @sha1s = Hash.new do |h,k|
159     if File.exist?(k)
160       @log.verbose "computing SHA1: #{k}"
161       @sha1_mtimes[k] = File.mtime(k)
162       h[k] = Digest::SHA1.file(k).hexdigest
163     else
164       h[k] = ""
165     end
166   end
167 
168   @mtime_only = false
169 end

Public Instance Methods

add_library(lib) click to toggle source
    # File lib/daedalus.rb
188 def add_library(lib)
189   if f = lib.cflags
190     @cflags = f + @cflags
191     @cflags.uniq!
192   end
193 
194   if f = lib.ldflags
195     @ldflags = f + @ldflags
196     @ldflags.uniq!
197   end
198 end
ar(library, objects) click to toggle source
    # File lib/daedalus.rb
256 def ar(library, objects)
257   @log.show "AR", library
258   @log.command "ar rv #{library} #{objects.join(' ')}"
259   @log.command "ranlib #{library}"
260 end
c_compile(source, object) click to toggle source
    # File lib/daedalus.rb
226 def c_compile(source, object)
227   @log.show "CC", source
228   @log.command "#{@cc} #{@cflags.join(' ')} -c -o #{object} #{source}"
229 end
calculate_deps(path) click to toggle source
    # File lib/daedalus.rb
267 def calculate_deps(path)
268   dirs = header_directories() + ["/usr/include"]
269   flags = @cflags.join(' ')
270   begin
271     dep = DependencyGrapher.new @cc, [path], dirs, flags
272     dep.process
273 
274     # This is a quick work-around for a craptastic bug that I can't figure
275     # out. Sometimes this raises an exception saying it can't find a file
276     # which is pretty obviously there. I've been unable to figure out
277     # what causes this and thus how to fix.
278     #
279     # So as a temporary measure, if an exception is raised, I'm going to
280     # just do it again. Previous results have shown that this should
281     # work the 2nd time even though the first time failed.
282     #
283     # I know this sounds silly, but we need some fix for this.
284   rescue Exception
285     dep = DependencyGrapher.new @cc, [path], dirs, flags
286     dep.process
287   end
288 
289   dep.sources.first.dependencies.sort
290 end
compile(source, object) click to toggle source
    # File lib/daedalus.rb
218 def compile(source, object)
219   if source =~ /\.cpp$/
220     cxx_compile(source, object)
221   else
222     c_compile(source, object)
223   end
224 end
cxx_compile(source, object) click to toggle source
    # File lib/daedalus.rb
231 def cxx_compile(source, object)
232   @log.show "CXX", source
233   @log.command "#{@cxx} #{@cflags.join(' ')} #{@cxxflags.join(' ')} -c -o #{object} #{source}"
234 end
header_directories() click to toggle source
    # File lib/daedalus.rb
173 def header_directories
174   dirs = []
175   @cflags.each do |fl|
176     fl.split(/\s+/).each do |part|
177       if part.index("-I") == 0
178         dirs << part[2..-1]
179       end
180     end
181   end
182   dirs
183 end
mtime(path) click to toggle source
    # File lib/daedalus.rb
204 def mtime(path)
205   @mod_times[path]
206 end
sha1(path) click to toggle source
    # File lib/daedalus.rb
208 def sha1(path)
209   if @sha1s.key?(path)
210     if File.mtime(path) > @sha1_mtimes[path]
211       @sha1s.delete(path)
212     end
213   end
214 
215   @sha1s[path]
216 end