Class: Build::Task
- Inherits:
-
Graph::Task
- Object
- Graph::Task
- Build::Task
- Defined in:
- lib/build/task.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
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #cp(source_path, destination_path) ⇒ Object
-
#initialize(walker, node, group, logger: nil) ⇒ Task
constructor
A new instance of Task.
- #install(source_path, destination_path) ⇒ Object
- #invoke_rule(rule, arguments, &block) ⇒ Object
- #mkpath(path) ⇒ Object
- #rm(path) ⇒ Object
- #run!(*arguments) ⇒ Object
- #shell_environment ⇒ Object
- #spawn(*arguments) ⇒ Object
- #to_s ⇒ Object
- #touch(path) ⇒ Object
- #update ⇒ Object
- #wet? ⇒ Boolean
- #write(path, data, mode = "w") ⇒ Object
Constructor Details
#initialize(walker, node, group, logger: nil) ⇒ Task
Returns a new instance of Task.
51 52 53 54 55 56 |
# File 'lib/build/task.rb', line 51 def initialize(walker, node, group, logger: nil) super(walker, node) @group = group @logger = logger end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
62 63 64 |
# File 'lib/build/task.rb', line 62 def group @group end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
63 64 65 |
# File 'lib/build/task.rb', line 63 def logger @logger end |
Instance Method Details
#cp(source_path, destination_path) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/build/task.rb', line 95 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
118 119 120 121 122 123 |
# File 'lib/build/task.rb', line 118 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
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/build/task.rb', line 138 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
109 110 111 112 113 114 115 116 |
# File 'lib/build/task.rb', line 109 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
102 103 104 105 106 107 |
# File 'lib/build/task.rb', line 102 def rm(path) return unless wet? @logger&.info(self) {Console::Shell.for('rm -rf', path)} FileUtils.rm_rf(path) end |
#run!(*arguments) ⇒ Object
84 85 86 |
# File 'lib/build/task.rb', line 84 def run!(*arguments) self.spawn(shell_environment, *arguments) end |
#shell_environment ⇒ Object
80 81 82 |
# File 'lib/build/task.rb', line 80 def shell_environment @shell_environment ||= environment.flatten.export end |
#spawn(*arguments) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/build/task.rb', line 69 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 |
#to_s ⇒ Object
58 59 60 |
# File 'lib/build/task.rb', line 58 def to_s "\#<#{Task} #{node.name}>" end |
#touch(path) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/build/task.rb', line 88 def touch(path) return unless wet? @logger&.info(self) {Console::Shell.for('touch', path)} FileUtils.touch(path) end |
#update ⇒ Object
134 135 136 |
# File 'lib/build/task.rb', line 134 def update @node.apply!(self) end |
#wet? ⇒ Boolean
65 66 67 |
# File 'lib/build/task.rb', line 65 def wet? @node.dirty? end |
#write(path, data, mode = "w") ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/build/task.rb', line 125 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 |