Skip to content

Commit

Permalink
- Add general way for source plugins to add flags specific to that
Browse files Browse the repository at this point in the history
  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.
  #27
  • Loading branch information
jordansissel committed May 17, 2011
1 parent 5288f92 commit 00e6e8b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
7 changes: 7 additions & 0 deletions bin/fpm
Expand Up @@ -8,11 +8,15 @@ 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 ||= {}

Expand Down Expand Up @@ -125,6 +129,9 @@ def main(args)
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
Expand Down
3 changes: 2 additions & 1 deletion lib/fpm/builder.rb
Expand Up @@ -41,7 +41,8 @@ def initialize(settings, paths=[])
:maintainer => settings.maintainer,
:provides => [],
:description => settings.description,
:url => settings.url
:url => settings.url,
:settings => settings.source
)

@edit = !!settings.edit
Expand Down
20 changes: 20 additions & 0 deletions lib/fpm/flags.rb
@@ -0,0 +1,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
22 changes: 19 additions & 3 deletions lib/fpm/source/gem.rb
Expand Up @@ -5,6 +5,13 @@
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_-]+$/
Expand Down Expand Up @@ -102,17 +109,26 @@ def make_tarball!(tar_path, builddir)
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 = "#{tmpdir}/#{::Gem::dir}"
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", gem]
"--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)

tar(tar_path, ".#{@paths.first}", tmpdir)
# make paths relative (/foo becomes ./foo)
tar(tar_path, @paths.collect {|p| ".#{p}"}, tmpdir)
FileUtils.rm_r(tmpdir)

# TODO(sissel): Make a helper method.
Expand Down

0 comments on commit 00e6e8b

Please sign in to comment.