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:
- :package
- Create all the requested package files.
- :clobber_package
- Delete all the package files. This target is automatically added to the main clobber target.
- :repackage
- Rebuild the package files from scratch, even if they are not out of date.
- "package_dir/name-version.tgz"
- Create a gzipped tar package (if need_tar is true).
- "package_dir/name-version.tar.gz"
- Create a gzipped tar package (if need_tar_gz is true).
- "package_dir/name-version.tar.bz2"
- Create a bzip2’d tar package (if need_tar_bz2 is true).
- "package_dir/name-version.zip"
- Create a zip package archive (if need_zip is true).
Example:
Rake::PackageTask.new("rake", "1.2.3") do |p| p.need_tar = true p.package_files.include("lib/**/*.rb") end
Methods
Attributes
[RW] | name | Name of the package (from the GEM Spec). |
[RW] | need_tar | True if a gzipped tar file (tgz) should be produced (default is false). |
[RW] | need_tar_bz2 | True if a bzip2’d tar file (tar.bz2) should be produced (default is false). |
[RW] | need_tar_gz | True if a gzipped tar file (tar.gz) should be produced (default is false). |
[RW] | need_zip | True if a zip file should be produced (default is false) |
[RW] | package_dir | Directory used to store the package files (default is ‘pkg’). |
[RW] | package_files | List of files to be included in the package. |
[RW] | version | Version of the package (e.g. ‘1.3.2’). |
Public Class methods
Create a Package Task with the given name and version.
[ show source ]
# File lib/rake/packagetask.rb, line 72 72: def initialize(name=nil, version=nil) 73: init(name, version) 74: yield self if block_given? 75: define unless name.nil? 76: end
Public Instance methods
Create the tasks defined by this task library.
[ show source ]
# File lib/rake/packagetask.rb, line 91 91: def define 92: fail "Version required (or :noversion)" if @version.nil? 93: @version = nil if :noversion == @version 94: 95: desc "Build all the packages" 96: task :package 97: 98: desc "Force a rebuild of the package files" 99: task :repackage => [:clobber_package, :package] 100: 101: desc "Remove package products" 102: task :clobber_package do 103: rm_r package_dir rescue nil 104: end 105: 106: task :clobber => [:clobber_package] 107: 108: [ 109: [need_tar, tgz_file, "z"], 110: [need_tar_gz, tar_gz_file, "z"], 111: [need_tar_bz2, tar_bz2_file, "j"] 112: ].each do |(need, file, flag)| 113: if need 114: task :package => ["#{package_dir}/#{file}"] 115: file "#{package_dir}/#{file}" => [package_dir_path] + package_files do 116: chdir(package_dir) do 117: sh %{tar #{flag}cvf #{file} #{package_name}} 118: end 119: end 120: end 121: end 122: 123: if need_zip 124: task :package => ["#{package_dir}/#{zip_file}"] 125: file "#{package_dir}/#{zip_file}" => [package_dir_path] + package_files do 126: chdir(package_dir) do 127: sh %{zip -r #{zip_file} #{package_name}} 128: end 129: end 130: end 131: 132: directory package_dir 133: 134: file package_dir_path => @package_files do 135: mkdir_p package_dir rescue nil 136: @package_files.each do |fn| 137: f = File.join(package_dir_path, fn) 138: fdir = File.dirname(f) 139: mkdir_p(fdir) if !File.exist?(fdir) 140: if File.directory?(fn) 141: mkdir_p(f) 142: else 143: rm_f f 144: safe_ln(fn, f) 145: end 146: end 147: end 148: self 149: end
Initialization that bypasses the "yield self" and "define" step.
[ show source ]
# File lib/rake/packagetask.rb, line 79 79: def init(name, version) 80: @name = name 81: @version = version 82: @package_files = Rake::FileList.new 83: @package_dir = 'pkg' 84: @need_tar = false 85: @need_tar_gz = false 86: @need_tar_bz2 = false 87: @need_zip = false 88: end
[ show source ]
# File lib/rake/packagetask.rb, line 155 155: def package_dir_path 156: "#{package_dir}/#{package_name}" 157: end
[ show source ]
# File lib/rake/packagetask.rb, line 151 151: def package_name 152: @version ? "#{@name}-#{@version}" : @name 153: end
[ show source ]
# File lib/rake/packagetask.rb, line 167 167: def tar_bz2_file 168: "#{package_name}.tar.bz2" 169: end
[ show source ]
# File lib/rake/packagetask.rb, line 163 163: def tar_gz_file 164: "#{package_name}.tar.gz" 165: end
[ show source ]
# File lib/rake/packagetask.rb, line 159 159: def tgz_file 160: "#{package_name}.tgz" 161: end
[ show source ]
# File lib/rake/packagetask.rb, line 171 171: def zip_file 172: "#{package_name}.zip" 173: end