3
# A raw platform for creating packages.
9
# The PackageTask will create the following targets:
11
# [<b>:clobber_package</b>]
12
# Delete all the package files. This target is automatically
13
# added to the main clobber target.
16
# Rebuild the package files from scratch, even if they are not out
19
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tgz"</b>]
20
# Create a gzipped tar package (if <em>need_tar</em> is true).
22
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.gz"</b>]
23
# Create a gzipped tar package (if <em>need_tar_gz</em> is true).
25
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.bz2"</b>]
26
# Create a bzip2'd tar package (if <em>need_tar_bz2</em> is true).
28
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.zip"</b>]
29
# Create a zip package archive (if <em>need_zip</em> is true).
33
# Rake::PackageTask.new("rake", "1.2.3") do |p|
35
# p.package_files.include("lib/**/*.rb")
38
class Rake::RedLabPackageTask < Rake::TaskLib
39
# The different directory types we can manage.
43
:sitelibdir => :rubylibs
46
# Name of the package (from the GEM Spec).
49
# Version of the package (e.g. '1.3.2').
50
attr_accessor :version
52
# Directory used to store the package files (default is 'pkg').
53
attr_accessor :package_dir
55
# The directory to which to publish packages and html and such.
56
attr_accessor :publishdir
58
# The package-specific publishing directory
59
attr_accessor :pkgpublishdir
61
# The Product name. Defaults to a capitalized version of the
63
attr_accessor :product
65
# The copyright message.
66
attr_accessor :copyright
71
# The license file. Defaults to COPYING.
72
attr_accessor :license
74
# The readme file. Defaults to README.
78
attr_accessor :description
81
attr_accessor :summary
83
# The directory in which to put the binaries. Defaults to the system
90
# The directory in which to put the system binaries. Defaults to the
92
attr_accessor :sbindir
94
# The system binaries.
98
attr_accessor :rubylibs
100
# The directory in which to put Ruby libraries. Defaults to the
102
attr_accessor :sitelibdir
104
# The URL for the package.
107
# The source for the package.
108
attr_accessor :source
110
# Our operating system.
113
# Add a required package.
114
def add_dependency(name, version = nil)
115
@requires[name] = version
118
# Create the tasks defined by this task library.
120
fail "Version required (or :noversion)" if @version.nil?
121
@version = nil if :noversion == @version
124
file pkgdest => self.package_dir
126
directory self.package_dir
133
# Return the list of files associated with a dirname.
135
if @dirtypes.include?(dirname)
136
return self.send(@dirtypes[dirname])
138
raise "Could not find directory type %s" % dirname
142
# Create a Package Task with the given name and version.
143
def initialize(name=nil, version=nil)
144
# Theoretically, one could eventually add directory types here.
145
@dirtypes = DIRTYPES.dup
152
@product = name.capitalize
154
@bindir = Config::CONFIG["bindir"]
155
@sbindir = Config::CONFIG["sbindir"]
156
@sitelibdir = Config::CONFIG["sitelibdir"]
161
yield self if block_given?
163
define unless name.nil?
165
# Make sure they've provided everything necessary.
166
%w{copyright vendor description}.each do |attr|
167
unless self.send(attr)
168
raise "You must provide the attribute %s" % attr
173
# Make tasks for copying/linking all of the necessary files.
179
# Iterate across all of the file locations...
180
@dirtypes.each do |dirname, filemethod|
181
tname = ("copy" + dirname.to_s).intern
183
dir = self.send(dirname)
187
# This is where we're putting the files.
188
targetdir = self.targetdir(dirname)
190
# Make sure our target directories exist
192
file targetdir => basedir
194
# Get the file list and remove the leading directory.
195
files = self.files(dirname) or next
198
files.each do |sourcefile|
199
# The file without the basedir. This is necessary because
200
# files are created with the path from ".", but they often
201
# have 'lib' changed to 'site_ruby' or something similar.
202
destfile = File.join(targetdir, sourcefile.sub(/^\w+\//, ''))
205
# Make sure the base directory is listed as a prereq
206
sourcedir = File.dirname(sourcefile)
208
unless sourcedir == "."
209
destdir = File.dirname(destfile)
214
# Now make the task associated with creating the object in
216
if FileTest.directory?(sourcefile)
219
file(destfile => sourcefile) do
220
if FileTest.exists?(destfile)
221
if File.stat(sourcefile) > File.stat(destfile)
223
safe_ln(sourcefile, destfile)
226
safe_ln(sourcefile, destfile)
230
# If we've set the destdir, then list it as a prereq.
232
file destfile => destdir
237
# And create a task for each one
240
# And then mark our task as a prereq
244
task :copycode => [self.package_dir, pkgdest]
246
task :copycode => tasks do
247
puts "Finished copying"
251
# Where we're copying a given type of file.
252
def targetdir(dirname)
253
File.join(pkgdest(), self.send(dirname)).sub("//", "/")
259
@version ? "#{@name}-#{@version}" : @name
263
"#{package_dir}/#{package_name}"