In Files

  • rake-13.0.1/lib/rake/packagetask.rb

Rake::PackageTask

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

Attributes

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_tar_xz[RW]

True if a xz'd tar file (tar.xz) 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').

without_parent_dir[RW]

True if parent directory should be omited (default is false)

zip_command[RW]

Zip command for zipped archives. The default is 'zip'.

Public Class Methods

new(name=nil, version=nil) click to toggle source

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.

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 89
def initialize(name=nil, version=nil)
  init(name, version)
  yield self if block_given?
  define unless name.nil?
end
            

Public Instance Methods

define() click to toggle source

Create the tasks defined by this task library.

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 112
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"],
    [need_tar_xz, tar_xz_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(working_dir) { sh @tar_command, "#{flag}cvf", file, target_dir }
        mv "#{package_dir_path}/#{target_dir}", package_dir if without_parent_dir
      end
    end
  end

  if need_zip
    task package: ["#{package_dir}/#{zip_file}"]
    file "#{package_dir}/#{zip_file}" =>
      [package_dir_path] + package_files do
      chdir(working_dir) { sh @zip_command, "-r", zip_file, target_dir }
      mv "#{package_dir_path}/#{zip_file}", package_dir if without_parent_dir
    end
  end

  directory package_dir_path => @package_files do
    @package_files.each do |fn|
      f = File.join(package_dir_path, fn)
      fdir = File.dirname(f)
      mkdir_p(fdir) unless File.exist?(fdir)
      if File.directory?(fn)
        mkdir_p(f)
      else
        rm_f f
        safe_ln(fn, f)
      end
    end
  end
  self
end
            
init(name, version) click to toggle source

Initialization that bypasses the “yield self” and “define” step.

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 96
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_tar_xz = false
  @need_zip = false
  @tar_command = "tar"
  @zip_command = "zip"
  @without_parent_dir = false
end
            
package_dir_path() click to toggle source

The directory this package will be built in

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 178
def package_dir_path
  "#{package_dir}/#{package_name}"
end
            
package_name() click to toggle source

The name of this package

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 172
def package_name
  @version ? "#{@name}-#{@version}" : @name
end
            
tar_bz2_file() click to toggle source

The package name with .tar.bz2 added

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 196
def tar_bz2_file
  "#{package_name}.tar.bz2"
end
            
tar_gz_file() click to toggle source

The package name with .tar.gz added

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 190
def tar_gz_file
  "#{package_name}.tar.gz"
end
            
tar_xz_file() click to toggle source

The package name with .tar.xz added

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 202
def tar_xz_file
  "#{package_name}.tar.xz"
end
            
target_dir() click to toggle source

target directory relative to working_dir

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 217
def target_dir
  without_parent_dir ? "." : package_name
end
            
tgz_file() click to toggle source

The package name with .tgz added

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 184
def tgz_file
  "#{package_name}.tgz"
end
            
working_dir() click to toggle source
 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 212
def working_dir
  without_parent_dir ? package_dir_path : package_dir
end
            
zip_file() click to toggle source

The package name with .zip added

 
               # File rake-13.0.1/lib/rake/packagetask.rb, line 208
def zip_file
  "#{package_name}.zip"
end