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
- #shell_environment ⇒ Object
- #spawn(*arguments) ⇒ Object
- #touch(path) ⇒ Object
- #update ⇒ Object
- #wet? ⇒ Boolean
Constructor Details
#initialize(walker, node, group, logger: nil) ⇒ Task
Returns a new instance of Task.
101 102 103 104 105 106 107 |
# File 'lib/build/controller.rb', line 101 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
139 140 141 142 143 144 |
# File 'lib/build/controller.rb', line 139 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.
171 172 173 |
# File 'lib/build/controller.rb', line 171 def fs self end |
#install(source_path, destination_path) ⇒ Object
163 164 165 166 167 168 |
# File 'lib/build/controller.rb', line 163 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
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/build/controller.rb', line 179 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
153 154 155 156 157 158 159 160 161 |
# File 'lib/build/controller.rb', line 153 def mkpath(path) return unless wet? unless File.exist?(path) @logger.info('shell'){ ['mkpath', path] } FileUtils.mkpath(path) end end |
#rm(path) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/build/controller.rb', line 146 def rm(path) return unless wet? @logger.info('shell'){ ['rm -rf', path] } FileUtils.rm_rf(path) end |
#run!(*arguments) ⇒ Object
128 129 130 |
# File 'lib/build/controller.rb', line 128 def run!(*arguments) self.spawn(shell_environment, *arguments) end |
#shell_environment ⇒ Object
124 125 126 |
# File 'lib/build/controller.rb', line 124 def shell_environment @shell_environment ||= environment.flatten.export end |
#spawn(*arguments) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/build/controller.rb', line 113 def spawn(*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
132 133 134 135 136 137 |
# File 'lib/build/controller.rb', line 132 def touch(path) return unless wet? @logger.info('shell'){ ['touch', path] } FileUtils.touch(path) end |
#update ⇒ Object
175 176 177 |
# File 'lib/build/controller.rb', line 175 def update @node.apply!(self) end |
#wet? ⇒ Boolean
109 110 111 |
# File 'lib/build/controller.rb', line 109 def wet? @node.dirty? end |