forked from masamitsu-murase/seven_zip_ruby
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRakefile
More file actions
81 lines (65 loc) · 2.41 KB
/
Rakefile
File metadata and controls
81 lines (65 loc) · 2.41 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require "fileutils"
require "tempfile"
require "bundler/gem_tasks"
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
end
BINARY_FILES = [ "seven_zip_ruby/seven_zip_archive.so", "p7zip/bin/7z.so", "seven_zip_ruby/seven_zip_archive.bundle" ]
EXTENSIONS = [ "seven_zip_ruby", "p7zip" ]
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 => [ :clean_local, :build_local ]
task :build_local => [ :build_binary, :copy_binary ]
task :clean_local do
EXTENSIONS.each do |ext|
Dir.chdir "ext/#{ext}" do
sh("#{MAKE} clean") if (File.exist?("Makefile"))
end
end
FileUtils.rm_f(BINARY_FILES.map{ |i| "ext/#{i}" })
end
task :build_binary do
FileUtils.cp "ext/p7zip/makefile","ext/p7zip/makefile.old"
EXTENSIONS.each do |ext|
Dir.chdir "ext/#{ext}" do
FileUtils.rm_f(BINARY_FILES.map{ |i| "ext/#{i}" })
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
FileUtils.rm_f "ext/p7zip/Makefile"
FileUtils.mv "ext/p7zip/makefile.old","ext/p7zip/makefile"
end
task :copy_binary do
BINARY_FILES.each do |file|
dest = File.join("lib", "seven_zip_ruby", File.basename(file))
FileUtils.rmtree(dest) if (File.exist?(dest))
src = File.join("ext", file)
FileUtils.cp(src, dest) if (File.exist?(src))
end
end
task default: %i[build_local spec]