This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

rpg-package-spec does everything gemspec related

  • Loading branch information...
rtomayko committed Mar 15, 2010
1 parent 0783e80 commit eb3ac032a1423938ebca775bfc4a1c4bfc94ae3d
Showing with 158 additions and 20 deletions.
  1. +2 −0 .gitignore
  2. +12 −3 Makefile
  3. +2 −17 rpg-package-register.sh
  4. +142 −0 rpg-package-spec.rb
View
@@ -41,3 +41,5 @@
/rpg-package-register
/rpg-parse-package-list
/rpg-solve
+/rpg-unpack
+/rpg-package-spec
View
@@ -33,14 +33,16 @@ SOURCES = \
rpg-install.sh rpg-list.sh rpg-version-test.sh rpg-uninstall.sh \
rpg-build.sh rpg-env.sh rpg-update.sh rpg-resolve.sh rpg-upgrade.sh \
rpg-steal.sh rpg-fsck.sh rpg-status.sh rpg-outdated.sh \
- rpg-package-register.sh rpg-package-install.sh rpg-solve.sh rpg-unpack.sh
+ rpg-package-register.sh rpg-package-install.sh rpg-solve.sh rpg-unpack.sh \
+ rpg-package-spec.rb
PROGRAMS = \
rpg-sh-setup rpg rpg-config rpg-deps rpg-fetch \
rpg-install rpg-list rpg-version-test rpg-uninstall \
rpg-build rpg-env rpg-update rpg-resolve rpg-upgrade \
rpg-steal rpg-fsck rpg-status rpg-outdated rpg-parse-package-list \
- rpg-package-register rpg-package-install rpg-solve rpg-unpack
+ rpg-package-register rpg-package-install rpg-solve rpg-unpack \
+ rpg-package-spec
DOCHTML = \
rpg-sh-setup.html rpg.html rpg-config.html rpg-deps.html rpg-fetch.html \
@@ -63,6 +65,13 @@ STANDALONE = $(NAME)-sa
echo " SHOCCO $@"
shocco $< > $@
+.rb:
+ echo " RUBY $@"
+ ruby -c $<
+ rm -f $@
+ cp $< $@
+ chmod a-w+x $@
+
build: $(PROGRAMS)
auto:
@@ -105,4 +114,4 @@ clean:
.SILENT:
-.SUFFIXES: .sh .html
+.SUFFIXES: .sh .html .rb
View
@@ -59,25 +59,10 @@ do
# The `name` and `version` files are redundant since that info can be
# obtained from `$(basename $(dirname <path>))` and `$(basename <path>)`,
# but having them there makes some things a bit easier.
- #
- # TODO this gemspec extraction nonsense needs to go. find a better way
- # to get the deps and other information.
mkdir -p "$packagedir"
echo "$package" > "$packagedir/name"
echo "$version" > "$packagedir/version"
-
- gem spec --ruby "$file" > "$gemspec"
- ruby <<RUBY
- require 'rubygems'
- spec = eval(File.read('$gemspec'), binding, '$gemspec', 1)
- File.open('$deps', 'wb') do |fd|
- spec.dependencies.each do |dep|
- dep.requirement.as_list.each do |req|
- fd.puts '%s %s %s' % [dep.type, dep.name, req]
- end
- end
- end
-RUBY
-
+ rpg-unpack -cm "$file" > "$gemspec"
+ rpg-package-spec -i "$gemspec"
echo "$packagedir"
done
View
@@ -0,0 +1,142 @@
+#!/usr/bin/env ruby
+# Read YAML gemspecs given as arguments or on standard input and write
+# rpg formatted spec hierarchies to the package database.
+USAGE = <<BANNER
+Usage: rpg-package-spec <spec>
+ rpg-package-spec [-i|--import] <spec> ...
+Deal with gemspecs.
+
+In the first form, read gemspec YAML from a gemspec or gem file and write
+parseable output to standard output. In the second form, read multiple
+gemspec files into the package database.
+
+Options
+ -i, --import Load gemspec data into the package database. No output
+ is written. Multiple files may be specified.
+
+This is a low level command used by the rpg package database machinery.
+BANNER
+
+# Bail out with no arguments or --help.
+if ARGV.empty?
+ puts USAGE
+ exit 2
+elsif ARGV.include?('--help')
+ puts USAGE
+ exit 0
+end
+
+# Re-execute through rpg if the environment isn't right.
+exec "rpg", $0, *ARGV if ENV['RPGDB'].empty?
+
+# Figure out if we're in import mode or print formatted output mode.
+if ['-i', '--import'].include?(ARGV.first)
+ ARGV.shift
+ import_mode = true
+else
+ import_mode = false
+end
+
+# Load the YAML in from file or extract from gem using `rpg-unpack(1)`.
+require 'ostruct'
+require 'yaml'
+
+ARGV.each do |file|
+ yaml =
+ if file =~ /\.gem$/
+ `rpg unpack -cm '#{file}'`
+ else
+ File.read(file)
+ end
+ doc = YAML.load(yaml)
+
+ # Turn this fucker into something sensible.
+ spec = doc.ivars.dup
+ spec['version'] = spec['version'].ivars['version']
+ spec['dependencies'] =
+ spec['dependencies'].map do |dep|
+ vars = dep.ivars
+ [
+ vars['name'],
+ vars['type'],
+ vars['version_requirements'].ivars['requirements'].map do |op,vers|
+ vers = vers.ivars['version']
+ [op, vers]
+ end
+ ]
+ end
+ spec['date'] =
+ case spec['date']
+ when Time; spec['date'].utc.strftime('%Y-%m-%d')
+ when Date; spec['date'].to_s
+ else fail "unexpected date value: #{spec['date'].inspect}"
+ end
+ spec.reject! { |k,v| v.respond_to?(:ivars) }
+
+ if import_mode
+
+ # Grab the package name and version.
+ package = spec['name']
+ version = spec['version']
+ package_dir = "#{ENV['RPGDB']}/#{package}/#{version}"
+
+ if !File.directory?(package_dir)
+ Dir.mkdir File.dirname(package_dir) rescue nil
+ Dir.mkdir package_dir rescue nil
+ if !File.directory?(package_dir)
+ abort "#{File.basename($0)}: package directory missing."
+ end
+ end
+
+ package_write =
+ lambda do |file, value|
+ File.open("#{package_dir}/#{file}", 'wb') do |fd|
+ fd.puts(value.to_s)
+ end
+ end
+
+ %w[name version date homepage platform email bindir summary description].each do |key|
+ package_write.call key, spec[key]
+ end
+
+ %w[authors files extensions executables test_files require_paths].each do |key|
+ next if spec[key].nil?
+ label = 'tests' if key == 'test_files'
+ label = 'libs' if key == 'require_paths'
+ package_write.call key, spec[key].join("\n")
+ end
+
+ File.open "#{package_dir}/dependencies", 'wb' do |fd|
+ spec['dependencies'].each do |name, type, reqs|
+ reqs.each do |op, vers|
+ fd.puts "#{type} #{name} #{op} #{vers}"
+ end
+ end
+ end
+
+ else
+
+ %w[name version date homepage platform email bindir].each do |key|
+ puts "#{key}: #{spec[key]}"
+ end
+
+ puts "rdoc: #{spec['rdoc_options'].join(' ')}"
+
+ %w[authors files extensions executables test_files require_paths].each do |key|
+ next if spec[key].nil?
+ label = key.chomp('s')
+ label = 'test' if key == 'test_files'
+ label = 'lib' if key == 'require_paths'
+ spec[key].each do |line|
+ puts "#{label}: #{line}"
+ end
+ end
+
+ spec['dependencies'].each do |name, type, reqs|
+ reqs.each do |op, vers|
+ puts "dependency: #{type} #{name} #{op} #{vers}"
+ end
+ end
+
+ end
+end

0 comments on commit eb3ac03

Please sign in to comment.