Class | Rake::PackageTask |
In: |
lib/rake/packagetask.rb
|
Parent: | TaskLib |
Create a packaging task that will package the project into distributable files (e.g zip archive or tar files).
The PackageTask will create the following targets:
Example:
Rake::PackageTask.new("rake", "1.2.3") do |p| p.need_tar = true p.package_files.include("lib/**/*.rb") end
name | [RW] | Name of the package (from the GEM Spec). |
need_tar | [RW] | True if a gzipped tar file (tgz) should be produced (default is false). |
need_tar_bz2 | [RW] | True if a bzip2‘d tar file (tar.bz2) should be produced (default is false). |
need_tar_gz | [RW] | True if a gzipped tar file (tar.gz) should be produced (default is false). |
need_zip | [RW] | True if a zip file should be produced (default is false) |
package_dir | [RW] | Directory used to store the package files (default is ‘pkg’). |
package_files | [RW] | List of files to be included in the package. |
tar_command | [RW] | Tar command for gzipped or bzip2ed archives. The default is ‘tar’. |
version | [RW] | Version of the package (e.g. ‘1.3.2’). |
zip_command | [RW] | Zip command for zipped archives. The default is ‘zip’. |
Create the tasks defined by this task library.
# File lib/rake/packagetask.rb, line 99 99: def define 100: fail "Version required (or :noversion)" if @version.nil? 101: @version = nil if :noversion == @version 102: 103: desc "Build all the packages" 104: task :package 105: 106: desc "Force a rebuild of the package files" 107: task :repackage => [:clobber_package, :package] 108: 109: desc "Remove package products" 110: task :clobber_package do 111: rm_r package_dir rescue nil 112: end 113: 114: task :clobber => [:clobber_package] 115: 116: [ 117: [need_tar, tgz_file, "z"], 118: [need_tar_gz, tar_gz_file, "z"], 119: [need_tar_bz2, tar_bz2_file, "j"] 120: ].each do |(need, file, flag)| 121: if need 122: task :package => ["#{package_dir}/#{file}"] 123: file "#{package_dir}/#{file}" => [package_dir_path] + package_files do 124: chdir(package_dir) do 125: sh %{env} 126: sh %{#{@tar_command} #{flag}cvf #{file} #{package_name}} 127: end 128: end 129: end 130: end 131: 132: if need_zip 133: task :package => ["#{package_dir}/#{zip_file}"] 134: file "#{package_dir}/#{zip_file}" => [package_dir_path] + package_files do 135: chdir(package_dir) do 136: sh %{#{@zip_command} -r #{zip_file} #{package_name}} 137: end 138: end 139: end 140: 141: directory package_dir 142: 143: file package_dir_path => @package_files do 144: mkdir_p package_dir rescue nil 145: @package_files.each do |fn| 146: f = File.join(package_dir_path, fn) 147: fdir = File.dirname(f) 148: mkdir_p(fdir) if !File.exist?(fdir) 149: if File.directory?(fn) 150: mkdir_p(f) 151: else 152: rm_f f 153: safe_ln(fn, f) 154: end 155: end 156: end 157: self 158: end
Initialization that bypasses the "yield self" and "define" step.
# File lib/rake/packagetask.rb, line 85 85: def init(name, version) 86: @name = name 87: @version = version 88: @package_files = Rake::FileList.new 89: @package_dir = 'pkg' 90: @need_tar = false 91: @need_tar_gz = false 92: @need_tar_bz2 = false 93: @need_zip = false 94: @tar_command = 'tar' 95: @zip_command = 'zip' 96: end
# File lib/rake/packagetask.rb, line 164 164: def package_dir_path 165: "#{package_dir}/#{package_name}" 166: end
# File lib/rake/packagetask.rb, line 160 160: def package_name 161: @version ? "#{@name}-#{@version}" : @name 162: end
# File lib/rake/packagetask.rb, line 176 176: def tar_bz2_file 177: "#{package_name}.tar.bz2" 178: end
# File lib/rake/packagetask.rb, line 172 172: def tar_gz_file 173: "#{package_name}.tar.gz" 174: end