123456789_123456789_123456789_123456789_123456789_

Class: Rake::PackageTask

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, TaskLib
Instance Chain:
Inherits: Rake::TaskLib
Defined in: lib/rake/packagetask.rb

Overview

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

Constant Summary

::FileUtils - Included

LN_SUPPORTED, RUBY

FileUtilsExt - Included

DEFAULT

Class Method Summary

Instance Attribute Summary

  • #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.

  • #version rw

    Version of the package (e.g.

  • #without_parent_dir rw

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

  • #zip_command rw

    Zip command for zipped archives.

Instance Method Summary

DSL - Included

#desc

Describes the next rake task.

#directory

Declare a set of files tasks to create the given directories on demand.

#file

Declare a file task.

#file_create

Declare a file creation task.

#import

Import the partial Rakefiles fn.

#multitask

Declare a task that performs its prerequisites in parallel.

#namespace

Create a new rake namespace and use it for evaluating the given block.

#rule

Declare a rule for auto-tasks.

#task

Declare a basic task.

FileUtilsExt - Included

#nowrite

Get/set the nowrite flag controlling output from the ::FileUtils utilities.

#rake_check_options

Check that the options do not contain options not listed in optdecl.

#rake_output_message

Send the message to the default rake output (which is $stderr).

#verbose

Get/set the verbose flag controlling output from the ::FileUtils utilities.

#when_writing

Use this function to prevent potentially destructive ruby code from running when the :nowrite flag is set.

::FileUtils - Included

#ruby

Run a Ruby interpreter with the given arguments.

#safe_ln

Attempt to do a normal file link, but fall back to a copy if the link fails.

#sh

Run the system command cmd.

#split_all

Split a file path into individual directory names.

#create_shell_runner, #set_verbose_option, #sh_show_command

Cloneable - Included

#initialize_copy

The hook that is invoked by 'clone' and 'dup' methods.

Constructor Details

.new(name = nil, version = nil) {|_self| ... } ⇒ PackageTask

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.

Yields:

  • (_self)

Yield Parameters:

  • _self (PackageTask)

    the object that the method was called on

[ GitHub ]

  
# File '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

Instance Attribute Details

#name (rw)

Name of the package (from the GEM Spec).

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 47

attr_accessor :name

#need_tar (rw)

True if a gzipped tar file (tgz) should be produced (default is false).

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 57

attr_accessor :need_tar

#need_tar_bz2 (rw)

True if a bzip2'd tar file (tar.bz2) should be produced (default is false).

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 65

attr_accessor :need_tar_bz2

#need_tar_gz (rw)

True if a gzipped tar file (tar.gz) should be produced (default is false).

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 61

attr_accessor :need_tar_gz

#need_tar_xz (rw)

True if a xz'd tar file (tar.xz) should be produced (default is false)

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 68

attr_accessor :need_tar_xz

#need_zip (rw)

True if a zip file should be produced (default is false)

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 71

attr_accessor :need_zip

#package_dir (rw)

Directory used to store the package files (default is 'pkg').

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 53

attr_accessor :package_dir

#package_files (rw)

List of files to be included in the package.

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 74

attr_accessor :package_files

#tar_command (rw)

Tar command for gzipped or bzip2ed archives. The default is 'tar'.

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 77

attr_accessor :tar_command

#version (rw)

Version of the package (e.g. '1.3.2').

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 50

attr_accessor :version

#without_parent_dir (rw)

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

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 83

attr_accessor :without_parent_dir

#zip_command (rw)

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

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 80

attr_accessor :zip_command

Instance Method Details

#define

Create the tasks defined by this task library.

[ GitHub ]

  
# File '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)

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

[ GitHub ]

  
# File '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

The directory this package will be built in

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 178

def package_dir_path
  "#{package_dir}/#{package_name}"
end

#package_name

The name of this package

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 172

def package_name
  @version ? "#{@name}-#{@version}" : @name
end

#tar_bz2_file

The package name with .tar.bz2 added

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 196

def tar_bz2_file
  "#{package_name}.tar.bz2"
end

#tar_gz_file

The package name with .tar.gz added

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 190

def tar_gz_file
  "#{package_name}.tar.gz"
end

#tar_xz_file

The package name with .tar.xz added

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 202

def tar_xz_file
  "#{package_name}.tar.xz"
end

#target_dir

target directory relative to working_dir

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 217

def target_dir
  without_parent_dir ? "." : package_name
end

#tgz_file

The package name with .tgz added

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 184

def tgz_file
  "#{package_name}.tgz"
end

#working_dir

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 212

def working_dir
  without_parent_dir ? package_dir_path : package_dir
end

#zip_file

The package name with .zip added

[ GitHub ]

  
# File 'lib/rake/packagetask.rb', line 208

def zip_file
  "#{package_name}.zip"
end