Class: Build::Graph::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/build/graph/node.rb

Overview

This is essentialy a immutable key:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inputs, outputs, process) ⇒ Node

Returns a new instance of Node.



30
31
32
33
34
35
36
37
# File 'lib/build/graph/node.rb', line 30

def initialize(inputs, outputs, process)
	# These are immutable - rather than change them, create a new node:
	@inputs = inputs
	@outputs = outputs
	
	# Represents an abstract process, e.g. a name or a function.
	@process = process
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



39
40
41
# File 'lib/build/graph/node.rb', line 39

def inputs
  @inputs
end

#outputsObject (readonly)

Returns the value of attribute outputs.



40
41
42
# File 'lib/build/graph/node.rb', line 40

def outputs
  @outputs
end

#processObject (readonly)

Returns the value of attribute process.



41
42
43
# File 'lib/build/graph/node.rb', line 41

def process
  @process
end

Class Method Details

.top(inputs = Files::Paths::NONE, outputs = :inherit, **options, &block) ⇒ Object



91
92
93
# File 'lib/build/graph/node.rb', line 91

def self.top(inputs = Files::Paths::NONE, outputs = :inherit, **options, &block)
	self.new(inputs, outputs, block, **options)
end

Instance Method Details

#dirty?Boolean

This is a canonical dirty function. All outputs must exist and must be newer than all inputs. This function is not efficient, in the sense that it must query all files on disk for last modified time.

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/build/graph/node.rb', line 54

def dirty?
	if inherit_outputs?
		return true
	elsif @inputs.count == 0 or @outputs.count == 0
		# If there are no inputs or no outputs we are always dirty:
		return true
		
		# I'm not entirely sure this is the correct approach. If input is a glob that matched zero items, but might match items that are older than outputs, what is the correct output from this function?
	else
		# Dirty if any outputs don't exist:
		return true if @outputs.any?{|path| !path.exist?}
		
		# Dirty if input modified after any output:
		if input_modified_time = self.modified_time
			# Outputs should always be more recent than their inputs:
			return true if @outputs.any?{|output_path| output_path.modified_time < input_modified_time}
		else
			# None of the inputs exist:
			true
		end
	end
	
	return false
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/build/graph/node.rb', line 79

def eql?(other)
	other.kind_of?(self.class) and @inputs.eql?(other.inputs) and @outputs.eql?(other.outputs) and @process.eql?(other.process)
end

#hashObject



83
84
85
# File 'lib/build/graph/node.rb', line 83

def hash
	[@inputs, @outputs, @process].hash
end

#inherit_outputs?Boolean

Nodes that inherit outputs are special in the sense that outputs are not available until all child nodes have been evaluated.

Returns:

  • (Boolean)


44
45
46
# File 'lib/build/graph/node.rb', line 44

def inherit_outputs?
	@outputs == :inherit
end

#inspectObject



87
88
89
# File 'lib/build/graph/node.rb', line 87

def inspect
	"<#{self.class.name} #{@inputs.inspect} => #{@outputs.inspect} by #{@process.inspect}>"
end

#modified_timeObject

This computes the most recent modified time for all inputs.



49
50
51
# File 'lib/build/graph/node.rb', line 49

def modified_time
	modified_time = @inputs.map{|path| path.modified_time}.max
end