class Rake::DmgTask

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

Constants

VERSION

Attributes

admin_rights[RW]

We have administration rights (default: false; this setting is checked only by the dmg_options method).

dmg_command[RW]

System utility used to build the DMG file (default: hdiutil).

dmg_options[W]

DMG build options (default tailored to hdiutil; see dmg_options implementation). Assigning any value to this attribute temporarily switch off the default ones.

extra_source_files[RW]

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.

name[RW]

Name of the disk image (required).

package_dir[RW]

Directory used to store the disk image (default: ‘pkg’).

source_files[RW]

List of files to be included in the DMG file (default: empty).

strip[RW]

Path prefix to strip from each file name in the final DMG file (default: nil).

version[RW]

Version of the DMG (required; use :noversion for unversioned disk images).

Public Class Methods

new(name=nil, version=nil) { |self| ... } click to toggle source

Create a Package Task with the given name and version.

   # File lib/rake/dmg.rb
74 def initialize(name=nil, version=nil)
75   @name = name
76   @version = version
77   @package_dir = 'pkg'
78   @source_files = Rake::FileList.new
79   @extra_source_files = {}
80   @dmg_command = 'hdiutil'
81   @admin_rights = false
82   @dmg_options = nil
83   @strip = nil
84   yield self if block_given?
85   define_tasks unless name.nil?
86 end

Public Instance Methods

define_tasks() click to toggle source

Create the tasks defined by this task library.

    # File lib/rake/dmg.rb
 89 def define_tasks
 90   fail "Version required (or :noversion)" if @version.nil?
 91   @version = nil if :noversion == @version
 92 
 93   desc "Build the disk image file"
 94   task :dmg => "#{package_dir}/#{dmg_file}"
 95 
 96   file "#{package_dir}/#{dmg_file}" => dmg_dir_path do
 97     chdir package_dir do
 98       sh "#{dmg_command} create #{dmg_options}"
 99     end
100   end
101 
102   directory package_dir
103 
104   file dmg_dir_path => source_files + extra_source_files.keys do
105     prefix_to_strip = /^#{@strip}/ if @strip
106     mkdir_p package_dir rescue nil
107     source_files.each do |fn|
108       fn_stripped = @strip == nil ? fn : fn.sub(prefix_to_strip, '')
109       f = File.join(dmg_dir_path, fn_stripped)
110       fdir = File.dirname(f)
111       mkdir_p(fdir) if !File.exist?(fdir)
112       if File.directory?(fn)
113         mkdir_p(f)
114       else
115         rm_f f
116         safe_ln(fn, f)
117       end
118     end
119     extra_source_files.each do |k, v|
120       f = File.join(dmg_dir_path, v)
121       mkdir_p(File.dirname(f)) rescue nil
122       rm_f f
123       safe_ln k, f
124     end
125   end
126 
127   desc "Remove the disk image files"
128   task :clobber_dmg do
129     rm_r package_dir rescue nil
130   end
131 
132   task :clobber => :clobber_dmg
133 
134   desc "Force a rebuild of the disk image file"
135   task :rebuild_dmg => [:clobber_dmg, :dmg]
136 
137   self
138 end
dmg_dir_path() click to toggle source

Temporary directory used to gather the DMG’s content before actual building.

    # File lib/rake/dmg.rb
159 def dmg_dir_path
160   "#{package_dir}/#{dmg_name}"
161 end
dmg_file() click to toggle source

DMG file name.

    # File lib/rake/dmg.rb
146 def dmg_file
147   dmg_name + '.dmg'
148 end
dmg_name() click to toggle source

DMG volume name.

    # File lib/rake/dmg.rb
141 def dmg_name
142   @version ? "#{@name}-#{@version}" : @name
143 end
dmg_options() click to toggle source

Build options for dmg_command, tailored to hdiutil.

    # File lib/rake/dmg.rb
151 def dmg_options
152   @dmg_options || "-srcdir #{dmg_name} -ov -volname #{name} " +
153     "#{admin_rights ? '-uid 99 -gid 99' : '' } " + 
154     "#{dmg_file}"
155 end