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 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.
49 50 51 52 53 54 55 |
# File 'lib/build/task.rb', line 49 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
87 88 89 90 91 92 |
# File 'lib/build/task.rb', line 87 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.
119 120 121 |
# File 'lib/build/task.rb', line 119 def fs self end |
#install(source_path, destination_path) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/build/task.rb', line 111 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
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/build/task.rb', line 127 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
101 102 103 104 105 106 107 108 109 |
# File 'lib/build/task.rb', line 101 def mkpath(path) return unless wet? unless File.exist?(path) @logger.info('shell'){ ['mkpath', path] } FileUtils.mkpath(path) end end |
#rm(path) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/build/task.rb', line 94 def rm(path) return unless wet? @logger.info('shell'){ ['rm -rf', path] } FileUtils.rm_rf(path) end |
#run!(*arguments) ⇒ Object
76 77 78 |
# File 'lib/build/task.rb', line 76 def run!(*arguments) self.spawn(shell_environment, *arguments) end |
#shell_environment ⇒ Object
72 73 74 |
# File 'lib/build/task.rb', line 72 def shell_environment @shell_environment ||= environment.flatten.export end |
#spawn(*arguments) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/build/task.rb', line 61 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
80 81 82 83 84 85 |
# File 'lib/build/task.rb', line 80 def touch(path) return unless wet? @logger.info('shell'){ ['touch', path] } FileUtils.touch(path) end |
#update ⇒ Object
123 124 125 |
# File 'lib/build/task.rb', line 123 def update @node.apply!(self) end |
#wet? ⇒ Boolean
57 58 59 |
# File 'lib/build/task.rb', line 57 def wet? @node.dirty? end |