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.



788
789
790
791
# File 'lib/daedalus.rb', line 788

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

Instance Method Details

#build(ctx) ⇒ Object



829
830
831
832
833
# File 'lib/daedalus.rb', line 829

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

#cleanObject



835
836
837
838
839
840
841
842
843
# File 'lib/daedalus.rb', line 835

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

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

#consider(ctx, tasks) ⇒ Object



824
825
826
827
# File 'lib/daedalus.rb', line 824

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

#describe(ctx) ⇒ Object



845
846
847
848
849
850
851
# File 'lib/daedalus.rb', line 845

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

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

#file_info(ctx, files) ⇒ Object



853
854
855
856
857
858
859
860
861
862
# File 'lib/daedalus.rb', line 853

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



793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
# File 'lib/daedalus.rb', line 793

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