Cross package maker. DEB/RPM generation or conversion. Derived from jordansissel/fpm.

⌈⌋ ⎇ branch:  cross package maker


Check-in [bbaf8bab13]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:- Add general way for source plugins to add flags specific to that plugin. For now, only 'gem' uses this. - Add flag --gem-bin-path to install a gem's executables to a specific place. Some folks like /usr/bin, so, package puppet with bins there: * fpm -s gem -t deb --gem-bin-path /usr/bin puppet The original implementation for this bin-path flag was by lassizci. https://github.com/jordansissel/fpm/pull/27
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bbaf8bab1301d835bb90ed6be1d9286e3ab9aeee
User & Date: jls@semicomplete.com 2011-05-17 07:17:22
Context
2011-05-17
07:20
version bump check-in: bc37cb148d user: jls@semicomplete.com tags: trunk
07:17
- Add general way for source plugins to add flags specific to that plugin. For now, only 'gem' uses this. - Add flag --gem-bin-path to install a gem's executables to a specific place. Some folks like /usr/bin, so, package puppet with bins there: * fpm -s gem -t deb --gem-bin-path /usr/bin puppet The original implementation for this bin-path flag was by lassizci. https://github.com/jordansissel/fpm/pull/27 check-in: bbaf8bab13 user: jls@semicomplete.com tags: trunk
02:49
version bump check-in: 68ecea9d2b user: jls@semicomplete.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bin/fpm.

1
2
3
4
5
6
7
8
9
10

11
12
13
14



15
16
17
18
19
20
21
#!/usr/bin/env ruby
#

require "rubygems"
require "optparse"
require "ostruct"
require "erb"

$: << "#{File.dirname(__FILE__)}/../lib"
require "fpm"


def main(args)
  settings = OpenStruct.new
  settings.exclude = []




  # Maintainer scripts - https://github.com/jordansissel/fpm/issues/18
  settings.scripts ||= {} 

  opts = OptionParser.new do |opts|
    # TODO(sissel): Maybe this should be '-o OUTPUT' ?
    opts.on("-p PACKAGEFILE", "--package PACKAGEFILE",










>




>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env ruby
#

require "rubygems"
require "optparse"
require "ostruct"
require "erb"

$: << "#{File.dirname(__FILE__)}/../lib"
require "fpm"
require "fpm/flags"

def main(args)
  settings = OpenStruct.new
  settings.exclude = []

  # Source-specific settings/flags go here.
  settings.source = {}

  # Maintainer scripts - https://github.com/jordansissel/fpm/issues/18
  settings.scripts ||= {} 

  opts = OptionParser.new do |opts|
    # TODO(sissel): Maybe this should be '-o OUTPUT' ?
    opts.on("-p PACKAGEFILE", "--package PACKAGEFILE",
121
122
123
124
125
126
127



128
129
130
131
132
133
134

    opts.on("--url URL",
            "Add a url for this package.") do |url|
      settings.url = url
    end # --url
  end # OptionParser




  opts.parse!(args)

  ok = true
  if settings.package_type.nil?
    $stderr.puts "Missing package target type (no -t flag?)"
    ok = false
  end







>
>
>







125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

    opts.on("--url URL",
            "Add a url for this package.") do |url|
      settings.url = url
    end # --url
  end # OptionParser

  # Add extra flags.
  FPM::Source::Gem.flags(FPM::Flags.new(opts, "gem", "gem source only"), settings)

  opts.parse!(args)

  ok = true
  if settings.package_type.nil?
    $stderr.puts "Missing package target type (no -t flag?)"
    ok = false
  end

Changes to lib/fpm/builder.rb.

37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
      :name => settings.package_name,
      :prefix => settings.prefix,
      :suffix => settings.suffix,
      :exclude => settings.exclude,
      :maintainer => settings.maintainer,
      :provides => [],
      :description => settings.description,
      :url => settings.url

    )

    @edit = !!settings.edit

    @paths = paths
    @package = package_class_for(settings.package_type).new(@source)
    # Append dependencies given from settings (-d flag for fpm)







|
>







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
      :name => settings.package_name,
      :prefix => settings.prefix,
      :suffix => settings.suffix,
      :exclude => settings.exclude,
      :maintainer => settings.maintainer,
      :provides => [],
      :description => settings.description,
      :url => settings.url,
      :settings => settings.source
    )

    @edit = !!settings.edit

    @paths = paths
    @package = package_class_for(settings.package_type).new(@source)
    # Append dependencies given from settings (-d flag for fpm)

