-
Notifications
You must be signed in to change notification settings - Fork 17
/
Rakefile
70 lines (63 loc) · 2.18 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
68
69
require 'tmpdir'
require 'open-uri'
require 'archive/tar/minitar'
require 'zlib'
require 'fileutils'
require 'bundler'
Bundler::GemHelper.install_tasks
def get_dest_dir(ruby_dir, version, tempdir)
dest_dir = File.dirname(__FILE__) + "/lib/debase/ruby_core_source/#{ruby_dir}"
return dest_dir if version.include?('-p')
patchlevel = ENV['PATCHLEVEL']
if !patchlevel
puts "extracting patchlevel from version.h"
patchlevel = File.new("#{tempdir}/#{ruby_dir}/version.h").each_line.map do |li|
if /#define RUBY_PATCHLEVEL (-?\d+)/ =~ li
break $1
else
nil
end
end#.find { |p| not p.nil?}
puts "extracted patchlevel '#{patchlevel}'"
end
if patchlevel
dest_dir = dest_dir + "-p" + patchlevel unless patchlevel == '-1'
else
warn "Unable to extract patchlevel from verion.h assuming there is no patchlevel please use a $PATCHLEVEL to specify one"
end
dest_dir
end
desc <<DESCR
Add ruby headers under lib for a given VERSION and (optional) PATCHLEVEL,
\t\t\tif patchlevel is not provided it will be extracted from version.h.
\t\t\tTGZ_FILE_NAME can be used to provide pre-downloaded tgz file
DESCR
task :add_source do
version = ENV['VERSION'] or abort "Need a $VERSION"
ruby_dir = "ruby-#{version}"
if ENV['TGZ_FILE_NAME']
temp = ENV['TGZ_FILE_NAME']
puts "Using pre-downloaded bundle #{temp}"
else
minor_version = version.split('.')[0..1].join('.')
uri_path = "http://ftp.ruby-lang.org/pub/ruby/#{minor_version}/#{ruby_dir}.tar.gz"
puts "Downloading #{uri_path}..."
temp = open(uri_path)
end
puts "Unpacking #{uri_path}..."
tgz = Zlib::GzipReader.new(File.open(temp, "rb"))
Dir.mktmpdir do |dir|
inc_dir = dir + "/" + ruby_dir + "/*.inc"
hdr_dir = dir + "/" + ruby_dir + "/*.h"
more_hdr_dir = dir + "/" + ruby_dir + "/ccan/**/*.h"
Archive::Tar::Minitar.unpack(tgz, dir)
dest_dir = get_dest_dir(ruby_dir, version, dir)
puts dest_dir
FileUtils.mkdir_p(dest_dir)
Dir.glob([ inc_dir, hdr_dir, more_hdr_dir ]).each do |file|
target = file.sub(dir + '/' + ruby_dir, dest_dir)
FileUtils.mkdir_p(File.dirname(target))
FileUtils.cp(file, target, verbose: false)
end
end
end