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

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.



100
101
102
# File 'lib/build/build_node.rb', line 100

def output_environment
  @output_environment
end

Instance Method Details

#cp(source_path, destination_path) ⇒ Object

Copy a file from source to destination.



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

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

Install a file to a destination path.



175
176
177
178
179
180
# File 'lib/build/build_node.rb', line 175

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

Invoke a rule with the given arguments, normalising them and invoking the rule node.



199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/build/build_node.rb', line 199

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

#mkpath(path) ⇒ Object

Create a directory and all intermediate directories.



163
164
165
166
167
168
169
170
# File 'lib/build/build_node.rb', line 163

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

Remove a file or directory recursively.



154
155
156
157
158
159
# File 'lib/build/build_node.rb', line 154

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

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

Run a shell command within the task’s environment.



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

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

#shell_environmentObject



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

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

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

Spawn a process if the node is dirty, raising CommandFailure on non-zero exit.



110
111
112
113
114
115
116
117
118
119
# File 'lib/build/build_node.rb', line 110

def spawn(*arguments, **options)
	if wet?
		Console.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

Touch a file, creating or updating its modification time.



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

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

#wet?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/build/build_node.rb', line 103

def wet?
	@node.dirty?
end

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

Write data to a file.



186
187
188
189
190
191
192
193
# File 'lib/build/build_node.rb', line 186

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