Class: Rubu::Build

Inherits:
Action show all
Includes:
FlowRun
Defined in:
lib/rubu.rb

Overview

Build Action. Build Action takes one or more sources, and turns them into one or more targets.

Direct Known Subclasses

AlwaysBuild, DateBuild, MarkBuild

Instance Attribute Summary (collapse)

Attributes inherited from Action

#errmsg, #output, #status, #subs

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from FlowRun

#parallel_run, #serial_run

Methods inherited from Action

#display, #error, #host, #host_in, #host_out, #pick, #use

Constructor Details

- (Build) initialize(sources = [], targets = [])

Returns a new instance of Build



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/rubu.rb', line 450

def initialize( sources = [], targets = [] )
    super()

    unless sources.kind_of? Array
        @sources = [ sources ]
    else
        @sources = sources
    end

    unless targets.kind_of? Array
        @targets = [ targets ]
    else
        @targets = targets
    end

    setup
end

Instance Attribute Details

- (Object) sources (readonly)

Returns the value of attribute sources



447
448
449
# File 'lib/rubu.rb', line 447

def sources
  @sources
end

- (Object) targets (readonly)

Returns the value of attribute targets



448
449
450
# File 'lib/rubu.rb', line 448

def targets
  @targets
end

Class Method Details

+ (Object) use(sources = [], targets = [])

Create Action and register.



427
428
429
# File 'lib/rubu.rb', line 427

def self.use( sources = [], targets = [] )
    self.new( sources, targets ).use
end

+ (Object) usezip(sources, targets)

Combine list of sources and targets to source/target pairs and register.



440
441
442
443
444
# File 'lib/rubu.rb', line 440

def self.usezip( sources, targets )
    sources.zip( targets ).map do |pair|
        self.new( *pair ).use
    end
end

+ (Object) zip(sources, targets)

Combine list of sources and targets to source/target pairs.



432
433
434
435
436
# File 'lib/rubu.rb', line 432

def self.zip( sources, targets )
    sources.zip( targets ).map do |pair|
        self.new( *pair )
    end
end

Instance Method Details

- (Boolean) date_update?

Check for date (timestamp) based update needs.

Returns:

  • (Boolean)


492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/rubu.rb', line 492

def date_update?

    # Check if targets are missing.
    @targets.each do |target|
        unless target.exist?
            return true
        end
    end

    # Check if source(s) are newer than target(s).

    newest_source = Time.new( 0 )
    @sources.each do |source|
        if source.time > newest_source && !source.skip
            newest_source = source.time
        end
    end

    oldest_target = Time.now
    @targets.each do |target|
        if target.time < oldest_target
            oldest_target = target.time
        end
    end

    return newest_source > oldest_target
end

- (Object) fork(&blk)

Execute commands (in block) in parallel.



585
586
587
588
589
590
# File 'lib/rubu.rb', line 585

def fork( &blk )
    host_in
    instance_eval &blk
    host_out
    parallel_run
end

- (Boolean) mark_update?

Check for mark (checksum) based update needs.

Returns:

  • (Boolean)


522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/rubu.rb', line 522

def mark_update?

    unless date_update?
        return false
    end

    # Check if targets are missing.
    unless target.exist?
        return true
    end

    old_verbose = Order[ :verbose ]
    Order[ :verbose ] = false
    build
    Order[ :verbose ] = old_verbose

    unless target.exist?
        error "file generation failure"
        exit false
    end

    unless State.md5_check_and_update?( target.rpath )
        target.skip = true
        return false
    end

    true
end

- (Object) rbdef(desc = nil, &cmd)

Define and register Ruby command.



579
580
581
582
# File 'lib/rubu.rb', line 579

def rbdef( desc = nil, &cmd )
    rb = RubyCommand.new( desc, &cmd )
    rb.use
end

- (Object) rbrun(desc = nil, &cmd)

Define and run Ruby command.



574
575
576
# File 'lib/rubu.rb', line 574

def rbrun( desc = nil, &cmd )
    RubyCommand.new( desc, &cmd ).run
end

- (Object) run

Run Build Action and capture status.



475
476
477
478
479
480
481
482
# File 'lib/rubu.rb', line 475

def run
    if update?
        build
    else
        @status = :success
    end
    self
end

- (Object) setup

Defined by users.



470
471
# File 'lib/rubu.rb', line 470

def setup
end

- (Object) shdef(cmd)

Define and register Shell command.



568
569
570
571
# File 'lib/rubu.rb', line 568

def shdef( cmd )
    sh = ShellCommand.new( cmd )
    sh.use
end

- (Object) shrun(cmd)

Define and run Shell command.



563
564
565
# File 'lib/rubu.rb', line 563

def shrun( cmd )
    ShellCommand.new( cmd ).run
end

- (Object) source

Main (first) source file.



553
554
555
# File 'lib/rubu.rb', line 553

def source
    @sources[0]
end

- (Object) target

Main (first) target file.



558
559
560
# File 'lib/rubu.rb', line 558

def target
    @targets[0]
end

- (Boolean) update?

Default update.

Returns:

  • (Boolean)


486
487
488
# File 'lib/rubu.rb', line 486

def update?
    true
end

- (Object) walk(&blk)

Execute commands (in block) in series.



593
594
595
596
597
598
# File 'lib/rubu.rb', line 593

def walk( &blk )
    host_in
    instance_eval &blk
    host_out
    serial_run
end