Class: Daedalus::ExternalLibrary

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ExternalLibrary

Returns a new instance of ExternalLibrary.



456
457
458
459
460
461
462
463
464
465
466
# File 'lib/daedalus.rb', line 456

def initialize(path)
  @path = path

  @cflags = nil
  @ldflags = nil
  @objects = nil

  @build_dir = path
  @builder = nil
  @data = nil
end

Instance Attribute Details

#cflagsObject

Returns the value of attribute cflags.



468
469
470
# File 'lib/daedalus.rb', line 468

def cflags
  @cflags
end

#ldflagsObject

Returns the value of attribute ldflags.



468
469
470
# File 'lib/daedalus.rb', line 468

def ldflags
  @ldflags
end

#objectsObject

Returns the value of attribute objects.



468
469
470
# File 'lib/daedalus.rb', line 468

def objects
  @objects
end

#pathObject

Returns the value of attribute path.



468
469
470
# File 'lib/daedalus.rb', line 468

def path
  @path
end

Instance Method Details

#build(ctx) ⇒ Object



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/daedalus.rb', line 528

def build(ctx)
  raise "Unable to build" unless @builder

  ctx.log.inc!

  ctx.log.show "LB", @build_dir

  Dir.chdir(@build_dir) do
    @builder.call(ctx.log)
  end

  @data[:sha1] = sha1()

  File.open(@data_file, "wb") do |f|
    f << Marshal.dump(@data)
  end
end

#consider(ctx, tasks) ⇒ Object



524
525
526
# File 'lib/daedalus.rb', line 524

def consider(ctx, tasks)
  tasks.pre << self if out_of_date?(ctx)
end

#describe(ctx) ⇒ Object



546
547
# File 'lib/daedalus.rb', line 546

def describe(ctx)
end

#file(f) ⇒ Object



490
491
492
# File 'lib/daedalus.rb', line 490

def file(f)
  File.join(@path, f)
end

#have_objectsObject



508
509
510
511
512
513
514
515
# File 'lib/daedalus.rb', line 508

def have_objects
  return true unless @objects
  @objects.each do |o|
    return false unless File.exists?(o)
  end

  return true
end

#out_of_date?(ctx) ⇒ Boolean

Returns:

  • (Boolean)


517
518
519
520
521
522
# File 'lib/daedalus.rb', line 517

def out_of_date?(ctx)
  return true  unless have_objects
  return false unless @builder
  return false if @data and @data[:sha1] == sha1
  return true
end

#sha1Object



494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/daedalus.rb', line 494

def sha1
  sha1 = Digest::SHA1.new

  Dir["#{@build_dir}/*"].each do |f|
    sha1.file(f) if File.file?(f)
  end

  Dir["#{@build_dir}/**/*"].each do |f|
    sha1.file(f) if File.file?(f)
  end

  sha1.hexdigest
end

#to_build(&blk) ⇒ Object



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/daedalus.rb', line 470

def to_build(&blk)
  @builder = blk

  @data_file = "#{@build_dir}.data"

  if File.exists?(@data_file)
    begin
      File.open @data_file, "rb" do |f|
        @data = Marshal.load(f.read)
      end
    rescue
      STDERR.puts "WARNING: ExternalLibrary#to_build: load '#{data_path}' failed"
      @data = {}
    end
  else
    @data = {}
  end

end