Class: RdKafkaRecipe
- Inherits:
-
MiniPortile
- Object
- MiniPortile
- RdKafkaRecipe
- Defined in:
- ext/hermann/extconf.rb
Overview
MiniPortile overrides
RdKafkaRecipe is a class that adds some librdkafka specific customizations to make sure that we can safely build librdkafka when installing this gem
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Returns the value of attribute checksum.
Instance Method Summary collapse
- #configure ⇒ Object
-
#configure_defaults ⇒ Object
Overriding this from MiniPortile because it includes autoconf defaults that don’t apply to librdkafka’s mklove-based configure script.
- #configured? ⇒ Boolean
- #download_file(url, full_path, count = 3) ⇒ Object
- #download_file_http(url, full_path, count = 3) ⇒ Object
Instance Attribute Details
#checksum ⇒ Object
Returns the value of attribute checksum.
23 24 25 |
# File 'ext/hermann/extconf.rb', line 23 def checksum @checksum end |
Instance Method Details
#configure ⇒ Object
25 26 27 |
# File 'ext/hermann/extconf.rb', line 25 def configure execute('configure', %Q(bash configure #{})) end |
#configure_defaults ⇒ Object
Overriding this from MiniPortile because it includes autoconf defaults that don’t apply to librdkafka’s mklove-based configure script
35 36 37 |
# File 'ext/hermann/extconf.rb', line 35 def configure_defaults [] end |
#configured? ⇒ Boolean
29 30 31 |
# File 'ext/hermann/extconf.rb', line 29 def configured? File.exists?(File.join(work_path, 'Makefile.config')) end |
#download_file(url, full_path, count = 3) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'ext/hermann/extconf.rb', line 39 def download_file(url, full_path, count=3) super(url, full_path, count) # Support some simple checksumming unless Digest::MD5.hexdigest(File.read(full_path)) == checksum raise 'Checksum error!' end end |
#download_file_http(url, full_path, count = 3) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'ext/hermann/extconf.rb', line 48 def download_file_http(url, full_path, count = 3) filename = File.basename(full_path) uri = URI.parse(url) if ENV['http_proxy'] _, userinfo, p_host, p_port = URI.split(ENV['http_proxy']) proxy_user, proxy_pass = userinfo.split(/:/) if userinfo http = Net::HTTP.new(uri.host, uri.port, p_host, p_port, proxy_user, proxy_pass) else http = Net::HTTP.new(uri.host, uri.port) if URI::HTTPS === uri http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER store = OpenSSL::X509::Store.new # Auto-include system-provided certificates store.set_default_paths if ENV.has_key?("SSL_CERT_FILE") && File.exist?(ENV["SSL_CERT_FILE"]) store.add_file ENV["SSL_CERT_FILE"] end http.cert_store = store end end "Downloading #{filename} " http.start do |h| h.request_get(uri.path, 'Accept-Encoding' => 'identity') do |response| case response when Net::HTTPNotFound output "404 - Not Found" return false when Net::HTTPClientError output "Error: Client Error: #{response.inspect}" return false when Net::HTTPRedirection raise "Too many redirections for the original URL, halting." if count <= 0 url = response["location"] return download_file(url, full_path, count - 1) when Net::HTTPOK return with_tempfile(filename, full_path) do |temp_file| size = 0 progress = 0 total = response.header["Content-Length"].to_i if total == 0 # There are cases when apparently GitHub.com will return an empty # content-length header, which means we can't really trust the # response, so we'll treat it like a redirect puts "Empty content-length header, retrying" return download_file(url, full_path, count - 1) end response.read_body do |chunk| temp_file << chunk size += chunk.size new_progress = (size * 100) / total unless new_progress == progress "\rDownloading %s (%3d%%) " % [filename, new_progress] end progress = new_progress end output end end end end end |