Class: MiniPortile
- Inherits:
-
Object
- Object
- MiniPortile
- Defined in:
- lib/mini_portile2/version.rb,
lib/mini_portile2/mini_portile.rb
Direct Known Subclasses
Constant Summary collapse
- VERSION =
"2.7.0"
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.
-
#source_directory ⇒ Object
Returns the value of attribute source_directory.
-
#target ⇒ Object
Returns the value of attribute target.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.mingw? ⇒ Boolean
GNU MinGW compiled Ruby?.
-
.mswin? ⇒ Boolean
MS Visual-C compiled Ruby?.
- .windows? ⇒ Boolean
Instance Method Summary collapse
- #activate ⇒ Object
- #apply_patch(patch_file) ⇒ Object
- #compile ⇒ Object
- #configure ⇒ Object
- #configured? ⇒ Boolean
- #cook ⇒ Object
- #download ⇒ Object
- #downloaded? ⇒ Boolean
- #extract ⇒ Object
- #gcc_cmd ⇒ Object
-
#initialize(name, version, **kwargs) ⇒ MiniPortile
constructor
A new instance of MiniPortile.
- #install ⇒ Object
- #installed? ⇒ Boolean
- #make_cmd ⇒ Object
- #patch ⇒ Object
- #path ⇒ Object
- #prepare_build_directory ⇒ Object
Constructor Details
#initialize(name, version, **kwargs) ⇒ MiniPortile
Returns a new instance of MiniPortile.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mini_portile2/mini_portile.rb', line 49 def initialize(name, version, **kwargs) @name = name @version = version @target = 'ports' @files = [] @patch_files = [] @log_files = {} @logger = STDOUT @source_directory = nil @original_host = @host = detect_host @gcc_command = kwargs[:gcc_command] @make_command = kwargs[:make_command] end |
Instance Attribute Details
#configure_options ⇒ Object
120 121 122 |
# File 'lib/mini_portile2/mini_portile.rb', line 120 def @configure_options ||= configure_defaults end |
#files ⇒ Object
Returns the value of attribute files.
33 34 35 |
# File 'lib/mini_portile2/mini_portile.rb', line 33 def files @files end |
#host ⇒ Object
Returns the value of attribute host.
33 34 35 |
# File 'lib/mini_portile2/mini_portile.rb', line 33 def host @host end |
#logger ⇒ Object
Returns the value of attribute logger.
33 34 35 |
# File 'lib/mini_portile2/mini_portile.rb', line 33 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/mini_portile2/mini_portile.rb', line 31 def name @name end |
#original_host ⇒ Object (readonly)
Returns the value of attribute original_host.
31 32 33 |
# File 'lib/mini_portile2/mini_portile.rb', line 31 def original_host @original_host end |
#patch_files ⇒ Object
Returns the value of attribute patch_files.
33 34 35 |
# File 'lib/mini_portile2/mini_portile.rb', line 33 def patch_files @patch_files end |
#source_directory ⇒ Object
Returns the value of attribute source_directory.
33 34 35 |
# File 'lib/mini_portile2/mini_portile.rb', line 33 def source_directory @source_directory end |
#target ⇒ Object
Returns the value of attribute target.
33 34 35 |
# File 'lib/mini_portile2/mini_portile.rb', line 33 def target @target end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
31 32 33 |
# File 'lib/mini_portile2/mini_portile.rb', line 31 def version @version end |
Class Method Details
.mingw? ⇒ Boolean
GNU MinGW compiled Ruby?
40 41 42 |
# File 'lib/mini_portile2/mini_portile.rb', line 40 def self.mingw? RbConfig::CONFIG['target_os'] =~ /mingw/ end |
.mswin? ⇒ Boolean
MS Visual-C compiled Ruby?
45 46 47 |
# File 'lib/mini_portile2/mini_portile.rb', line 45 def self.mswin? RbConfig::CONFIG['target_os'] =~ /mswin/ end |
.windows? ⇒ Boolean
35 36 37 |
# File 'lib/mini_portile2/mini_portile.rb', line 35 def self.windows? RbConfig::CONFIG['target_os'] =~ /mswin|mingw/ end |
Instance Method Details
#activate ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/mini_portile2/mini_portile.rb', line 189 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 |
#apply_patch(patch_file) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/mini_portile2/mini_portile.rb', line 90 def apply_patch(patch_file) ( # Not a class variable because closures will capture self. @apply_patch ||= case when which('git') lambda { |file| "Running git apply with #{file}... " # By --work-tree=. git-apply uses the current directory as # the project root and will not search upwards for .git. execute('patch', ["git", "--git-dir=.", "--work-tree=.", "apply", "--whitespace=warn", file], :initial_message => false) } when which('patch') lambda { |file| "Running patch with #{file}... " execute('patch', ["patch", "-p1", "-i", file], :initial_message => false) } else raise "Failed to complete patch task; patch(1) or git(1) is required." end ).call(patch_file) end |
#compile ⇒ Object
139 140 141 |
# File 'lib/mini_portile2/mini_portile.rb', line 139 def compile execute('compile', make_cmd) end |
#configure ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/mini_portile2/mini_portile.rb', line 124 def configure return if configured? FileUtils.mkdir_p(tmp_path) cache_file = File.join(tmp_path, 'configure.options_cache') File.open(cache_file, "w") { |f| f.write .to_s } command = Array(File.join((source_directory || "."), "configure")) if RUBY_PLATFORM=~/mingw|mswin/ # Windows doesn't recognize the shebang. command.unshift("sh") end execute('configure', command + ) end |
#configured? ⇒ Boolean
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/mini_portile2/mini_portile.rb', line 156 def configured? configure = File.join((source_directory || work_path), 'configure') makefile = File.join(work_path, 'Makefile') cache_file = File.join(tmp_path, 'configure.options_cache') = File.exist?(cache_file) ? File.read(cache_file) : "" = .to_s ( == ) && newer?(makefile, configure) end |
#cook ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/mini_portile2/mini_portile.rb', line 174 def cook if source_directory prepare_build_directory else download unless downloaded? extract patch end configure unless configured? compile install unless installed? return true end |
#download ⇒ Object
76 77 78 79 80 81 |
# File 'lib/mini_portile2/mini_portile.rb', line 76 def download files_hashs.each do |file| download_file(file[:url], file[:local_path]) verify_file(file) end end |
#downloaded? ⇒ Boolean
148 149 150 151 152 153 154 |
# File 'lib/mini_portile2/mini_portile.rb', line 148 def downloaded? missing = files_hashs.detect do |file| !File.exist?(file[:local_path]) end missing ? false : true end |
#extract ⇒ Object
83 84 85 86 87 88 |
# File 'lib/mini_portile2/mini_portile.rb', line 83 def extract files_hashs.each do |file| verify_file(file) extract_file(file[:local_path], tmp_path) end end |
#gcc_cmd ⇒ Object
228 229 230 |
# File 'lib/mini_portile2/mini_portile.rb', line 228 def gcc_cmd (ENV["CC"] || @gcc_command || RbConfig::CONFIG["CC"] || "gcc").dup end |
#install ⇒ Object
143 144 145 146 |
# File 'lib/mini_portile2/mini_portile.rb', line 143 def install return if installed? execute('install', %Q(#{make_cmd} install)) end |
#installed? ⇒ Boolean
167 168 169 170 171 172 |
# File 'lib/mini_portile2/mini_portile.rb', line 167 def installed? makefile = File.join(work_path, 'Makefile') target_dir = Dir.glob("#{port_path}/*").find { |d| File.directory?(d) } newer?(target_dir, makefile) end |
#make_cmd ⇒ Object
232 233 234 |
# File 'lib/mini_portile2/mini_portile.rb', line 232 def make_cmd (ENV["MAKE"] || @make_command || ENV["make"] || "make").dup end |
#patch ⇒ Object
113 114 115 116 117 118 |
# File 'lib/mini_portile2/mini_portile.rb', line 113 def patch @patch_files.each do |full_path| next unless File.exist?(full_path) apply_patch(full_path) end end |
#path ⇒ Object
224 225 226 |
# File 'lib/mini_portile2/mini_portile.rb', line 224 def path File.(port_path) end |
#prepare_build_directory ⇒ Object
69 70 71 72 73 74 |
# File 'lib/mini_portile2/mini_portile.rb', line 69 def prepare_build_directory raise "source_directory is not set" if source_directory.nil? output "Building #{@name} #{@version} from source at '#{source_directory}'" FileUtils.mkdir_p(File.join(tmp_path, [name, version].join("-"))) FileUtils.rm_rf(port_path) # make sure we always re-install end |