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
- D
- I
- N
- P
- T
- Z
[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] | tar_command | Tar command for gzipped or bzip2ed archives. The default is 'tar'. |
[RW] | version | Version of the package (e.g. '1.3.2'). |
[RW] | zip_command | Zip command for zipped archives. The default is 'zip'. |
Create a Package Task with the given name and
version. Use :noversion
as the version to build a package
without a version or to provide a fully-versioned package name.
Create the tasks defined by this task library.
# File lib/rake/packagetask.rb, line 100 def define fail "Version required (or :noversion)" if @version.nil? @version = nil if :noversion == @version desc "Build all the packages" task :package desc "Force a rebuild of the package files" task :repackage => [:clobber_package, :package] desc "Remove package products" task :clobber_package do rm_r package_dir rescue nil end task :clobber => [:clobber_package] [ [need_tar, tgz_file, "z"], [need_tar_gz, tar_gz_file, "z"], [need_tar_bz2, tar_bz2_file, "j"] ].each do |(need, file, flag)| if need task :package => ["#{package_dir}/#{file}"] file "#{package_dir}/#{file}" => [package_dir_path] + package_files do chdir(package_dir) do sh %Q{#{@tar_command} #{flag}cvf #{file} #{package_name}} end end end end if need_zip task :package => ["#{package_dir}/#{zip_file}"] file "#{package_dir}/#{zip_file}" => [package_dir_path] + package_files do chdir(package_dir) do sh %Q{#{@zip_command} -r #{zip_file} #{package_name}} end end end directory package_dir file package_dir_path => @package_files do mkdir_p package_dir rescue nil @package_files.each do |fn| f = File.join(package_dir_path, fn) 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 end self end
Initialization that bypasses the “yield self” and “define” step.
# File lib/rake/packagetask.rb, line 86 def init(name, version) @name = name @version = version @package_files = Rake::FileList.new @package_dir = 'pkg' @need_tar = false @need_tar_gz = false @need_tar_bz2 = false @need_zip = false @tar_command = 'tar' @zip_command = 'zip' end