~gandelman-a/ubuntu/precise/facter/lp877621

« back to all changes in this revision

Viewing changes to tasks/rake/redlabpackage.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-11-06 00:52:19 UTC
  • mfrom: (1.1.6 upstream) (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091106005219-6ccua0q7b885z2ad
Tags: 1.5.6-2ubuntu1
* Merge from debian testing, remaining changes:
  - Use bind9-host9 only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env ruby
2
 
 
3
 
# A raw platform for creating packages.
4
 
 
5
 
require 'rbconfig'
6
 
require 'rake'
7
 
require 'rake/tasklib'
8
 
 
9
 
# The PackageTask will create the following targets:
10
 
#
11
 
# [<b>:clobber_package</b>]
12
 
#   Delete all the package files.  This target is automatically
13
 
#   added to the main clobber target.
14
 
#
15
 
# [<b>:repackage</b>]
16
 
#   Rebuild the package files from scratch, even if they are not out
17
 
#   of date.
18
 
#
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).  
21
 
#
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).  
24
 
#
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).  
27
 
#
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).
30
 
#
31
 
# Example:
32
 
#
33
 
#   Rake::PackageTask.new("rake", "1.2.3") do |p|
34
 
#     p.need_tar = true
35
 
#     p.package_files.include("lib/**/*.rb")
36
 
#   end
37
 
#
38
 
class Rake::RedLabPackageTask < Rake::TaskLib
39
 
    # The different directory types we can manage.
40
 
    DIRTYPES = {
41
 
        :bindir => :bins,
42
 
        :sbindir => :sbins,
43
 
        :sitelibdir => :rubylibs
44
 
    }
45
 
 
46
 
    # Name of the package (from the GEM Spec).
47
 
    attr_accessor :name
48
 
 
49
 
    # Version of the package (e.g. '1.3.2').
50
 
    attr_accessor :version
51
 
 
52
 
    # Directory used to store the package files (default is 'pkg').
53
 
    attr_accessor :package_dir
54
 
 
55
 
    # The directory to which to publish packages and html and such.
56
 
    attr_accessor :publishdir
57
 
 
58
 
    # The package-specific publishing directory
59
 
    attr_accessor :pkgpublishdir
60
 
 
61
 
    # The Product name.  Defaults to a capitalized version of the
62
 
    # package name
63
 
    attr_accessor :product
64
 
 
65
 
    # The copyright message.
66
 
    attr_accessor :copyright
67
 
 
68
 
    # The vendor.
69
 
    attr_accessor :vendor
70
 
 
71
 
    # The license file.  Defaults to COPYING.
72
 
    attr_accessor :license
73
 
 
74
 
    # The readme file.  Defaults to README.
75
 
    attr_accessor :readme
76
 
 
77
 
    # The description.
78
 
    attr_accessor :description
79
 
 
80
 
    # The summary.
81
 
    attr_accessor :summary
82
 
 
83
 
    # The directory in which to put the binaries.  Defaults to the system
84
 
    # default.
85
 
    attr_accessor :bindir
86
 
 
87
 
    # The executables.
88
 
    attr_accessor :bins
89
 
 
90
 
    # The directory in which to put the system binaries.  Defaults to the
91
 
    # system default.
92
 
    attr_accessor :sbindir
93
 
 
94
 
    # The system binaries.
95
 
    attr_accessor :sbins
96
 
 
97
 
    # The libraries.
98
 
    attr_accessor :rubylibs
99
 
 
100
 
    # The directory in which to put Ruby libraries.  Defaults to the
101
 
    # system site_dir.
102
 
    attr_accessor :sitelibdir
103
 
 
104
 
    # The URL for the package.
105
 
    attr_accessor :url
106
 
    
107
 
    # The source for the package.
108
 
    attr_accessor :source
109
 
 
110
 
    # Our operating system.
111
 
    attr_reader :os
112
 
 
113
 
    # Add a required package.
114
 
    def add_dependency(name, version = nil)
115
 
        @requires[name] = version
116
 
    end
117
 
 
118
 
    # Create the tasks defined by this task library.
119
 
    def define
120
 
        fail "Version required (or :noversion)" if @version.nil?
121
 
        @version = nil if :noversion == @version
122
 
 
123
 
        directory pkgdest
