Module: Pkg::Util::RakeUtils

Defined in:
lib/packaging/util/rake_utils.rb

Overview

Utility methods for working with rake tasks. These utilities will not work if the packaging repo was loaded as a library unless rake has been required explicitly.

Class Method Summary collapse

Class Method Details

.add_dependency(depender, dependency) ⇒ Object

Add a dependency to a rake task. “depender” must be an instance of

Rake::Task, but dependency can be either a Rake::Task instance, or a String
referring to the name of a Rake::Task instance.


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/packaging/util/rake_utils.rb', line 36

def add_dependency(depender, dependency)
  if using_rake?
    if !task_defined?(depender)
      fail "Could not locate a Rake task named '#{depender.to_s}' to add a dependency of '#{dependency.to_s}' to"
    elsif !task_defined?(dependency)
      fail "Could not locate a Rake task named '#{dependency.to_s}' to add as a dependency of '#{depender.to_s}'"
    else
      depender_task = Rake::Task[depender]
      depender_task.enhance([dependency])
    end
  end
end

.evaluate_pre_tasksObject

Evaluate any pre-tasks known by the configuration of this invocation.

Again, this is quite pointless if the user has not invoked the packaging
repo via rake, so we're just not going to do anything.


53
54
55
56
57
58
59
60
61
62
# File 'lib/packaging/util/rake_utils.rb', line 53

def evaluate_pre_tasks
  if using_rake? and Pkg::Config.pre_tasks
    unless Pkg::Config.pre_tasks.is_a?(Hash)
      fail "The 'pre_tasks' key must be a Hash of depender => dependency pairs"
    end
    Pkg::Config.pre_tasks.each do |depender, dependency|
      add_dependency(depender, dependency)
    end
  end
end

.get_task(task_name) ⇒ Object

Return the Rake::Task object associated with a task name



21
22
23
24
25
# File 'lib/packaging/util/rake_utils.rb', line 21

def get_task(task_name)
  if using_rake? and task_defined?(task_name)
    Rake::Task[task_name]
  end
end

.invoke_task(task, *args) ⇒ Object



27
28
29
30
# File 'lib/packaging/util/rake_utils.rb', line 27

def invoke_task(task, *args)
  Rake::Task[task].reenable
  Rake::Task[task].invoke(*args)
end

.load_packaging_tasks(packaging_root = Pkg::Config.packaging_root) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/packaging/util/rake_utils.rb', line 64

def load_packaging_tasks(packaging_root = Pkg::Config.packaging_root)
  packaging_task_dir = File.join(packaging_root, 'tasks')
  tasks = [
    '00_utils.rake',
    '30_metrics.rake',
    'apple.rake',
    'archive.rake',
    'build.rake',
    'clean.rake',
    'deb.rake',
    'deb_repos.rake',
    'doc.rake',
    'education.rake',
    'fetch.rake',
    'gem.rake',
    'jenkins.rake',
    'jenkins_dynamic.rake',
    'load_extras.rake',
    'mock.rake',
    'nightly_repos.rake',
    'pe_deb.rake',
    'pe_rpm.rake',
    'pe_ship.rake',
    'pe_sign.rake',
    'pe_tar.rake',
    'retrieve.rake',
    'rpm.rake',
    'rpm_repos.rake',
    'ship.rake',
    'sign.rake',
    'tag.rake',
    'tar.rake',
    'update.rake',
    'vendor_gems.rake',
    'version.rake',
    'z_data_dump.rake',
    'config.rake',
    'vanagon.rake',
    'deprecated.rake'
  ]

  tasks.each do |task|
    load File.join(packaging_task_dir, task)
  end

  Pkg::Util::RakeUtils.evaluate_pre_tasks
end

.task_defined?(task_name) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/packaging/util/rake_utils.rb', line 13

def task_defined?(task_name)
  if using_rake?
    Rake::Task.task_defined?(task_name)
  end
end

.using_rake?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/packaging/util/rake_utils.rb', line 9

def using_rake?
  defined?(Rake::Task)
end