Class: MiniPortile
- Inherits:
-
Object
- Object
- MiniPortile
- Defined in:
- lib/mini_portile.rb
Instance Attribute Summary collapse
- #configure_options ⇒ Object
-
#files ⇒ Object
Returns the value of attribute files.
-
#host ⇒ Object
Returns the value of attribute host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#original_host ⇒ Object
readonly
Returns the value of attribute original_host.
-
#patch_files ⇒ Object
Returns the value of attribute patch_files.
-
#target ⇒ Object
Returns the value of attribute target.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #activate ⇒ Object
- #compile ⇒ Object
- #configure ⇒ Object
- #configured? ⇒ Boolean
- #cook ⇒ Object
- #download ⇒ Object
- #downloaded? ⇒ Boolean
- #extract ⇒ Object
-
#initialize(name, version) ⇒ MiniPortile
constructor
A new instance of MiniPortile.
- #install ⇒ Object
- #installed? ⇒ Boolean
- #patch ⇒ Object
- #path ⇒ Object
Constructor Details
#initialize(name, version) ⇒ MiniPortile
Returns a new instance of MiniPortile.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mini_portile.rb', line 13 def initialize(name, version) @name = name @version = version @target = 'ports' @files = [] @patch_files = [] @logger = STDOUT @original_host = @host = detect_host end |
Instance Attribute Details
#configure_options ⇒ Object
46 47 48 |
# File 'lib/mini_portile.rb', line 46 def @configure_options ||= configure_defaults end |
#files ⇒ Object
Returns the value of attribute files.
11 12 13 |
# File 'lib/mini_portile.rb', line 11 def files @files end |
#host ⇒ Object
Returns the value of attribute host.
11 12 13 |
# File 'lib/mini_portile.rb', line 11 def host @host end |
#logger ⇒ Object
Returns the value of attribute logger.
11 12 13 |
# File 'lib/mini_portile.rb', line 11 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/mini_portile.rb', line 9 def name @name end |
#original_host ⇒ Object (readonly)
Returns the value of attribute original_host.
9 10 11 |
# File 'lib/mini_portile.rb', line 9 def original_host @original_host end |
#patch_files ⇒ Object
Returns the value of attribute patch_files.
11 12 13 |
# File 'lib/mini_portile.rb', line 11 def patch_files @patch_files end |
#target ⇒ Object
Returns the value of attribute target.
11 12 13 |
# File 'lib/mini_portile.rb', line 11 def target @target end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/mini_portile.rb', line 9 def version @version end |
Instance Method Details
#activate ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/mini_portile.rb', line 107 def activate lib_path = File.join(port_path, "lib") vars = { 'PATH' => File.join(port_path, 'bin'), 'CPATH' => File.join(port_path, 'include'), 'LIBRARY_PATH' => lib_path }.reject { |env, path| !File.directory?(path) } output "Activating #{@name} #{@version} (from #{port_path})..." vars.each do |var, path| full_path = File.(path) # turn into a valid Windows path (if required) full_path.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR # save current variable value old_value = ENV[var] || '' unless old_value.include?(full_path) ENV[var] = "#{full_path}#{File::PATH_SEPARATOR}#{old_value}" end end # rely on LDFLAGS when cross-compiling if File.exist?(lib_path) && (@host != @original_host) full_path = File.(lib_path) old_value = ENV.fetch("LDFLAGS", "") unless old_value.include?(full_path) ENV["LDFLAGS"] = "-L#{full_path} #{old_value}".strip end end end |
#compile ⇒ Object
60 61 62 |
# File 'lib/mini_portile.rb', line 60 def compile execute('compile', 'make') end |
#configure ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/mini_portile.rb', line 50 def configure return if configured? md5_file = File.join(tmp_path, 'configure.md5') digest = Digest::MD5.hexdigest() File.open(md5_file, "w") { |f| f.write digest } execute('configure', %Q(sh configure #{})) end |
#configured? ⇒ Boolean
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mini_portile.rb', line 78 def configured? configure = File.join(work_path, 'configure') makefile = File.join(work_path, 'Makefile') md5_file = File.join(tmp_path, 'configure.md5') stored_md5 = File.exist?(md5_file) ? File.read(md5_file) : "" current_md5 = Digest::MD5.hexdigest() (current_md5 == stored_md5) && newer?(makefile, configure) end |
#cook ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/mini_portile.rb', line 96 def cook download unless downloaded? extract patch configure unless configured? compile install unless installed? return true end |
#download ⇒ Object
24 25 26 27 28 29 |
# File 'lib/mini_portile.rb', line 24 def download @files.each do |url| filename = File.basename(url) download_file(url, File.join(archives_path, filename)) end end |
#downloaded? ⇒ Boolean
69 70 71 72 73 74 75 76 |
# File 'lib/mini_portile.rb', line 69 def downloaded? missing = @files.detect do |url| filename = File.basename(url) !File.exist?(File.join(archives_path, filename)) end missing ? false : true end |
#extract ⇒ Object
31 32 33 34 35 36 |
# File 'lib/mini_portile.rb', line 31 def extract @files.each do |url| filename = File.basename(url) extract_file(File.join(archives_path, filename), tmp_path) end end |
#install ⇒ Object
64 65 66 67 |
# File 'lib/mini_portile.rb', line 64 def install return if installed? execute('install', %Q(make install)) end |
#installed? ⇒ Boolean
89 90 91 92 93 94 |
# File 'lib/mini_portile.rb', line 89 def installed? makefile = File.join(work_path, 'Makefile') target_dir = Dir.glob("#{port_path}/*").find { |d| File.directory?(d) } newer?(target_dir, makefile) end |
#patch ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/mini_portile.rb', line 38 def patch @patch_files.each do |full_path| next unless File.exists?(full_path) output "Running git apply with #{full_path}..." execute('patch', %Q(git apply #{full_path})) end end |
#path ⇒ Object
142 143 144 |
# File 'lib/mini_portile.rb', line 142 def path File.(port_path) end |