-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Rakefile
67 lines (53 loc) · 2.03 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require "fileutils"
require "tempfile"
require "bundler/gem_tasks"
BINARY_FILES = [ "seven_zip_archive.so", "seven_zip_archive.bundle" ]
MAKE = (ENV["MAKE"] || ENV["make"] || (RUBY_PLATFORM.include?("mswin") ? "nmake" : "make"))
task :build_platform => [ :pre_platform, :build, :post_platform ]
task :pre_platform do
FileUtils.mv("seven_zip_ruby.gemspec", "seven_zip_ruby.gemspec.bak")
versions = Dir.glob("lib/seven_zip_ruby/*").select{ |i| File.directory?(i) }.map{ |i| i.split("/").last }.sort_by{ |i| i.split(".").map(&:to_i) }
min_version = versions.first + ".0"
max_version = versions.last.split(".").first + "." + (versions.last.split(".").last.to_i + 1).to_s + ".0"
gemspec = File.open("resources/seven_zip_ruby.gemspec.platform", "r", &:read)
.gsub("SPEC_REQUIRED_RUBY_VERSION"){ "spec.required_ruby_version = [ '>= #{min_version}', '< #{max_version}' ]" }
File.open("seven_zip_ruby.gemspec", "w") do |f|
f.write(gemspec)
end
end
task :post_platform do
FileUtils.mv("seven_zip_ruby.gemspec.bak", "seven_zip_ruby.gemspec")
end
task :build_local_all => [ :build_local_clean, :build_local ]
task :build_local => [ :build_binary, :copy_binary ]
task :build_local_clean do
Dir.chdir "ext/seven_zip_ruby" do
sh("#{MAKE} clean") if (File.exist?("Makefile"))
end
[ "ext/seven_zip_ruby", "lib/seven_zip_ruby" ].each do |dir|
FileUtils.rmtree(BINARY_FILES.map{ |i| "#{dir}/#{i}" })
end
end
task :build_binary do
Dir.chdir "ext/seven_zip_ruby" do
FileUtils.rmtree BINARY_FILES
Tempfile.open([ "site", ".rb" ], Dir.pwd) do |temp|
temp.puts <<"EOS"
require('rbconfig')
RbConfig::CONFIG['sitearchdir'] = "../../lib"
EOS
temp.flush
sh "ruby -r#{File.expand_path(temp.path)} extconf.rb"
temp.unlink
end
sh "#{MAKE}"
end
end
task :copy_binary do
BINARY_FILES.each do |file|
src = File.join("ext", "seven_zip_ruby", file)
dest = File.join("lib", "seven_zip_ruby", file)
FileUtils.rmtree(dest) if (File.exist?(dest))
FileUtils.cp(src, dest) if (File.exist?(src))
end
end