Added lib/fpm/flags.rb.









































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
require "fpm/namespace"

class FPM::Flags
  def initialize(opts, flag_prefix, help_prefix)
    @opts = opts
    @flag_prefix = flag_prefix
    @help_prefix = help_prefix
  end # def initialize

  def on(*args, &block)
    fixed_args = args.collect do |arg|
      if arg =~ /^--/
        "--#{@flag_prefix}-#{arg.gsub(/^--/, "")}" 
      else
        "(#{@help_prefix}) #{arg}"
      end
    end
    @opts.on(*fixed_args, &block)
  end # def on
end # class FPM::Flags

Changes to lib/fpm/source/gem.rb.

1
2
3
4
5
6
7







8
9
10
11
12
13
14
require "fpm/namespace"
require "fpm/source"
require "rubygems/package"
require "rubygems"
require "fileutils"

class FPM::Source::Gem < FPM::Source







  def get_source(params)
    gem = @paths.first
    looks_like_name_re = /^[A-Za-z0-9_-]+$/
    if !File.exists?(gem) 
      if gem =~ looks_like_name_re
        download(gem, params[:version])
      else







>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require "fpm/namespace"
require "fpm/source"
require "rubygems/package"
require "rubygems"
require "fileutils"

class FPM::Source::Gem < FPM::Source
  def self.flags(opts, settings)
    opts.on("--bin-path DIRECTORY",
            "The directory to install gem executables") do |path|
      settings.source[:bin_path] = path
    end
  end # def flags

  def get_source(params)
    gem = @paths.first
    looks_like_name_re = /^[A-Za-z0-9_-]+$/
    if !File.exists?(gem) 
      if gem =~ looks_like_name_re
        download(gem, params[:version])
      else
98
99
100
101
102
103
104

105
106
107
108
109

110
111
112






113
114

115
116
117
118
119
120
121
122

  def make_tarball!(tar_path, builddir)
    tmpdir = "#{tar_path}.dir"
    gem = @paths.first
    if self[:prefix]
      installdir = "#{tmpdir}/#{self[:prefix]}"
      # TODO(sissel): Overwriting @paths is bad mojo and confusing...

      @paths = [ self[:prefix] ]
    else
      installdir = "#{tmpdir}/#{::Gem::dir}"
      @paths = [ ::Gem::dir ]
    end

    ::FileUtils.mkdir_p(installdir)
    args = ["gem", "install", "--quiet", "--no-ri", "--no-rdoc",
       "--install-dir", installdir, "--ignore-dependencies", gem]






    system(*args)
    

    tar(tar_path, ".#{@paths.first}", tmpdir)
    FileUtils.rm_r(tmpdir)

    # TODO(sissel): Make a helper method.
    system(*["gzip", "-f", tar_path])
  end

end # class FPM::Source::Gem







>


|


>


|
>
>
>
>
>
>


>
|







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

  def make_tarball!(tar_path, builddir)
    tmpdir = "#{tar_path}.dir"
    gem = @paths.first
    if self[:prefix]
      installdir = "#{tmpdir}/#{self[:prefix]}"
      # TODO(sissel): Overwriting @paths is bad mojo and confusing...
      # Maybe we shouldn't?
      @paths = [ self[:prefix] ]
    else
      installdir = File.join(tmpdir, ::Gem::dir)
      @paths = [ ::Gem::dir ]
    end

    ::FileUtils.mkdir_p(installdir)
    args = ["gem", "install", "--quiet", "--no-ri", "--no-rdoc",
       "--install-dir", installdir, "--ignore-dependencies"]
    if self[:settings][:bin_path]
      args += ["--bindir", File.join(tmpdir, self[:settings][:bin_path])]
      @paths << self[:settings][:bin_path]
    end

    args << gem
    system(*args)
    
    # make paths relative  (/foo becomes ./foo)
    tar(tar_path, @paths.collect {|p| ".#{p}"}, tmpdir)
    FileUtils.rm_r(tmpdir)

    # TODO(sissel): Make a helper method.
    system(*["gzip", "-f", tar_path])
  end

end # class FPM::Source::Gem