Class: Daedalus::Program

Inherits:
Path
  • Object
show all
Defined in:
lib/daedalus.rb

Instance Attribute Summary

Attributes inherited from Path

#data, #path

Instance Method Summary collapse

Methods inherited from Path

#artifacts_path, #basename, #data_path, #save!

Constructor Details

#initialize(path, files) ⇒ Program

Returns a new instance of Program.



709
710
711
712
# File 'lib/daedalus.rb', line 709

def initialize(path, files)
  super path
  @files = files.sort_by { |x| x.path }
end

Instance Method Details

#build(ctx) ⇒ Object



750
751
752
753
# File 'lib/daedalus.rb', line 750

def build(ctx)
  ctx.log.inc!
  ctx.link @path, objects
end

#cleanObject



755
756
757
758
759
760
761
762
763
# File 'lib/daedalus.rb', line 755

def clean
  @files.each do |f|
    f.clean if f.respond_to? :clean
  end

  File.unlink @path if File.exists?(@path)
  File.unlink data_path if File.exists?(data_path)
  Dir.rmdir artifacts_path if Dir.entries(artifacts_path).empty?
end

#consider(ctx, tasks) ⇒ Object



745
746
747
748
# File 'lib/daedalus.rb', line 745

def consider(ctx, tasks)
  @files.each { |x| x.consider(ctx, tasks) }
  tasks.post << self unless tasks.empty? and File.exists?(@path)
end

#describe(ctx) ⇒ Object



765
766
767
768
769
770
771
# File 'lib/daedalus.rb', line 765

def describe(ctx)
  puts "Program: #{@path}"

  @files.each do |f|
    f.describe(ctx)
  end
end

#file_info(ctx, files) ⇒ Object



773
774
775
776
777
778
779
780
781
782
# File 'lib/daedalus.rb', line 773

def file_info(ctx, files)
  files.each do |n|
    obj = @files.find { |x| x.path == n }
    if obj
      obj.info(ctx)
    else
      puts "Unable to find file: #{n}"
    end
  end
end

#objectsObject



714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
# File 'lib/daedalus.rb', line 714

def objects
  # This partitions the list into .o's first and .a's last. This
  # is because gcc on some platforms require that static libraries
  # be linked last. This is because gcc builds a list of undefined
  # symbols, and then when it hits a .a, looks in the archive
  # to try and resolve those symbols. So if a .o needs something
  # from a .a, the .a MUST come after the .o
  objects = []
  archives = []

  @files.each do |x|
    if x.respond_to? :object_path
      if File.extname(x.object_path) == ".a"
        archives << x.object_path
      else
        objects << x.object_path
      end
    else
      x.objects.each do |obj|
        if File.extname(obj) == ".a"
          archives << obj
        else
          objects << obj
        end
      end
    end
  end

  objects.sort + archives
end