Class: Rant::SourceNode

Inherits:
Object show all
Includes:
Node
Defined in:
lib/rant/import/nodes/default.rb

Overview

A SourceNode describes dependencies between source files. Thus there is no action attached to a SourceNode. The target should be an existing file as well as all dependencies.

An example would be a C source file which depends on other C source files because of #include statements.

Rantfile usage: gen SourceNode, “myext.c” => %w(ruby.h myext.h)

Direct Known Subclasses

SignedSourceNode

Instance Method Summary collapse

Methods included from Node

#inspect

Constructor Details

#initialize(rac, name, prerequisites = []) ⇒ SourceNode

Returns a new instance of SourceNode.



471
472
473
474
475
476
477
478
479
480
# File 'lib/rant/import/nodes/default.rb', line 471

def initialize(rac, name, prerequisites = [])
    super()
    @rac = rac
    @name = name or raise ArgumentError, "name not given"
    @pre = prerequisites
    @run = false
    # The timestamp is the latest of this file and all
    # dependencies:
    @ts = nil
end

Instance Method Details

#invoke(opt = INVOKE_OPT) ⇒ Object



525
526
527
528
# File 'lib/rant/import/nodes/default.rb', line 525

def invoke(opt = INVOKE_OPT)
           # self.timestamp would be required for correctness...
    false
end

#prerequisitesObject

Use this readonly!



482
483
484
# File 'lib/rant/import/nodes/default.rb', line 482

def prerequisites
    @pre
end


529
530
531
# File 'lib/rant/import/nodes/default.rb', line 529

def related_sources
    @pre
end

#timestamp(opt = INVOKE_OPT) ⇒ Object

Note: The timestamp will only be calculated once!



486
487
488
489
490
491
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
519
520
521
522
523
524
# File 'lib/rant/import/nodes/default.rb', line 486

def timestamp(opt = INVOKE_OPT)
    # Circular dependencies don't generate endless
    # recursion/loops because before calling the timestamp
    # method of any other node, we set @ts to some non-nil
    # value.
    return @ts if @ts
    goto_task_home
    if File.exist?(@name)
	@ts = File.mtime @name
    else
	rac.abort_at(ch, "SourceNode: no such file -- #@name")
    end
    sd = project_subdir
    @pre.each { |f|
	nodes = rac.resolve f, sd
	if nodes.empty?
	    if File.exist? f
		mtime = File.mtime f
		@ts = mtime if mtime > @ts
	    else
		rac.abort_at(ch, 
		    "SourceNode: no such file -- #{f}")
	    end
	else
	    nodes.each { |node|
                       node.invoke(opt)
		if node.respond_to? :timestamp
		    node_ts = node.timestamp(opt)
                           goto_task_home
		    @ts = node_ts if node_ts > @ts
		else
		    rac.abort_at(ch, 
			"SourceNode can't depend on #{node.name}")
		end
	    }
	end
    }
    @ts
end