Class: Rake::DmgTask
- Inherits:
-
Object
- Object
- Rake::DmgTask
- Includes:
- DSL
- Defined in:
- lib/rake/dmg.rb,
lib/rake/dmg/version.rb
Overview
Create a packaging task that will package the project into a distributable disk image.
The DmgTask will create the following targets:
- :dmg
-
Create the requested DMG file.
- :clobber_dmg
-
Delete the disk image. Automatically added to the main clobber target.
- :rebuild_dmg
-
Rebuild the disk image from scratch.
Other tasks are created as prerequisites of the main ones and can safely be ignored.
Most of the attributes/characteristics of the DmgTask object must be set upon creation via the optional block; altering them afterward has no effect.
Example:
Rake::DmgTask.new("pimpernel", :noversion) do |p|
p.source_files.include("lib/**/*.rb")
p.extra_source_files = {'resources/ds_store' => '/.DS_Store',
'resources/background.png' => '/.background/background.png'}
end
Constant Summary collapse
- VERSION =
'0.0.3'
Instance Attribute Summary collapse
-
#admin_rights ⇒ Object
We have administration rights (default: false; this setting is checked only by the
dmg_options
method). -
#dmg_command ⇒ Object
System utility used to build the DMG file (default: hdiutil).
-
#dmg_options ⇒ Object
Build options for
dmg_command
, tailored to hdiutil. -
#extra_source_files ⇒ Object
List of extra files to be included in the DMG file (default: empty).
-
#name ⇒ Object
Name of the disk image (required).
-
#package_dir ⇒ Object
Directory used to store the disk image (default: ‘pkg’).
-
#source_files ⇒ Object
List of files to be included in the DMG file (default: empty).
-
#strip ⇒ Object
Path prefix to strip from each file name in the final DMG file (default: nil).
-
#version ⇒ Object
Version of the DMG (required; use :noversion for unversioned disk images).
Instance Method Summary collapse
-
#define_tasks ⇒ Object
Create the tasks defined by this task library.
-
#dmg_dir_path ⇒ Object
Temporary directory used to gather the DMG’s content before actual building.
-
#dmg_file ⇒ Object
DMG file name.
-
#dmg_name ⇒ Object
DMG volume name.
-
#initialize(name = nil, version = nil) {|_self| ... } ⇒ DmgTask
constructor
Create a Package Task with the given name and version.
Constructor Details
#initialize(name = nil, version = nil) {|_self| ... } ⇒ DmgTask
Create a Package Task with the given name and version.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rake/dmg.rb', line 74 def initialize(name=nil, version=nil) @name = name @version = version @package_dir = 'pkg' @source_files = Rake::FileList.new @extra_source_files = {} @dmg_command = 'hdiutil' @admin_rights = false @dmg_options = nil @strip = nil yield self if block_given? define_tasks unless name.nil? end |
Instance Attribute Details
#admin_rights ⇒ Object
We have administration rights (default: false; this setting is checked only by the dmg_options
method).
62 63 64 |
# File 'lib/rake/dmg.rb', line 62 def admin_rights @admin_rights end |
#dmg_command ⇒ Object
System utility used to build the DMG file (default: hdiutil).
58 59 60 |
# File 'lib/rake/dmg.rb', line 58 def dmg_command @dmg_command end |
#dmg_options ⇒ Object
Build options for dmg_command
, tailored to hdiutil.
151 152 153 154 155 |
# File 'lib/rake/dmg.rb', line 151 def @dmg_options || "-srcdir #{dmg_name} -ov -volname #{name} " + "#{admin_rights ? '-uid 99 -gid 99' : '' } " + "#{dmg_file}" end |
#extra_source_files ⇒ Object
List of extra files to be included in the DMG file (default: empty). Each item is a couple key/value: key is the source, value is the target inside the DMG.
55 56 57 |
# File 'lib/rake/dmg.rb', line 55 def extra_source_files @extra_source_files end |
#name ⇒ Object
Name of the disk image (required).
41 42 43 |
# File 'lib/rake/dmg.rb', line 41 def name @name end |
#package_dir ⇒ Object
Directory used to store the disk image (default: ‘pkg’).
47 48 49 |
# File 'lib/rake/dmg.rb', line 47 def package_dir @package_dir end |
#source_files ⇒ Object
List of files to be included in the DMG file (default: empty).
50 51 52 |
# File 'lib/rake/dmg.rb', line 50 def source_files @source_files end |
#strip ⇒ Object
Path prefix to strip from each file name in the final DMG file (default: nil).
71 72 73 |
# File 'lib/rake/dmg.rb', line 71 def strip @strip end |
#version ⇒ Object
Version of the DMG (required; use :noversion for unversioned disk images).
44 45 46 |
# File 'lib/rake/dmg.rb', line 44 def version @version end |
Instance Method Details
#define_tasks ⇒ Object
Create the tasks defined by this task library.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rake/dmg.rb', line 89 def define_tasks fail "Version required (or :noversion)" if @version.nil? @version = nil if :noversion == @version desc "Build the disk image file" task :dmg => "#{package_dir}/#{dmg_file}" file "#{package_dir}/#{dmg_file}" => dmg_dir_path do chdir package_dir do sh "#{dmg_command} create #{}" end end directory package_dir file dmg_dir_path => source_files + extra_source_files.keys do prefix_to_strip = /^#{@strip}/ if @strip mkdir_p package_dir rescue nil source_files.each do |fn| fn_stripped = @strip == nil ? fn : fn.sub(prefix_to_strip, '') f = File.join(dmg_dir_path, fn_stripped) fdir = File.dirname(f) mkdir_p(fdir) if !File.exist?(fdir) if File.directory?(fn) mkdir_p(f) else rm_f f safe_ln(fn, f) end end extra_source_files.each do |k, v| f = File.join(dmg_dir_path, v) mkdir_p(File.dirname(f)) rescue nil rm_f f safe_ln k, f end end desc "Remove the disk image files" task :clobber_dmg do rm_r package_dir rescue nil end task :clobber => :clobber_dmg desc "Force a rebuild of the disk image file" task :rebuild_dmg => [:clobber_dmg, :dmg] self end |
#dmg_dir_path ⇒ Object
Temporary directory used to gather the DMG’s content before actual building.
159 160 161 |
# File 'lib/rake/dmg.rb', line 159 def dmg_dir_path "#{package_dir}/#{dmg_name}" end |
#dmg_file ⇒ Object
DMG file name.
146 147 148 |
# File 'lib/rake/dmg.rb', line 146 def dmg_file dmg_name + '.dmg' end |
#dmg_name ⇒ Object
DMG volume name.
141 142 143 |
# File 'lib/rake/dmg.rb', line 141 def dmg_name @version ? "#{@name}-#{@version}" : @name end |