Sha256: a7448e8b7898a7b1fee78aeb57ef64b34cb2ba3bcbfa90312f4fbaac2c12c4a7

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require File.expand_path('../../lib/rdkafka/version', __FILE__)
require "mini_portile2"
require "fileutils"

task :default => :clean do
  # MiniPortile#download_file_http is a monkey patch that removes the download
  # progress indicator. This indicator relies on the 'Content Length' response
  # headers, which is not set by GitHub
  class MiniPortile
    def download_file_http(url, full_path, _count)
      filename = File.basename(full_path)
      with_tempfile(filename, full_path) do |temp_file|
        params = { 'Accept-Encoding' => 'identity' }
        OpenURI.open_uri(url, 'rb', params) do |io|
          temp_file.write(io.read)
        end
        output
      end
    end
  end

  # Download and compile librdkafka
  recipe = MiniPortile.new("librdkafka", Rdkafka::LIBRDKAFKA_VERSION)
  recipe.files = ["https://codeload.github.com/edenhill/librdkafka/tar.gz/v#{Rdkafka::LIBRDKAFKA_VERSION}"]
  recipe.configure_options = ["--host=#{recipe.host}"]
  recipe.cook
  # Move dynamic library we're interested in
  if recipe.host.include?('darwin')
    from_extension = '1.dylib'
    to_extension   = 'dylib'
  else
    from_extension = 'so.1'
    to_extension = 'so'
  end
  lib_path = File.join(File.dirname(__FILE__), "ports/#{recipe.host}/librdkafka/#{Rdkafka::LIBRDKAFKA_VERSION}/lib/librdkafka.#{from_extension}")
  FileUtils.mv(lib_path, File.join(File.dirname(__FILE__), "librdkafka.#{to_extension}"))
  # Cleanup files created by miniportile we don't need in the gem
  FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
  FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
end

task :clean do
  FileUtils.rm_f File.join(File.dirname(__FILE__), "librdkafka.dylib")
  FileUtils.rm_f File.join(File.dirname(__FILE__), "librdkafka.so")
  FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
  FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rdkafka-0.4.0 ext/Rakefile