Class: Rscons::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/rscons/task.rb

Overview

A task is a named collection of actions and/or dependencies.

Defined Under Namespace

Classes: Param

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, &block) ⇒ Task

Construct a task.

Parameters:

  • name (String)

    Task name.

  • options (Hash)

    Options.

Options Hash (options):

  • :autoconf (Boolean)

    Whether to automatically configure before running this task (default true).



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/rscons/task.rb', line 123

def initialize(name, options, &block)
  @autoconf = true
  @dependencies = []
  @description = nil
  @name = name
  @params = {}
  @param_values = {}
  @actions = []
  Task.register(self)
  modify(options, &block)
end

Instance Attribute Details

#actionsArray<Proc> (readonly)

Returns Task action blocks.

Returns:

  • (Array<Proc>)

    Task action blocks.



92
93
94
# File 'lib/rscons/task.rb', line 92

def actions
  @actions
end

#autoconfBoolean (readonly)

Returns Whether to automatically configure before running this task.

Returns:

  • (Boolean)

    Whether to automatically configure before running this task.



96
97
98
# File 'lib/rscons/task.rb', line 96

def autoconf
  @autoconf
end

#descriptionString? (readonly)

Returns Task description, if given.

Returns:

  • (String, nil)

    Task description, if given.



100
101
102
# File 'lib/rscons/task.rb', line 100

def description
  @description
end

#nameString (readonly)

Returns Task name.

Returns:

  • (String)

    Task name.



104
105
106
# File 'lib/rscons/task.rb', line 104

def name
  @name
end

#param_valuesHash<String => String> (readonly)

Returns Task parameter values.

Returns:

  • (Hash<String => String>)

    Task parameter values.



112
113
114
# File 'lib/rscons/task.rb', line 112

def param_values
  @param_values
end

#paramsHash<String => Param> (readonly)

Returns Task params.

Returns:

  • (Hash<String => Param>)

    Task params.



108
109
110
# File 'lib/rscons/task.rb', line 108

def params
  @params
end

Class Method Details

.[](name = nil) ⇒ Hash, ...

Access a task by name.

Parameters:

  • name (String, nil) (defaults to: nil)

    Task name, or nil to return a Hash of all tasks.

Returns:

  • (Hash, Task, nil)

    Hash of all tasks if name is nil, otherwise Task with the given name, if found.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rscons/task.rb', line 16

def [](name = nil)
  if name
    if task = tasks[name]
      task
    else
      raise RsconsError.new("Task '#{name}' not found")
    end
  else
    tasks
  end
end

.register(task) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Register a newly created task.

Parameters:

  • task (Task)

    Task to register.



36
37
38
# File 'lib/rscons/task.rb', line 36

def register(task)
  tasks[task.name] = task
end

.tasksHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get all registered tasks.

Returns:

  • (Hash)

    All registered tasks.



46
47
48
# File 'lib/rscons/task.rb', line 46

def tasks
  @tasks ||= {}
end

Instance Method Details

#[](param_name) ⇒ String

Get a parameter’s value.

Parameters:

  • param_name (String)

    Parameter name.

Returns:

  • (String)

    Parameter value.



142
143
144
145
146
147
148
# File 'lib/rscons/task.rb', line 142

def [](param_name)
  param = @params[param_name]
  unless param
    raise RsconsError.new("Could not find parameter '#{param_name}'")
  end
  @param_values[param_name]
end

#check_executevoid

This method returns an undefined value.

Check if the task has been executed, and if not execute it.



175
176
177
178
179
# File 'lib/rscons/task.rb', line 175

def check_execute
  unless executed?
    execute
  end
end

#executevoid

This method returns an undefined value.

Execute a task’s actions.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rscons/task.rb', line 153

def execute
  @executed = true
  if @autoconf
    Rscons.application.check_configure
    Rscons.application.check_process_environments
  end
  @dependencies.each do |dependency|
    Task[dependency].check_execute
  end
  if @name == "configure"
    Rscons.application.silent_configure = false
    Rscons.application.configure
  else
    @actions.each do |action|
      action[self, param_values]
    end
  end
end

#executed?Boolean

Check if the task has been executed.

Returns:

  • (Boolean)

    Whether the task has been executed.



185
186
187
# File 'lib/rscons/task.rb', line 185

def executed?
  @executed
end

#modify(options, &block) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Modify a task.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/rscons/task.rb', line 194

def modify(options, &block)
  if options.include?(:autoconf)
    @autoconf = options[:autoconf]
  end
  if options.include?(:desc)
    @description = options[:desc]
  end
  if options.include?(:depends)
    @dependencies += Array(options[:depends])
  end
  if options.include?(:params)
    Array(options[:params]).each do |param|
      @params[param.name] = param
      set_param_value(param.name, param.value)
    end
  end
  if block
    if env = Environment.running_environment
      @actions << proc do
        block[]
        env.process
      end
    else
      @actions << block
    end
  end
end

#set_param_value(param_name, param_value) ⇒ void

This method returns an undefined value.

Set parameter value.

Parameters:

  • param_name (String)

    Parameter name.

  • param_value (String, Boolean)

    Parameter value.



230
231
232
233
234
235
# File 'lib/rscons/task.rb', line 230

def set_param_value(param_name, param_value)
  if param = @params[param_name]
    param.value = param_value
  end
  @param_values[param_name] = param_value
end