Class: Build::Task

Inherits:
Graph::Task
  • Object
show all
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

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

#fsObject

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_environmentObject



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

#updateObject



175
176
177
# File 'lib/build/controller.rb', line 175

def update
  @node.apply!(self)
end

#wet?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/build/controller.rb', line 109

def wet?
  @node.dirty?
end