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] || options[:mass_generate])
31 if options[:mass_generate] == true
33 puts "Ebuilds are in #{Portage.rubydev_overlay}"
37 spec_groups = packages.map {|pkg| get_specs(pkg)}
38 all_specs = spec_groups.flatten
42 puts "Create ebuild for #{spec.full_name}" if options[:verbose]
43 gem_ebuild = Ebuild.new(spec)
47 # No prepend, digest the ebuilds
48 if options[:prepend] == false
49 ebuilds.each {|ebuild| ebuild.execute('digest')}
51 # don't specify --generate, continue digest and emerge
52 if options[:generate] == false
53 system('emerge '+ARGV.join(' '))
56 # don't clean up if --generate because overlay may be /tmp/*
57 if options[:generate] == true
58 puts "Ebuilds are in #{Portage.rubydev_overlay}"
66 navigate(pkg.package_name,pkg.gem_requirement) { |spec| specs << spec }
70 def navigate(gem_name,gem_version = nil,&block)
71 if Portage.ebuild_exists(gem_name,gem_version)
72 puts "Ebuild for #{gem_name} exists" if options[:verbose]
75 # cache source_index_hash, no need to recheck it everytime
76 @@gri = Gem::RemoteInstaller.new if @@gri.nil?
77 @@sources = @@gri.source_index_hash if @@sources.nil?
78 version_requirement = gem_version.is_a?(Gem::Version::Requirement) ? gem_version : Gem::Version::Requirement.new(gem_version || ">= 0")
80 for source_name,source in @@sources
81 specs = source.find_name(gem_name, version_requirement)
82 next if specs.nil? or specs.empty?
83 # ignore mswin32 platform
84 satisfied_specs = specs.find_all do |spec|
85 spec.platform == 'ruby' and
86 version_requirement.satisfied_by?(spec.version)
88 gem_spec = satisfied_specs[-1]
90 def local?() false; end
91 def set_source(source)
98 gem_spec.set_source(source_name)
102 puts "#{gem_name} not found"
106 for dep in gem_spec.dependencies
107 navigate(dep.name, dep.requirement_list, &block)
118 :mass_generate => false
124 for i in 1..arg.length-1
125 if SHORTMAP.key? arg[i..i]
126 opts[SHORTMAP[arg[i..i]]] = true
128 puts "Unknown option '-#{arg[i..i]}'"
132 if LONGMAP.key? arg[2..-1]
133 opts[LONGMAP[arg[2..-1]]] = true
135 puts "Unknown option '#{arg}'"
138 packages << DependencyAtom.new(arg)
141 return opts, packages
145 @@gri = Gem::RemoteInstaller.new if @@gri.nil?
146 @@sources = @@gri.source_index_hash if @@sources.nil?
147 for source_name,source in @@sources
148 source.each do |full_name,spec|
149 if spec.platform == 'ruby'
152 def local?() false; end
153 def set_source(source) @source = source end
154 def fetched_from() @source end
156 spec.set_source(source_name)