1 #!/opt/ruby-enterprise/bin/ruby
10 PKGBUILD = %{# Generated by gem2arch-ruby-enterprise
12 _gemname=<%= gem_name %>
13 pkgname=ruby-enterprise-$_gemname
16 pkgdesc="<%= description %>"
17 arch=('i686' 'x86_64')
20 depends=('ruby-enterprise'<%= depends %>)
21 makedepends=('ruby-enterprise')
22 source=(http://gems.rubyforge.org/gems/$_gemname-$pkgver.gem)
23 noextract=($_gemname-$pkgver.gem)
24 md5sums=('<%= md5sum %>')
28 local _gemdir=`/opt/ruby-enterprise/bin/ruby -rubygems -e'puts Gem.default_dir'`
29 /opt/ruby-enterprise/bin/gem install --ignore-dependencies --no-rdoc --no-ri -i "$pkgdir$_gemdir" $_gemname-$pkgver.gem
33 def download(gem_name, gem_ver = nil)
34 version = gem_ver || Gem::Requirement.default
36 all = Gem::Requirement.default
37 dep = Gem::Dependency.new gem_name, version
39 puts "Fetch #{gem_name} spec"
41 specs_and_sources = Gem::SpecFetcher.fetcher.fetch dep, all
42 specs_and_sources.sort_by { |spec,| spec.version }
43 spec, source_uri = specs_and_sources.last
46 $stderr.puts "Could not find #{gem_name} in any repository"
50 puts "Downloaded #{spec.full_name}"
52 path = Gem::RemoteFetcher.fetcher.download spec, source_uri
53 FileUtils.mv path, "#{spec.full_name}.gem"
58 def calc_digest(file_name)
59 md5sum = Digest::MD5.new
60 file_size = File.size file_name
62 File.open(file_name) do |f|
63 while buf = f.read(1024)
71 def gen_pkgbuild(spec)
73 gem_ver = spec.version
75 contact = ENV['ARCH_RUBY'] || ''
77 website = spec.homepage
78 description = spec.summary
80 md5sum = calc_digest(spec.full_name + '.gem')
82 depends = spec.runtime_dependencies
83 depends = if depends.empty? then ""
85 ' ' + depends.map do |d|
86 d.requirement.requirements.map do |comp, ver|
87 comp = '>=' if comp == '~>'
88 "'ruby-enterprise-#{d.name}#{comp}#{ver}'"
93 return ERB.new(PKGBUILD).result(binding)
98 puts "Usage: #{$0} GEM_NAME [GEM_VER]"
102 Dir.mktmpdir do |tmp_dir|
106 spec = download *ARGV.take(2)
108 target_dir = "#{base_dir}/ruby-enterprise-#{spec.name}"
109 Dir.mkdir target_dir unless File.exist? target_dir
112 'PKGBUILD' => lambda {|s| gen_pkgbuild s }
113 }.each do |file, gen_file|
114 puts "Generated #{file} for ruby-enterprise-#{spec.full_name}"
115 File.open(file, 'w') {|f| f.write gen_file.call(spec) }
117 FileUtils.mv file, target_dir