Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix permission issue on some environment #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rubygems'
require 'rubygems/package_task'
require 'rake/testtask'
require "rake/extensiontask"

spec = eval(File.new("wkhtmltopdf-binary.gemspec").readlines.join("\n"))

Expand All @@ -14,3 +15,6 @@ end

desc 'Run tests'
task default: :test

Rake::ExtensionTask.new "wkhtmltopdf" do |ext|
end
45 changes: 45 additions & 0 deletions ext/wkhtmltopdf/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'mkmf'
require 'rbconfig'
require 'zlib'

suffix = case RbConfig::CONFIG['host_os']
when /linux/
os = `. /etc/os-release 2> /dev/null && echo ${ID}_${VERSION_ID}`.strip

if os.start_with?('elementary') || os.start_with?('linuxmint') || os.start_with?('pop')
os = 'ubuntu_18.04'
end

# CentOS 6 doesn't have `/etc/os-release`.
if (os.empty? && File.read('/etc/centos-release').start_with?('CentOS release 6')) ||
os.start_with?('amzn_')
os = 'centos_6'
end

# Deepin fallback
os = 'debian_9' if /deepin/.match?(os)

architecture = RbConfig::CONFIG['host_cpu'] == 'x86_64' ? 'amd64' : 'i386'

"#{os}_#{architecture}"
when /darwin/
'macos_cocoa'
else
'unknown'
end

binary = File.join(File.dirname(__FILE__), "../../bin/wkhtmltopdf_#{suffix}")
puts binary
if File.exist?("#{binary}.gz") && !File.exist?(binary)
File.open binary, 'wb', 0o755 do |file|
Zlib::GzipReader.open("#{binary}.gz") { |gzip| file << gzip.read }
end
end

unless File.exist? binary
raise 'Invalid platform, must be running on Ubuntu 16.04/18.04/20.04 ' \
'CentOS 6/7/8, Debian 9/10, or intel-based Cocoa macOS ' \
"(missing binary: #{binary})."
end

create_makefile 'wkhtmltopdf/wkhtmltopdf'
Empty file added ext/wkhtmltopdf/wkhtmltopdf.c
Empty file.
1 change: 1 addition & 0 deletions wkhtmltopdf-binary.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Gem::Specification.new do |s|
s.files = Dir['bin/*']
s.executables << "wkhtmltopdf"
s.require_path = '.'
s.extensions = %w[ext/wkhtmltopdf/extconf.rb]

s.add_development_dependency "minitest"
end