Class: Gem::PackageTask
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Rake::PackageTask
|
|
|
Instance Chain:
self,
Rake::PackageTask
|
|
| Inherits: |
Rake::PackageTask
|
| Defined in: | lib/rubygems/package_task.rb |
Overview
Create a package based upon a Specification. ::Gem packages, as well as
zip files and tar/gzipped packages can be produced by this task.
In addition to the Rake targets generated by Rake::PackageTask, a
PackageTask will also generate the following tasks:
["package_dir/name-version.gem"] Create a RubyGems package with the given name and version.
Example using a Specification:
require 'rubygems'
require 'rubygems/package_task'
spec = Gem::Specification.new do |s|
s.summary = "Ruby based make-like utility."
s.name = 'rake'
s.version = PKG_VERSION
s.requirements << 'none'
s.files = PKG_FILES
s.description = <<-EOF
Rake is a Make-like program implemented in Ruby. Tasks
and dependencies are specified in standard Ruby syntax.
EOF
end
Gem::PackageTask.new(spec) do |pkg|
pkg.need_zip = true
pkg.need_tar = true
end
Class Method Summary
-
.new(gem_spec) {|_self| ... } ⇒ PackageTask
constructor
Create a
::GemPackage task library.
Instance Attribute Summary
-
#content_addressable
rw
Indicates whether this package should be built as a content-addressable gem.
-
#gem_spec
rw
Ruby
Specificationcontaining the metadata for this package.
Instance Method Summary
-
#define
Create the Rake tasks and actions specified by this
PackageTask. -
#init(gem)
Initialization tasks without the "yield self" or define operations.
-
#package_name
The name of this package.
- #content_addressable_ruby_abi private
- #discard_stale_stamp_file private
- #recorded_gem_path private
- #stamp_file private
Constructor Details
.new(gem_spec) {|_self| ... } ⇒ PackageTask
Instance Attribute Details
#content_addressable (rw)
Indicates whether this package should be built as a content-addressable gem.
# File 'lib/rubygems/package_task.rb', line 70
attr_accessor :content_addressable
#gem_spec (rw)
Ruby Specification containing the metadata for this package. The
name, version and package_files are automatically determined from the
gemspec and don't need to be explicitly provided.
# File 'lib/rubygems/package_task.rb', line 66
attr_accessor :gem_spec
Instance Method Details
#content_addressable_ruby_abi (private)
[ GitHub ]# File 'lib/rubygems/package_task.rb', line 169
def content_addressable_ruby_abi return unless content_addressable Gem::ContentAddress.ruby_abi_for(gem_spec.required_ruby_version) end
#define
Create the Rake tasks and actions specified by this PackageTask.
(define is automatically called if a block is given to .new).
# File 'lib/rubygems/package_task.rb', line 98
def define Gem::ContentAddress.eligible!(gem_spec) if content_addressable super gem_file = File.basename gem_spec.cache_file gem_path = File.join package_dir, gem_file gem_dir = package_dir_path if content_addressable build_target = stamp_file gem_description = "content-addressable gem #{gem_spec.name}-#{gem_spec.version} " \ "(Platform: #{gem_spec.platform}, Ruby ABI: #{content_addressable_ruby_abi})" discard_stale_stamp_file else build_target = gem_path gem_description = "gem file #{gem_file}" end task package: [:gem] directory package_dir directory gem_dir desc "Build the #{gem_description}" task gem: [build_target] trace = Rake.application..trace Gem.configuration.verbose = trace file build_target => [package_dir, gem_dir] + @gem_spec.files do previous_gem = recorded_gem_path if content_addressable built_gem_path = nil chdir(gem_dir) do when_writing "Creating #{gem_description}" do built_gem_file = Gem::Package.build gem_spec, content_addressable: content_addressable verbose trace do mv built_gem_file, ".." end if content_addressable built_gem_path = File.join(package_dir, built_gem_file) File.write File.join("..", File.basename(stamp_file)), built_gem_path end end end if previous_gem && built_gem_path && previous_gem != built_gem_path verbose trace do rm_f previous_gem end end end end
#discard_stale_stamp_file (private)
[ GitHub ]# File 'lib/rubygems/package_task.rb', line 186
def discard_stale_stamp_file return unless File.file?(stamp_file) path = recorded_gem_path File.delete(stamp_file) unless path && File.file?(path) end
#init(gem)
Initialization tasks without the "yield self" or define operations.
#package_name
The name of this package. Content-addressable builds append the Ruby ABI
so per-ABI builds of the same full_name do not share a staging
directory.
# File 'lib/rubygems/package_task.rb', line 161
def package_name name = super ruby_abi = content_addressable_ruby_abi ruby_abi ? "#{name}-#{ruby_abi}" : name end
#recorded_gem_path (private)
[ GitHub ]# File 'lib/rubygems/package_task.rb', line 179
def recorded_gem_path return unless File.file?(stamp_file) path = File.read(stamp_file).strip path unless path.empty? end
#stamp_file (private)
[ GitHub ]# File 'lib/rubygems/package_task.rb', line 175
def stamp_file File.join package_dir, "#{package_name}.gem-built" end