class Rake::PackageTask
end
p.package_files.include(“lib/*/.rb”)
p.need_tar = true
Rake::PackageTask.new(“rake”, “1.2.3”) do |p|
Example:
Create a zip package archive (if need_zip is true).
[“package_dir/name-version.zip”]
Create a bzip2’d tar package (if need_tar_bz2 is true).
[“package_dir/name-version.tar.bz2”]
Create a gzipped tar package (if need_tar_gz is true).
[“package_dir/name-version.tar.gz”]
Create a gzipped tar package (if need_tar is true).
[“package_dir/name-version.tgz”]
of date.
Rebuild the package files from scratch, even if they are not out
[:repackage]
added to the main clobber target.
Delete all the package files. This target is automatically
[:clobber_package]
Create all the requested package files.
[:package]
The PackageTask will create the following targets:
distributable files (e.g zip archive or tar files).
Create a packaging task that will package the project into
def define
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 %{#{@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 %{#{@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
def init(name, version)
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
def initialize(name=nil, version=nil)
def initialize(name=nil, version=nil) init(name, version) yield self if block_given? define unless name.nil? end
def package_dir_path
def package_dir_path "#{package_dir}/#{package_name}" end
def package_name
def package_name @version ? "#{@name}-#{@version}" : @name end
def tar_bz2_file
def tar_bz2_file "#{package_name}.tar.bz2" end
def tar_gz_file
def tar_gz_file "#{package_name}.tar.gz" end
def tgz_file
def tgz_file "#{package_name}.tgz" end
def zip_file
def zip_file "#{package_name}.zip" end