class BuildTask
This task class serves as the base class for the environment specific task classes genearted when adding targets.
Nested
Definitions
def wet?
Signature
-
returns
Boolean Whether the node is dirty and commands should actually be executed.
Implementation
def wet?
@node.dirty?
end
def spawn(*arguments, **options)
Spawn a process if the node is dirty, raising class Build::BuildTask::CommandFailure on non-zero exit.
Signature
-
parameter
argumentsArray The command and its arguments.
-
parameter
optionsHash Options forwarded to the process group.
Implementation
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
def shell_environment
Signature
-
returns
Hash A flattened, exported shell environment hash.
Implementation
def shell_environment
@shell_environment ||= environment.flatten.export
end
def run!(*arguments, **options)
Run a shell command within the task's environment.
Signature
-
parameter
argumentsArray The command and its arguments.
-
parameter
optionsHash Options forwarded to the process group.
Implementation
def run!(*arguments, **options)
self.spawn(shell_environment, *arguments, **options)
end
def touch(path)
Touch a file, creating or updating its modification time.
Signature
-
parameter
pathString The file path to touch.
Implementation
def touch(path)
return unless wet?
Console::Event::Spawn.for("touch", path).emit(self)
FileUtils.touch(path)
end
def cp(source_path, destination_path)
Copy a file from source to destination.
Signature
-
parameter
source_pathString The source file path.
-
parameter
destination_pathString The destination file path.
Implementation
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
def rm(path)
Remove a file or directory recursively.
Signature
-
parameter
pathString The path to remove.
Implementation
def rm(path)
return unless wet?
Console::Event::Spawn.for("rm", "-rf", path).emit(self)
FileUtils.rm_rf(path)
end
def mkpath(path)
Create a directory and all intermediate directories.
Signature
-
parameter
pathString The directory path to create.
Implementation
def mkpath(path)
return unless wet?
unless File.exist?(path)
Console::Event::Spawn.for("mkdir", "-p", path).emit(self)
FileUtils.mkpath(path)
end
end
def install(source_path, destination_path)
Install a file to a destination path.
Signature
-
parameter
source_pathString The source file path.
-
parameter
destination_pathString The destination file path.
Implementation
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
def write(path, data, mode = "w")
Write data to a file.
Signature
-
parameter
pathString The destination file path.
-
parameter
dataString The data to write.
-
parameter
modeString The file open mode.
Implementation
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
def invoke_rule(rule, arguments, &block)
Invoke a rule with the given arguments, normalising them and invoking the rule node.
Signature
-
parameter
ruleBuild::Rule The rule to invoke.
-
parameter
argumentsHash The arguments to pass to the rule.
-
returns
Object The result of the rule, typically a file path.
Implementation
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