Skip to content

Commit

Permalink
- Fix version 'iteration' in package output
Browse files Browse the repository at this point in the history
- some style fixups
- Allow gems to be versioned (fpm -s gem -t deb -v 1.0 somegem) will
  fetch somegem version 1.0
  • Loading branch information
jordansissel committed Jan 8, 2011
1 parent b3337b3 commit 56fb96d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
1 change: 0 additions & 1 deletion bin/fpm
Expand Up @@ -63,7 +63,6 @@ def main(args)

opts.parse!(args)

p settings
FPM::Builder.new(settings, args).assemble!

return 0
Expand Down
15 changes: 11 additions & 4 deletions lib/fpm/builder.rb
Expand Up @@ -40,6 +40,7 @@ def initialize(settings, paths=[])
@paths = paths

@output = settings.package_path
@recurse_dependencies = settings.recurse_dependencies
end # def initialize

def tar_path
Expand All @@ -48,7 +49,7 @@ def tar_path

# Assemble the package
def assemble!
output.gsub!(/VERSION/, "#{@source[:version]}-#{@source[:iteration]}")
output.gsub!(/VERSION/, "#{@source[:version]}-#{@package.iteration}")
output.gsub!(/ARCH/, @package.architecture)

File.delete(output) if File.exists?(output) && !File.directory?(output)
Expand All @@ -70,22 +71,25 @@ def assemble!
end

cleanup!

end # def assemble!

private
private
def builddir
@builddir ||= File.expand_path(
"#{Dir.pwd}/build-#{@package.type}-#{File.basename(output)}"
)
end

private
def make_builddir!
FileUtils.rm_rf builddir
garbage << builddir
FileUtils.mkdir(builddir) if !File.directory?(builddir)
end

# TODO: [Jay] make this better.
private
def package_class_for(type)
type = FPM::Target::constants.find { |c| c.downcase == type }
if !type
Expand All @@ -96,6 +100,7 @@ def package_class_for(type)
end

# TODO: [Jay] make this better.
private
def source_class_for(type)
type = FPM::Source::constants.find { |c| c.downcase == type }
if !type
Expand All @@ -105,29 +110,31 @@ def source_class_for(type)
return FPM::Source.const_get(type)
end

private
def cleanup!
return [] if garbage.empty?
FileUtils.rm_rf(garbage) && garbage.clear
end

private
def generate_specfile
File.open(@package.specfile(builddir), "w") do |f|
f.puts @package.render_spec
end
end

private
def generate_md5sums
md5sums = checksum(paths)
File.open("#{builddir}/md5sums", "w") { |f| f.puts md5sums }
md5sums
end

private
def checksum(paths)
md5sums = []
paths.each do |path|
md5sums += %x{find #{path} -type f -print0 | xargs -0 md5sum}.split("\n")
end
end # def checksum


end
5 changes: 3 additions & 2 deletions lib/fpm/source.rb
Expand Up @@ -28,7 +28,7 @@ def initialize(paths, root, params={})
@paths = paths
@root = root

get_source
get_source(params)
get_metadata

# override the inferred data with the passed-in data
Expand All @@ -46,9 +46,10 @@ def get_metadata

# This method should be overridden by package sources that need to do any
# kind of fetching.
def get_source
def get_source(params)
# noop by default
end # def get_source

def make_tarball!(tar_path)
raise NoMethodError,
"Please subclass FPM::Source and define make_tarball!(tar_path)"
Expand Down
12 changes: 8 additions & 4 deletions lib/fpm/source/gem.rb
Expand Up @@ -5,19 +5,22 @@
require "fileutils"

class FPM::Source::Gem < FPM::Source
def get_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
# TODO(sissel): Use the Gem API
download(gem)
download(gem, params[:version])
else
raise "Path '#{gem}' is not a file and does not appear to be the name of a rubygem."
end
end
end # def get_source

def can_recurse_dependencies
true
end

def download(gem_name, version=nil)
# This code mostly mutated from rubygem's fetch_command.rb
# Code use permissible by rubygems's "GPL or these conditions below"
Expand All @@ -27,11 +30,12 @@ def download(gem_name, version=nil)
dep = ::Gem::Dependency.new gem_name, version
# How to handle prerelease? Some extra magic options?
#dep.prerelease = options[:prerelease]

specs_and_sources, errors =
::Gem::SpecFetcher.fetcher.fetch_with_errors(dep, false, true, false)
spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last


if spec.nil? then
raise "Invalid gem? Name: #{gem_name}, Version: #{version}, Errors: #{errors}"
end
Expand Down

0 comments on commit 56fb96d

Please sign in to comment.