Class: Build::Task
- Inherits:
-
Graph::Task
- Object
- Graph::Task
- Build::Task
- Defined in:
- lib/build/controller.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 Method Summary collapse
- #cp(source_path, destination_path) ⇒ Object
-
#fs ⇒ Object
Legacy FileUtils access, replaced with direct function calls.
-
#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 (also: #run!)
- #touch(path) ⇒ Object
- #update ⇒ Object
- #wet? ⇒ Boolean
Constructor Details
#initialize(walker, node, group, logger: nil) ⇒ Task
Returns a new instance of Task.
100 101 102 103 104 105 106 |
# File 'lib/build/controller.rb', line 100 def initialize(walker, node, group, logger: nil) super(walker, node) @group = group @logger = logger || Logger.new($stderr) end |
Instance Method Details
#cp(source_path, destination_path) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/build/controller.rb', line 132 def cp(source_path, destination_path) return unless wet? @logger.info('shell'){ ['cp', source_path, destination_path]} FileUtils.copy(source_path, destination_path) end |
#fs ⇒ Object
Legacy FileUtils access, replaced with direct function calls.
164 165 166 |
# File 'lib/build/controller.rb', line 164 def fs self end |
#install(source_path, destination_path) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/build/controller.rb', line 156 def install(source_path, destination_path) return unless wet? @logger.info('shell'){ ['install', source_path, destination_path]} FileUtils.install(source_path, destination_path) end |
#invoke_rule(rule, arguments, &block) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/build/controller.rb', line 172 def invoke_rule(rule, arguments, &block) arguments = rule.normalize(arguments, self) @logger.debug('invoke') {"-> #{rule}: #{arguments.inspect}"} node = RuleNode.new(rule, arguments, &block) task = invoke(node) @logger.debug('invoke') {"<- #{rule}: #{rule.result(arguments)}"} return rule.result(arguments) end |
#mkpath(path) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/build/controller.rb', line 146 def mkpath(path) return unless wet? unless File.exist?(path) @logger.info('shell'){ ['mkpath', path] } FileUtils.mkpath(path) end end |
#rm(path) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/build/controller.rb', line 139 def rm(path) return unless wet? @logger.info('shell'){ ['rm', path] } FileUtils.rm(path) end |
#run(*arguments) ⇒ Object Also known as: run!
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/build/controller.rb', line 112 def run(*arguments) if wet? @logger.info('shell') {arguments} status = @group.spawn(*arguments) if status != 0 raise CommandFailure.new(self, arguments, status) end end end |
#touch(path) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/build/controller.rb', line 125 def touch(path) return unless wet? @logger.info('shell'){ ['touch', path] } FileUtils.touch(path) end |
#update ⇒ Object
168 169 170 |
# File 'lib/build/controller.rb', line 168 def update @node.apply!(self) end |
#wet? ⇒ Boolean
108 109 110 |
# File 'lib/build/controller.rb', line 108 def wet? @node.dirty? end |