Re: Let's discuss big changes in Ruby packaging for squeeze+1
On 22/04/10 at 07:33 -0600, Marcelo E. Magallon wrote:
> When I was exploring a similar idea, I was thinking of going
> with:
>
> DIR=`basename "$gem" .gem`
> mkdir "$DIR"
> tar xOf "$gem" data.tar.gz | tar -C "$DIR" -xzf -
My own implementation:
#!/bin/bash
set -x
set -e
GEM=$1
BASENAME=$(basename $GEM .gem)
TDIR=$(mktemp -d /tmp/gem2tgz.XXXXXX)
mkdir $TDIR/$BASENAME
tar xf $GEM -O data.tar.gz | tar xz -C $TDIR/$BASENAME
tar xf $GEM -O metadata.gz | gunzip > $TDIR/$BASENAME/metadata
# Fix timestamps of files
find $TDIR/$BASENAME -exec touch -m {} \+
tar czf $BASENAME.tgz -C $TDIR $BASENAME
rm -rf $TDIR
> And using the gem metadata to extract things like the gem name,
> version, etc.
>
> But then I realised that it's better to use Rubygem's library,
> which allows for something like:
>
> require 'rubygems/format'
> format = Gem::Format.from_file_by_path ARGV.first
> spec = format.spec
> puts "Gem: #{spec.name} (#{spec.version})"
> format.file_entries.each do |entry, data|
> # entry['path'] is the file's path
> # entry['mode'] is the file's mode
> # data contains the actual file data
>
> # you only need to add sanity checks and filters here and
> # write data to entry['path']
> end
>
> It's a real pity that the gem spec does not include the license
> information in a machine readable format.
The problem with using the gem library is that I usually prefer not to
have it installed, to make it easier to detect usages of "require
'rubygems'". Maybe we should have our own private copy of just
rubygems/format for that.
--
| Lucas Nussbaum
| lucas@lucas-nussbaum.net http://www.lucas-nussbaum.net/ |
| jabber: lucas@nussbaum.fr GPG: 1024D/023B3F4F |
Reply to: