~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/rake/gempackagetask.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
# Define a package task library to aid in the definition of GEM
 
4
# packages.
 
5
 
 
6
require 'rubygems'
 
7
require 'rake'
 
8
require 'rake/packagetask'
 
9
require 'rubygems/user_interaction'
 
10
require 'rubygems/builder'
 
11
 
 
12
begin
 
13
  Gem.manage_gems
 
14
rescue NoMethodError => ex
 
15
  # Using rubygems prior to 0.6.1
 
16
end
 
17
 
 
18
module Rake
 
19
 
 
20
  # Create a package based upon a Gem spec.  Gem packages, as well as
 
21
  # zip files and tar/gzipped packages can be produced by this task.
 
22
  #
 
23
  # In addition to the Rake targets generated by PackageTask, a
 
24
  # GemPackageTask will also generate the following tasks:
 
25
  #
 
26
  # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.gem"</b>]
 
27
  #   Create a Ruby GEM package with the given name and version.
 
28
  #
 
29
  # Example using a Ruby GEM spec:
 
30
  #
 
31
  #   require 'rubygems'
 
32
  #
 
33
  #   spec = Gem::Specification.new do |s|
 
34
  #     s.platform = Gem::Platform::RUBY
 
35
  #     s.summary = "Ruby based make-like utility."
 
36
  #     s.name = 'rake'
 
37
  #     s.version = PKG_VERSION
 
38
  #     s.requirements << 'none'
 
39
  #     s.require_path = 'lib'
 
40
  #     s.autorequire = 'rake'
 
41
  #     s.files = PKG_FILES
 
42
  #     s.description = <<EOF
 
43
  #   Rake is a Make-like program implemented in Ruby. Tasks
 
44
  #   and dependencies are specified in standard Ruby syntax. 
 
45
  #   EOF
 
46
  #   end
 
47
  #   
 
48
  #   Rake::GemPackageTask.new(spec) do |pkg|
 
49
  #     pkg.need_zip = true
 
50
  #     pkg.need_tar = true
 
51
  #   end
 
52
  #
 
53
  class GemPackageTask < PackageTask
 
54
    # Ruby GEM spec containing the metadata for this package.  The
 
55
    # name, version and package_files are automatically determined
 
56
    # from the GEM spec and don't need to be explicitly provided.
 
57
    attr_accessor :gem_spec
 
58
 
 
59
    # Create a GEM Package task library.  Automatically define the gem
 
60
    # if a block is given.  If no block is supplied, then +define+
 
61
    # needs to be called to define the task.
 
62
    def initialize(gem_spec)
 
63
      init(gem_spec)
 
64
      yield self if block_given?
 
65
      define if block_given?
 
66
    end
 
67
 
 
68
    # Initialization tasks without the "yield self" or define
 
69
    # operations.
 
70
    def init(gem)
 
71
      super(gem.name, gem.version)
 
72
      @gem_spec = gem
 
73
      @package_files += gem_spec.files if gem_spec.files
 
74
    end
 
75
 
 
76
    # Create the Rake tasks and actions specified by this
 
77
    # GemPackageTask.  (+define+ is automatically called if a block is
 
78
    # given to +new+).
 
79
    def define
 
80
      super
 
81
      task :package => [:gem]
 
82
      desc "Build the gem file #{gem_file}"
 
83
      task :gem => ["#{package_dir}/#{gem_file}"]
 
84
      file "#{package_dir}/#{gem_file}" => [package_dir] + @gem_spec.files do
 
85
        when_writing("Creating GEM") {
 
86
          Gem::Builder.new(gem_spec).build
 
87
          verbose(true) {
 
88
            mv gem_file, "#{package_dir}/#{gem_file}"
 
89
          }
 
90
        }
 
91
      end
 
92
    end
 
93
    
 
94
    def gem_file
 
95
      if @gem_spec.platform == Gem::Platform::RUBY
 
96
        "#{package_name}.gem"
 
97
      else
 
98
        "#{package_name}-#{@gem_spec.platform}.gem"
 
99
      end
 
100
    end
 
101
    
 
102
  end
 
103
end