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
deprecated
Deprecated.
Please use #self instead.
-
#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
- #write(path, data, mode = "w") ⇒ Object
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
Deprecated.
Please use #self instead.
127 128 129 |
# File 'lib/build/task.rb', line 127 def fs self end |
#install(source_path, destination_path) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/build/task.rb', line 110 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
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/build/task.rb', line 135 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 |
# 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
131 132 133 |
# File 'lib/build/task.rb', line 131 def update @node.apply!(self) end |
#wet? ⇒ Boolean
57 58 59 |
# File 'lib/build/task.rb', line 57 def wet? @node.dirty? end |
#write(path, data, mode = "w") ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/build/task.rb', line 117 def write(path, data, mode = "w") return unless wet? @logger.info(:shell) {["write", path, "#{data.size}bytes"]} File.open(path, mode) do |file| file.write(data) end end |