5 attr_reader :overlay_dirs, :portage_dir, :portage_distdir, :portage_dev_ruby, :category
6 attr_reader :rubydev_overlay
8 def init(path="/etc/make.conf")
10 @overlay_dirs = %x(/usr/lib/portage/bin/portageq portdir_overlay).chomp.split(/ +/)
11 @portage_dir = %x(/usr/lib/portage/bin/portageq portdir).chomp
12 @portage_distdir = %x(/usr/lib/portage/bin/portageq distdir).chomp
13 @category = 'dev-ruby'
14 @ruby_vdb = File.join(%x(/usr/lib/portage/bin/portageq distdir).chomp,@category)
15 @portage_dir = '/usr/portage' unless File.directory? @portage_dir
16 @portage_distdir = '/usr/portage/distfiles' unless File.directory? @portage_distdir
17 @portage_dev_ruby = File.join(@portage_dir,@category)
19 @tmp_overlay_dir = "/tmp/ruby-modules_#{Process.pid}"
20 @overlay_dir = @overlay_dirs.find {|o| File.directory? o}
23 def setup_overlay(tmp_overlay = false)
24 @overlay_dir = (tmp_overlay == false && @overlay_dir) || @tmp_overlay_dir
25 Dir.mkdir(@overlay_dir, 0755) unless File.directory? @overlay_dir
26 @rubydev_overlay = File.join(@overlay_dir,@category)
27 Dir.mkdir(@rubydev_overlay, 0755) unless File.directory? @rubydev_overlay
28 ENV['PORTDIR_OVERLAY'] = @overlay_dir
32 # Should strictly check to make sure we don't accidentally rm_rf $HOME for example
33 if @overlay_dir == @tmp_overlay_dir and File.directory? @tmp_overlay_dir and @tmp_overlay_dir =~ /^\/tmp\//
35 FileUtils.rm_rf @tmp_overlay_dir
40 @cached_env = {} unless @cached_env.is_a? Hash
41 unless @cached_env.key? envvar
42 value = %x(/usr/lib/portage/bin/portageq envvar #{envvar}).chomp
43 @cached_env[envvar] = value
48 def ebuild_exists(name, gem_version)
49 portage_dir = File.join(@portage_dev_ruby,name)
50 overlay_dir = File.join(@rubydev_overlay,name)
51 version_requirement = gem_version.is_a?(Gem::Version::Requirement) ? gem_version : Gem::Version::Requirement.new(gem_version || ">= 0")
52 ebuilds = Dir.glob(File.join(portage_dir,'*.ebuild')) + Dir.glob(File.join(overlay_dir,'*.ebuild'))
53 return false if ebuilds.empty?
54 ebuilds.map! {|e| File.basename(e).gsub(/\.ebuild$/,'') }
55 satisfied_ebuild = ebuilds.find do |e|
56 dep_atom = DependencyAtom.new('='+e)
57 version = Gem::Version.create(dep_atom.version)
58 version_requirement.satisfied_by?(version)
60 satisfied_ebuild != nil
63 end # class ConfigFile