16 'prepend' => :prepend,
17 'verbose' => :verbose,
19 'generate' => :generate,
20 'madgen' => :mass_generate,
25 attr_accessor :options
28 @options, packages = parse_opts(ARGV)
29 Portage.setup_overlay(options[:prepend])
31 mass_generate and return if @options[:mass_generate] == true
33 spec_groups = packages.map {|pkg| get_specs(pkg)}
34 all_specs = spec_groups.flatten
38 puts "Create ebuild for #{spec.full_name}" if options[:verbose]
39 gem_ebuild = Ebuild.new(spec)
43 # No prepend, digest the ebuilds
44 if options[:prepend] == false
45 ebuilds.each {|ebuild| ebuild.execute('digest')}
47 # don't specify --generate, continue digest and emerge
48 if options[:generate] == false
49 system('emerge '+ARGV.join(' '))
51 puts "Ebuilds are in #{Portage.rubydev_overlay}"
54 # don't clean up if --generate because overlay may be /tmp/*
55 Portage.cleanup unless options[:generate] == true
60 navigate(pkg.package_name,pkg.gem_requirement) { |spec| specs << spec }
64 def navigate(gem_name,gem_version = nil,&block)
65 if Portage.ebuild_exists(gem_name,gem_version)
66 puts "Ebuild for #{gem_name} exists" if options[:verbose]
69 # cache source_index_hash, no need to recheck it everytime
70 @@gri = Gem::RemoteInstaller.new if @@gri.nil?
71 @@sources = @@gri.source_index_hash if @@sources.nil?
72 version_requirement = gem_version.is_a?(Gem::Version::Requirement) ? gem_version : Gem::Version::Requirement.new(gem_version || ">= 0")
74 for source_name,source in @@sources
75 specs = source.find_name(gem_name, version_requirement)
76 next if specs.nil? or specs.empty?
77 # ignore mswin32 platform
78 satisfied_specs = specs.find_all do |spec|
79 spec.platform == 'ruby' and
80 version_requirement.satisfied_by?(spec.version)
82 gem_spec = satisfied_specs[-1]
84 def local?() false; end
85 def set_source(source)
92 gem_spec.set_source(source_name)
96 puts "#{gem_name} not found"
100 for dep in gem_spec.dependencies
101 navigate(dep.name, dep.requirement_list, &block)
112 :mass_generate => false
118 for i in 1..arg.length-1
119 if SHORTMAP.key? arg[i..i]
120 opts[SHORTMAP[arg[i..i]]] = true
122 puts "Unknown option '-#{arg[i..i]}'"
126 if LONGMAP.key? arg[2..-1]
127 opts[LONGMAP[arg[2..-1]]] = true
129 puts "Unknown option '#{arg}'"
132 packages << DependencyAtom.new(arg)
135 return opts, packages
139 @@gri = Gem::RemoteInstaller.new if @@gri.nil?
140 @@sources = @@gri.source_index_hash if @@sources.nil?
141 for source_name,source in @@sources
142 source.each do |full_name,spec|
143 if spec.platform == 'ruby'
146 def local?() false; end
147 def set_source(source) @source = source end
148 def fetched_from() @source end