Skip to content
Browse files

Merge pull request #88 from tabletcorry/master

Adds gem prefix and safesystem
  • Loading branch information...
2 parents 05e7568 + 01bda52 commit bd346e752ead4873fa1b3ee0714157aec3787878 @jordansissel committed Aug 19, 2011
View
7 lib/fpm/builder.rb
@@ -1,4 +1,5 @@
require "fileutils"
+require "fpm/util"
require "pathname"
class FPM::Builder
@@ -102,10 +103,10 @@ def assemble!
data_tarball = File.join(builddir, "data.tar.gz")
Dir.chdir(builddir) do
FileUtils.mkdir_p(@package.unpack_data_to)
- system("gzip -d #{data_tarball}")
+ safesystem("gzip -d #{data_tarball}")
Dir.chdir(@package.unpack_data_to) do
@source.root = Dir.pwd
- system("tar -xf #{data_tarball.gsub(/\.gz$/, "")}")
+ safesystem("tar -xf #{data_tarball.gsub(/\.gz$/, "")}")
end
end
end
@@ -185,7 +186,7 @@ def edit_specfile
# TODO(sissel): support editing multiple files for targets like
# puppet which generate multiple manifests.
editor = ENV['FPM_EDITOR'] || ENV['EDITOR'] || 'vi'
- system("#{editor} '#{package.specfile(builddir)}'")
+ safesystem("#{editor} '#{package.specfile(builddir)}'")
unless File.size? package.specfile(builddir)
puts "Empty specfile. Aborting."
exit 1
View
5 lib/fpm/source.rb
@@ -1,4 +1,5 @@
require "fpm/namespace"
+require "fpm/util"
# Abstract class for a "thing to build a package from"
class FPM::Source
@@ -124,15 +125,15 @@ def tar(output, paths, chdir=".")
+ dirs
::Dir.chdir(chdir) do
- system(*dir_tar) if dirs.any?
+ safesystem(*dir_tar) if dirs.any?
end
files_tar = [ tar_cmd ] \
+ excludes \
+ [ "--owner=root", "--group=root", "-rf", output ] \
+ paths
::Dir.chdir(chdir) do
- system(*files_tar)
+ safesystem(*files_tar)
end
end # def tar
View
7 lib/fpm/source/dir.rb
@@ -1,6 +1,7 @@
require "fpm/source"
require "fileutils"
require "fpm/rubyfixes"
+require "fpm/util"
class FPM::Source::Dir < FPM::Source
def get_metadata
@@ -31,7 +32,7 @@ def make_tarball!(tar_path, builddir)
::FileUtils.mkdir_p(dest)
rsync = ["rsync", "-a", path, dest]
p rsync
- system(*rsync)
+ safesystem(*rsync)
# FileUtils.cp_r is pretty silly about how it copies files in some
# cases (funky permissions, etc)
@@ -45,14 +46,14 @@ def make_tarball!(tar_path, builddir)
end
::Dir.chdir("#{builddir}/tarbuild") do
- system("ls #{builddir}/tarbuild")
+ safesystem("ls #{builddir}/tarbuild")
tar(tar_path, ".")
end
else
tar(tar_path, paths)
end
# TODO(sissel): Make a helper method.
- system(*["gzip", "-f", tar_path])
+ safesystem(*["gzip", "-f", tar_path])
end # def make_tarball!
end # class FPM::Source::Dir
View
18 lib/fpm/source/gem.rb
@@ -3,13 +3,18 @@
require "rubygems/package"
require "rubygems"
require "fileutils"
+require "fpm/util"
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
+ opts.on("--package-prefix PREFIX",
+ "Prefix for gem packages") do |package_prefix|
+ settings.source[:package_prefix] = package_prefix
+ end
end # def flags
def get_source(params)
@@ -70,7 +75,12 @@ def get_metadata
self[field.to_sym] = spec.send(field) rescue "unknown"
end
- self[:name] = "rubygem#{self[:suffix]}-#{spec.name}"
+ if self[:settings][:package_prefix]
+ self[:package_prefix] = self[:settings][:package_prefix]
+ else
+ self[:package_prefix] = "rubygem"
+ end
+ self[:name] = "#{self[:package_prefix]}#{self[:suffix]}-#{spec.name}"
self[:maintainer] = spec.author
self[:url] = spec.homepage
@@ -100,7 +110,7 @@ def get_metadata
# Some reqs can be ">= a, < b" versions, let's handle that.
reqs.to_s.split(/, */).each do |req|
- self[:dependencies] << "rubygem#{self[:suffix]}-#{dep.name} #{req}"
+ self[:dependencies] << "#{self[:package_prefix]}#{self[:suffix]}-#{dep.name} #{req}"
end
end # runtime_dependencies
end # ::Gem::Package
@@ -131,14 +141,14 @@ def make_tarball!(tar_path, builddir)
end
args << gem
- system(*args)
+ safesystem(*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])
+ safesystem(*["gzip", "-f", tar_path])
end
end # class FPM::Source::Gem
View
5 lib/fpm/source/npm.rb
@@ -1,5 +1,6 @@
require "fpm/namespace"
require "fpm/source"
+require "fpm/util"
require "fileutils"
class FPM::Source::Npm < FPM::Source
@@ -25,11 +26,11 @@ def make_tarball!(tar_path, builddir)
::FileUtils.mkdir_p(installdir)
args = ["gem", "install", "--quiet", "--no-ri", "--no-rdoc",
"--install-dir", installdir, "--ignore-dependencies", @paths.first]
- system(*args)
+ safesystem(*args)
tar(tar_path, ".", tmpdir)
# TODO(sissel): Make a helper method.
- system(*["gzip", "-f", tar_path])
+ safesystem(*["gzip", "-f", tar_path])
end
end # class FPM::Source::Gem
View
27 lib/fpm/source/python.rb
@@ -1,5 +1,6 @@
require "fpm/namespace"
require "fpm/source"
+require "fpm/util"
require "rubygems/package"
require "rubygems"
require "fileutils"
@@ -20,6 +21,12 @@ def self.flags(opts, settings)
"The path to your easy_install tool. Default is 'easy_install'") do |path|
settings.source[:easy_install] = path
end
+
+ opts.on("--package-prefix PREFIX",
+ "Prefix for python packages") do |package_prefix|
+ settings.source[:package_prefix] = package_prefix
+ end
+
end # def flags
def get_source(params)
@@ -47,11 +54,7 @@ def download(package, version=nil)
want_pkg = "#{package}==#{version}"
end
- return_value = system(self[:settings][:easy_install], "--editable", "--build-directory", @tmpdir, want_pkg)
-
- if return_value.nil?
- raise "The execution of #{self[:settings][:easy_install]} failed"
- end
+ safesystem(self[:settings][:easy_install], "--editable", "--build-directory", @tmpdir, want_pkg)
# easy_install will put stuff in @tmpdir/packagename/, flatten that.
# That is, we want @tmpdir/setup.py, and start with
@@ -81,16 +84,22 @@ def get_metadata
metadata = JSON.parse(output[/\{.*\}/msx])
#p metadata
+ if self[:settings][:package_prefix]
+ self[:package_prefix] = self[:settings][:package_prefix]
+ else
+ self[:package_prefix] = "python"
+ end
+
self[:architecture] = metadata["architecture"]
self[:description] = metadata["description"]
self[:license] = metadata["license"]
self[:version] = metadata["version"]
- self[:name] = "python#{self[:suffix]}-#{metadata["name"]}"
+ self[:name] = "#{self[:package_prefix]}#{self[:suffix]}-#{metadata["name"]}"
self[:url] = metadata["url"]
self[:dependencies] = metadata["dependencies"].collect do |dep|
name, cmp, version = dep.split
- "python#{self[:suffix]}-#{name} #{cmp} #{version}"
+ "#{self[:package_prefix]}#{self[:suffix]}-#{name} #{cmp} #{version}"
end
end # def get_metadata
@@ -101,7 +110,7 @@ def make_tarball!(tar_path, builddir)
# Some setup.py's assume $PWD == current directory of setup.py, so let's
# chdir first.
::Dir.chdir(dir) do
- system(self[:settings][:python], "setup.py", "bdist")
+ safesystem(self[:settings][:python], "setup.py", "bdist")
end
dist_tar = ::Dir.glob(File.join(dir, "dist", "*.tar.gz")).first
@@ -110,7 +119,7 @@ def make_tarball!(tar_path, builddir)
@paths = [ "." ]
- system("cp", dist_tar, "#{tar_path}.gz")
+ safesystem("cp", dist_tar, "#{tar_path}.gz")
end # def make_tarball!
def garbage
View
5 lib/fpm/source/rpm.rb
@@ -1,4 +1,5 @@
require "fpm/source"
+require "fpm/util"
class FPM::Source::RPM < FPM::Source
def get_metadata
@@ -18,10 +19,10 @@ def get_metadata
def make_tarball!(tar_path, builddir)
tmpdir = "#{tar_path}.dir"
::Dir.mkdir(tmpdir)
- system("rpm2cpio #{@rpm} | (cd #{tmpdir}; cpio -i --make-directories)")
+ safesystem("rpm2cpio #{@rpm} | (cd #{tmpdir}; cpio -i --make-directories)")
tar(tar_path, ".", tmpdir)
@paths = ["."]
# TODO(sissel): Make a helper method.
- system(*["gzip", "-f", tar_path])
+ safesystem(*["gzip", "-f", tar_path])
end
end
View
7 lib/fpm/source/tar.rb
@@ -1,6 +1,7 @@
+require "fpm/rubyfixes"
require "fpm/source"
+require "fpm/util"
require "fileutils"
-require "fpm/rubyfixes"
class FPM::Source::Tar < FPM::Source
def get_metadata
@@ -31,7 +32,7 @@ def make_tarball!(tar_path, builddir)
end
#puts("tar #{flags}")
#sleep 5
- system("tar #{flags}")
+ safesystem("tar #{flags}")
if self[:prefix]
@paths = [self[:prefix]]
@@ -44,6 +45,6 @@ def make_tarball!(tar_path, builddir)
end
# TODO(sissel): Make a helper method.
- system(*["gzip", "-f", tar_path])
+ safesystem(*["gzip", "-f", tar_path])
end # def make_tarball!
end # class FPM::Source::Dir
View
13 lib/fpm/target/deb.rb
@@ -2,6 +2,7 @@
require "fpm/namespace"
require "fpm/package"
require "fpm/errors"
+require "fpm/util"
class FPM::Target::Deb < FPM::Package
@@ -66,16 +67,16 @@ def build!(params)
self.scripts.each do |name, path|
case name
when "pre-install"
- system("cp #{path} ./preinst")
+ safesystem("cp #{path} ./preinst")
control_files << "preinst"
when "post-install"
- system("cp #{path} ./postinst")
+ safesystem("cp #{path} ./postinst")
control_files << "postinst"
when "pre-uninstall"
- system("cp #{path} ./prerm")
+ safesystem("cp #{path} ./prerm")
control_files << "prerm"
when "post-uninstall"
- system("cp #{path} ./postrm")
+ safesystem("cp #{path} ./postrm")
control_files << "postrm"
else raise "Unsupported script name '#{name}' (path: #{path})"
end # case name
@@ -87,13 +88,13 @@ def build!(params)
end
# Make the control
- system("tar -zcf control.tar.gz #{control_files.map{ |f| "./#{f}" }.join(" ")}")
+ safesystem("tar -zcf control.tar.gz #{control_files.map{ |f| "./#{f}" }.join(" ")}")
# create debian-binary
File.open("debian-binary", "w") { |f| f.puts "2.0" }
# pack up the .deb
- system("ar -qc #{params[:output]} debian-binary control.tar.gz data.tar.gz")
+ safesystem("ar -qc #{params[:output]} debian-binary control.tar.gz data.tar.gz")
end # def build
def default_output
View
8 lib/fpm/target/rpm.rb
@@ -1,4 +1,5 @@
require "fpm/package"
+require "fpm/util"
class FPM::Target::Rpm < FPM::Package
def architecture
@@ -38,14 +39,11 @@ def build!(params)
"--define", "_sourcedir #{Dir.pwd}",
"--define", "_rpmdir #{Dir.pwd}/RPMS",
"#{name}.spec"]
- ret = system(*args)
- if !ret
- raise "rpmbuild failed (exit code: #{$?.exitstatus})"
- end
+ safesystem(*args)
Dir["#{Dir.pwd}/RPMS/**/*.rpm"].each do |path|
# This should only output one rpm, should we verify this?
- system("mv", path, params[:output])
+ safesystem("mv", path, params[:output])
end
end # def build!
end # class FPM::Target::RPM
View
13 lib/fpm/target/solaris.rb
@@ -2,6 +2,7 @@
require "fpm/namespace"
require "fpm/package"
require "fpm/errors"
+require "fpm/util"
# TODO(sissel): Add dependency checking support.
# IIRC this has to be done as a 'checkinstall' step.
@@ -25,10 +26,10 @@ def build!(params)
self.scripts.each do |name, path|
case name
when "pre-install"
- system("cp #{path} ./preinstall")
+ safesystem("cp #{path} ./preinstall")
File.chmod(0755, "./preinstall")
when "post-install"
- system("cp #{path} ./postinstall")
+ safesystem("cp #{path} ./postinstall")
File.chmod(0755, "./postinstall")
when "pre-uninstall"
raise FPM::InvalidPackageConfiguration.new(
@@ -43,9 +44,9 @@ def build!(params)
# Unpack data.tar.gz so we can build a package from it.
Dir.mkdir("data")
- system("gzip -d data.tar.gz");
+ safesystem("gzip -d data.tar.gz");
Dir.chdir("data") do
- system("tar -xf ../data.tar");
+ safesystem("tar -xf ../data.tar");
end
#system("(echo 'i pkginfo'; pkgproto data=/) > Prototype")
@@ -69,10 +70,10 @@ def build!(params)
end # File prototype
# Should create a package directory named by the package name.
- system("pkgmk -o -d .")
+ safesystem("pkgmk -o -d .")
# Convert the 'package directory' built above to a real solaris package.
- system("pkgtrans -s . #{params[:output]} #{name}")
+ safesystem("pkgtrans -s . #{params[:output]} #{name}")
end # def build
def default_output
View
7 lib/fpm/util.rb
@@ -0,0 +1,7 @@
+def safesystem(*call)
+ return_val = system(*call)
+ if !return_val
+ raise "'#{call}' failed with error code: #{$?.exitstatus}"
+ end
+ return return_val
+end # def safesystem

0 comments on commit bd346e7

Please sign in to comment.
Something went wrong with that request. Please try again.