Class: Build::BuildTask

Inherits:
Task
  • Object
show all
Defined in:
lib/build/build_node.rb

Overview

This task class serves as the base class for the environment specific task classes genearted when adding targets.

Defined Under Namespace

Classes: CommandFailure

Instance Attribute Summary collapse

Attributes inherited from Task

#group, #logger

Instance Method Summary collapse

Methods inherited from Task

#initialize, #name, #node_string, #task_class, #update

Constructor Details

This class inherits a constructor from Build::Task

Instance Attribute Details

#output_environmentObject

Returns the value of attribute output_environment.



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

def output_environment
  @output_environment
end

Instance Method Details

#cp(source_path, destination_path) ⇒ Object



128
129
130
131
132
133
# File 'lib/build/build_node.rb', line 128

def cp(source_path, destination_path)
	return unless wet?
	
	Console::Event::Spawn.for('cp', source_path, destination_path).emit(self)
	FileUtils.copy(source_path, destination_path)
end

#install(source_path, destination_path) ⇒ Object



151
152
153
154
155
156
# File 'lib/build/build_node.rb', line 151

def install(source_path, destination_path)
	return unless wet?
	
	Console::Event::Spawn.for('install', source_path, destination_path).emit(self)
	FileUtils.install(source_path, destination_path)
end

#invoke_rule(rule, arguments, &block) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/build/build_node.rb', line 167

def invoke_rule(rule, arguments, &block)
	arguments = rule.normalize(arguments, self)
	
	@logger&.debug(self) {"-> #{rule}(#{arguments.inspect})"}
	
	invoke(
		RuleNode.new(rule, arguments, &block)
	)
	
	@logger&.debug(self) {"<- #{rule}(...) -> #{rule.result(arguments)}"}
	
	return rule.result(arguments)
end

#mkpath(path) ⇒ Object



142
143
144
145
146
147
148
149
# File 'lib/build/build_node.rb', line 142

def mkpath(path)
	return unless wet?
	
	unless File.exist?(path)
		Console::Event::Spawn.for('mkdir', '-p', path).emit(self)
		FileUtils.mkpath(path)
	end
end

#rm(path) ⇒ Object



135
136
137
138
139
140
# File 'lib/build/build_node.rb', line 135

def rm(path)
	return unless wet?
	
	Console::Event::Spawn.for('rm', '-rf', path).emit(self)
	FileUtils.rm_rf(path)
end

#run!(*arguments, **options) ⇒ Object



117
118
119
# File 'lib/build/build_node.rb', line 117

def run!(*arguments, **options)
	self.spawn(shell_environment, *arguments, **options)
end

#shell_environmentObject



113
114
115
# File 'lib/build/build_node.rb', line 113

def shell_environment
	@shell_environment ||= environment.flatten.export
end

#spawn(*arguments, **options) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/build/build_node.rb', line 102

def spawn(*arguments, **options)
	if wet?
		@logger&.info(self) {Console::Event::Spawn.for(*arguments, **options)}
		status = @group.spawn(*arguments, **options)
		
		if status != 0
			raise CommandFailure.new(self, arguments, status)
		end
	end
end

#touch(path) ⇒ Object



121
122
123
124
125
126
# File 'lib/build/build_node.rb', line 121

def touch(path)
	return unless wet?
	
	Console::Event::Spawn.for('touch', path).emit(self)
	FileUtils.touch(path)
end

#wet?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/build/build_node.rb', line 98

def wet?
	@node.dirty?
end

#write(path, data, mode = "w") ⇒ Object



158
159
160
161
162
163
164
165
# File 'lib/build/build_node.rb', line 158

def write(path, data, mode = "w")
	return unless wet?
	
	Console::Event::Spawn.for('write', path).emit(self, size: data.size)
	File.open(path, mode) do |file|
		file.write(data)
	end
end