|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require File.expand_path('../../lib/rdkafka/version', __FILE__) |
| 4 | +require "digest" |
4 | 5 | require "fileutils" |
5 | 6 | require "open-uri" |
6 | 7 |
|
@@ -71,14 +72,50 @@ task :clean do |
71 | 72 | FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp") |
72 | 73 | end |
73 | 74 |
|
| 75 | +namespace :dist do |
| 76 | + task :dir do |
| 77 | + ENV["RDKAFKA_DIST_PATH"] ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'dist')) |
| 78 | + end |
| 79 | + |
| 80 | + task :file => "dist:dir" do |
| 81 | + ENV["RDKAFKA_DIST_FILE"] ||= File.join(ENV["RDKAFKA_DIST_PATH"], "librdkafka_#{Rdkafka::LIBRDKAFKA_VERSION}.tar.gz") |
| 82 | + end |
| 83 | + |
| 84 | + task :clean => "dist:file" do |
| 85 | + Dir.glob(File.join("#{ENV['RDKAFKA_DIST_PATH']}", "*")).each do |filename| |
| 86 | + next if filename.include? ENV["RDKAFKA_DIST_FILE"] |
| 87 | + |
| 88 | + FileUtils.rm_rf filename |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + task :download => "dist:file" do |
| 93 | + version = Rdkafka::LIBRDKAFKA_VERSION |
| 94 | + librdkafka_download = "https://codeload.github.com/confluentinc/librdkafka/tar.gz/v#{version}" |
| 95 | + |
| 96 | + URI.open(librdkafka_download) do |file| |
| 97 | + filename = ENV["RDKAFKA_DIST_FILE"] |
| 98 | + data = file.read |
| 99 | + |
| 100 | + if Digest::SHA256.hexdigest(data) != Rdkafka::LIBRDKAFKA_SOURCE_SHA256 |
| 101 | + raise "SHA256 does not match downloaded file" |
| 102 | + end |
| 103 | + |
| 104 | + File.write(filename, data) |
| 105 | + end |
| 106 | + end |
| 107 | + |
| 108 | + task :update => %w[dist:download dist:clean] |
| 109 | +end |
| 110 | + |
74 | 111 | namespace :build do |
75 | 112 | desc "Build librdkafka at the given git sha or tag" |
76 | 113 | task :git, [:ref] do |task, args| |
77 | 114 | ref = args[:ref] |
78 | 115 | version = "git-#{ref}" |
79 | 116 |
|
80 | 117 | recipe = MiniPortile.new("librdkafka", version) |
81 | | - recipe.files << "https://github.com/edenhill/librdkafka/archive/#{ref}.tar.gz" |
| 118 | + recipe.files << "https://github.com/confluentinc/librdkafka/archive/#{ref}.tar.gz" |
82 | 119 | recipe.configure_options = ["--host=#{recipe.host}","--enable-static", "--enable-zstd"] |
83 | 120 | recipe.cook |
84 | 121 |
|
|
0 commit comments