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) ⇒ Node

Returns a new instance of Node.

Parameters:

  • process (Object)

    Represents an abstract process, e.g. a name or a function.



29
30
31
32
# File 'lib/build/graph/node.rb', line 29

def initialize(inputs, outputs)
	@inputs = inputs
	@outputs = outputs
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



34
35
36
# File 'lib/build/graph/node.rb', line 34

def inputs
  @inputs
end

#outputsObject (readonly)

Returns the value of attribute outputs.



35
36
37
# File 'lib/build/graph/node.rb', line 35

def outputs
  @outputs
end

Class Method Details

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



96
97
98
# File 'lib/build/graph/node.rb', line 96

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

Instance Method Details

#==(other) ⇒ Object



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

def == other
	self.equal?(other) or
		self.class == other.class and
		@inputs == other.inputs and
		@outputs == other.outputs
end

#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)


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

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 inputs or outputs missing:
		return true if missing?
		
		# 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)


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

def eql?(other)
	self.equal?(other) or self == other
end

#hashObject



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

def hash
	@inputs.hash ^ @outputs.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)


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

def inherit_outputs?
	@outputs == :inherit
end

#inspectObject



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

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

#missing?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/build/graph/node.rb', line 47

def missing?
	@outputs.any?{|path| !path.exist?} || @inputs.any?{|path| !path.exist?}
end

#modified_timeObject

This computes the most recent modified time for all inputs.



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

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