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
Class Method Summary
-
.new(name = nil, version = nil) {|_self| ... } ⇒ PackageTask
constructor
Create a Package Task with the given name and version.
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. -
#zip_command
rw
Zip command for zipped archives.
Instance Method Summary
-
#define
Create the tasks defined by this task library.
-
#init(name, version)
Initialization that bypasses the “yield self” and “define” step.
-
#package_dir_path
The directory this package will be built in.
-
#package_name
The name of this package.
-
#tar_bz2_file
The package name with
.tar
.bz2 added. -
#tar_gz_file
The package name with
.tar
.gz added. -
#tar_xz_file
The package name with
.tar
.xz added. -
#tgz_file
The package name with
.tgz
added. -
#zip_file
The package name with
.zip
added.
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 |
#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 |
#rake_check_options | Check that the options do not contain options not listed in |
#rake_merge_option | Merge the given options with the default values. |
#rake_output_message | Send the message to the default rake output (which is $stderr). |
#verbose | Get/set the verbose flag controlling output from the |
#when_writing | Use this function to prevent potentially destructive ruby code from running when the |
::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 |
#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.
Instance Attribute Details
#name (rw)
Name of the package (from the GEM Spec).
# 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).
# 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).
# 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).
# 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)
# 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)
# File 'lib/rake/packagetask.rb', line 71
attr_accessor :need_zip
#package_dir (rw)
Directory used to store the package files (default is ‘pkg’).
# File 'lib/rake/packagetask.rb', line 53
attr_accessor :package_dir
#package_files (rw)
List of files to be included in the package.
# 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’.
# File 'lib/rake/packagetask.rb', line 77
attr_accessor :tar_command
#version (rw)
Version
of the package (e.g. ‘1.3.2’).
# File 'lib/rake/packagetask.rb', line 50
attr_accessor :version
#zip_command (rw)
Zip command for zipped archives. The default is ‘zip’.
# File 'lib/rake/packagetask.rb', line 80
attr_accessor :zip_command
Instance Method Details
#define
Create the tasks defined by this task library.
# File 'lib/rake/packagetask.rb', line 108
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(package_dir) { sh @tar_command, "#{flag}cvf", file, package_name } 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) { sh @zip_command, "-r", zip_file, package_name } 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.
# File 'lib/rake/packagetask.rb', line 93
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" end
#package_dir_path
The directory this package will be built in
# File 'lib/rake/packagetask.rb', line 172
def package_dir_path "#{package_dir}/#{package_name}" end
#package_name
The name of this package
# File 'lib/rake/packagetask.rb', line 166
def package_name @version ? "#{@name}-#{@version}" : @name end
#tar_bz2_file
The package name with .tar
.bz2 added
# File 'lib/rake/packagetask.rb', line 190
def tar_bz2_file "#{package_name}.tar.bz2" end
#tar_gz_file
The package name with .tar
.gz added
# File 'lib/rake/packagetask.rb', line 184
def tar_gz_file "#{package_name}.tar.gz" end
#tar_xz_file
The package name with .tar
.xz added
# File 'lib/rake/packagetask.rb', line 196
def tar_xz_file "#{package_name}.tar.xz" end
#tgz_file
The package name with .tgz
added
# File 'lib/rake/packagetask.rb', line 178
def tgz_file "#{package_name}.tgz" end
#zip_file
The package name with .zip
added
# File 'lib/rake/packagetask.rb', line 202
def zip_file "#{package_name}.zip" end