124
 
        file pkgdest => self.package_dir
125
 
 
126
 
        directory self.package_dir
127
 
 
128
 
        self.mkcopytasks
129
 
 
130
 
        self
131
 
    end
132
 
 
133
 
    # Return the list of files associated with a dirname.
134
 
    def files(dirname)
135
 
        if @dirtypes.include?(dirname)
136
 
            return self.send(@dirtypes[dirname])
137
 
        else
138
 
            raise "Could not find directory type %s" % dirname
139
 
        end
140
 
    end
141
 
 
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
146
 
 
147
 
        @requires = {}
148
 
 
149
 
        @name           = name
150
 
        @version        = version
151
 
        @package_dir    = 'pkg'
152
 
        @product        = name.capitalize
153
 
 
154
 
        @bindir         = Config::CONFIG["bindir"]
155
 
        @sbindir        = Config::CONFIG["sbindir"]
156
 
        @sitelibdir     = Config::CONFIG["sitelibdir"]
157
 
 
158
 
        @license        = "COPYING"
159
 
        @readme         = "README"
160
 
 
161
 
        yield self if block_given?
162
 
 
163
 
        define unless name.nil?
164
 
 
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
169
 
            end
170
 
        end
171
 
    end
172
 
 
173
 
    # Make tasks for copying/linking all of the necessary files.
174
 
    def mkcopytasks
175
 
        basedir = pkgdest()
176
 
 
177
 
        tasks = []
178
 
 
179
 
        # Iterate across all of the file locations...
180
 
        @dirtypes.each do |dirname, filemethod|
181
 
            tname = ("copy" + dirname.to_s).intern
182
 
 
183
 
            dir = self.send(dirname)
184
 
 
185
 
            reqs = []
186
 
 
187
 
            # This is where we're putting the files.
188
 
            targetdir = self.targetdir(dirname)
189
 
 
190
 
            # Make sure our target directories exist
191
 
            directory targetdir
192
 
            file targetdir => basedir
193
 
 
194
 
            # Get the file list and remove the leading directory.
195
 
            files = self.files(dirname) or next
196
 
 
197
 
            reqs = []
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+\//, ''))
203
 
                reqs << destfile
204
 
 
205
 
                # Make sure the base directory is listed as a prereq
206
 
                sourcedir = File.dirname(sourcefile)
207
 
                destdir = nil
208
 
                unless sourcedir == "."
209
 
                    destdir = File.dirname(destfile)
210
 
                    reqs << destdir
211
 
                    directory(destdir)
212
 
                end
213
 
 
214
 
                # Now make the task associated with creating the object in
215
 
                # question.
216
 
                if FileTest.directory?(sourcefile)
217
 
                    directory(destfile)
218
 
                else
219
 
                    file(destfile => sourcefile) do
220
 
                        if FileTest.exists?(destfile)
221
 
                            if File.stat(sourcefile) > File.stat(destfile)
222
 
                                rm_f destfile
223
 
                                safe_ln(sourcefile, destfile)
224
 
                            end
225
 
                        else
226
 
                            safe_ln(sourcefile, destfile)
227
 
                        end
228
 
                    end
229
 
                    
230
 
                    # If we've set the destdir, then list it as a prereq.
231
 
                    if destdir
232
 
                        file destfile => destdir
233
 
                    end
234
 
                end
235
 
            end
236
 
 
237
 
            # And create a task for each one
238
 
            task tname => reqs
239
 
             
240
 
            # And then mark our task as a prereq
241
 
            tasks << tname
242
 
        end
243
 
 
244
 
        task :copycode => [self.package_dir, pkgdest]
245
 
 
246
 
        task :copycode => tasks do
247
 
            puts "Finished copying"
248
 
        end
249
 
    end
250
 
 
251
 
    # Where we're copying a given type of file.
252
 
    def targetdir(dirname)
253
 
        File.join(pkgdest(), self.send(dirname)).sub("//", "/")
254
 
    end
255
 
 
256
 
    private
257
 
 
258
 
    def package_name
259
 
        @version ? "#{@name}-#{@version}" : @name
260
 
    end
261
 
 
262
 
    def package_dir_path
263
 
        "#{package_dir}/#{package_name}"
264
 
    end
265
 
end