class Daedalus::SourceFile

Public Class Methods

new(path) click to toggle source
Calls superclass method Daedalus::Path::new
    # File lib/daedalus.rb
336 def initialize(path)
337   super
338   @static_deps = []
339   @autogen_builder = nil
340 end

Public Instance Methods

autogenerate(&builder) click to toggle source
    # File lib/daedalus.rb
346 def autogenerate(&builder)
347   @autogen_builder = builder
348 end
build(ctx) click to toggle source
    # File lib/daedalus.rb
423 def build(ctx)
424   ctx.log.inc!
425 
426   if @autogen_builder
427     ctx.log.show "GN", @path
428     @autogen_builder.call(ctx.log)
429   end
430 
431   @data[:sha1] = sha1(ctx)
432   ctx.compile path, object_path
433   save!
434 end
clean() click to toggle source
    # File lib/daedalus.rb
436 def clean
437   File.unlink object_path if File.exist?(object_path)
438   File.unlink data_path if File.exist?(data_path)
439 
440   Dir.rmdir artifacts_path if Dir.entries(artifacts_path).empty?
441 end
consider(ctx, tasks) click to toggle source
    # File lib/daedalus.rb
419 def consider(ctx, tasks)
420   tasks << self if out_of_date?(ctx)
421 end
dependencies(ctx) click to toggle source
    # File lib/daedalus.rb
354 def dependencies(ctx)
355   deps = @data[:deps]
356 
357   if ctx.sha1(@path) != @data[:dep_sha1] or !deps
358     deps = recalc_depedencies(ctx)
359   end
360 
361   return deps + @static_deps
362 end
depends_on(static_deps) click to toggle source
    # File lib/daedalus.rb
342 def depends_on(static_deps)
343   @static_deps = static_deps
344 end
describe(ctx) click to toggle source
    # File lib/daedalus.rb
443 def describe(ctx)
444   if !File.exist?(object_path)
445     puts "#{@path}: unbuilt"
446   else
447     if @data[:sha1] != sha1(ctx)
448       puts "#{@path}: out-of-date"
449     end
450 
451     deps = newer_dependencies(ctx)
452 
453     unless deps.empty?
454       puts "#{@path}: dependencies changed"
455       deps.each do |d|
456         puts "  - #{d}"
457       end
458     end
459   end
460 end
info(ctx) click to toggle source
    # File lib/daedalus.rb
462 def info(ctx)
463   puts @path
464   puts "  object: #{object_path}"
465   puts "  last hash: #{@data[:sha1]}"
466   puts "  curr hash: #{sha1(ctx)}"
467 
468   puts "  dependencies:"
469   dependencies(ctx).each do |x|
470     puts "    #{x}"
471   end
472 end
newer_dependencies(ctx) click to toggle source
    # File lib/daedalus.rb
399 def newer_dependencies(ctx)
400   dependencies(ctx).find_all do |x|
401     ctx.mtime(x) > ctx.mtime(object_path)
402   end
403 end
object_path() click to toggle source
    # File lib/daedalus.rb
350 def object_path
351   File.join artifacts_path, "#{basename}.o"
352 end
out_of_date?(ctx) click to toggle source
    # File lib/daedalus.rb
405 def out_of_date?(ctx)
406   unless File.exist?(@path)
407     return true if @autogen_builder
408     raise Errno::ENOENT, "Missing #{@path}"
409   end
410 
411   return true unless File.exist?(object_path)
412 
413   return true if ctx.mtime_only and ctx.mtime(@path) > ctx.mtime(object_path)
414 
415   return true unless @data[:sha1] == sha1(ctx)
416   return false
417 end
recalc_depedencies(ctx) click to toggle source
    # File lib/daedalus.rb
364 def recalc_depedencies(ctx)
365   deps = ctx.calculate_deps(@path)
366 
367   @data[:dep_sha1] = ctx.sha1(@path)
368   @data[:deps] = deps
369 
370   return deps
371 end
sha1(ctx) click to toggle source
    # File lib/daedalus.rb
373 def sha1(ctx)
374   sha1 = Digest::SHA1.new
375   sha1 << ctx.sha1(@path)
376 
377   begin
378     dependencies(ctx).each do |d|
379       sha1 << ctx.sha1(d)
380     end
381   rescue StandardError
382     recalc_depedencies(ctx)
383 
384     sha1 = Digest::SHA1.new
385     sha1 << ctx.sha1(@path)
386 
387     dependencies(ctx).each do |d|
388       begin
389         sha1 << ctx.sha1(d)
390       rescue StandardError
391         raise "Unable to find dependency '#{d}' from #{@path}"
392       end
393     end
394   end
395 
396   sha1.hexdigest
397 end