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?
	
	@logger&.info(self) {Console::Shell.for('cp', source_path, destination_path)}
	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?
	
	@logger&.info(self) {Console::Shell.for('install', source_path, destination_path)}
	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)
		@logger&.info(self) {Console::Shell.for('mkpath', path)}
		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?
	
	@logger&.info(self) {Console::Shell.for('rm -rf', path)}
	FileUtils.rm_rf(path)
end

#run!(*arguments) ⇒ Object



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

def run!(*arguments)
	self.spawn(shell_environment, *arguments)
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) ⇒ Object



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

def spawn(*arguments)
	if wet?
		@logger&.info(self) {Console::Event::Spawn.for(*arguments)}
		status = @group.spawn(*arguments)
		
		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?
	
	@logger&.info(self) {Console::Shell.for('touch', path)}
	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?
	
	@logger&.info(self) {Console::Shell.for("write", path, "#{data.size}bytes")}
	File.open(path, mode) do |file|
		file.write(data)
	end
end