Skip to content

Commit 79fd1f1

Browse files
committed
add_source reworked to extract patchlevel from sources
patchlevel defined in version.h so let's extract it from there. Also added ability to use already downloaded .tgz
1 parent 231bfd1 commit 79fd1f1

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

Rakefile

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,56 @@ require 'fileutils'
66
require 'bundler'
77
Bundler::GemHelper.install_tasks
88

9-
desc 'Add ruby headers under lib for a given VERSION and PATCHLEVEL'
10-
task :add_source do
11-
version = ENV['VERSION'] or abort "Need a $VERSION"
12-
ruby_dir = "ruby-#{version}"
13-
minor_version = version.split('.')[0..1].join('.')
14-
uri_path = "http://ftp.ruby-lang.org/pub/ruby/#{minor_version}/#{ruby_dir}.tar.gz"
9+
def get_dest_dir(ruby_dir, version, tempdir)
1510
dest_dir = File.dirname(__FILE__) + "/lib/debase/ruby_core_source/#{ruby_dir}"
11+
return dest_dir if version.include?('-p')
1612

1713
patchlevel = ENV['PATCHLEVEL']
18-
if patchlevel
19-
dest_dir = dest_dir + "-p" + patchlevel
20-
elsif !version.include?('-p')
21-
abort "Need a $PATCHLEVEL"
14+
if !patchlevel
15+
puts "extracting patchlevel from version.h"
16+
patchlevel = File.new("#{tempdir}/#{ruby_dir}/version.h").each_line do |li|
17+
if /#define RUBY_PATCHLEVEL (\d+)/ =~ li
18+
break $1
19+
end
20+
end
21+
puts "extracted patchlevel '#{patchlevel}'"
22+
end
23+
if !patchlevel
24+
abort "Unable to extract patchlevel from verion.h please use a $PATCHLEVEL"
2225
end
26+
dest_dir = dest_dir + "-p" + patchlevel
27+
end
2328

29+
desc <<DESCR
30+
Add ruby headers under lib for a given VERSION and (optional) PATCHLEVEL,
31+
\t\t\tif patchlevel is not provided it will be extracted from version.h.
32+
\t\t\tTGZ_FILE_NAME can be used to provide pre-downloaded tgz file
33+
DESCR
34+
task :add_source do
35+
version = ENV['VERSION'] or abort "Need a $VERSION"
36+
ruby_dir = "ruby-#{version}"
2437

25-
puts "Downloading #{uri_path}..."
26-
temp = open(uri_path)
38+
if ENV['TGZ_FILE_NAME']
39+
temp = ENV['TGZ_FILE_NAME']
40+
puts "Using pre-downloaded bundle #{temp}"
41+
else
42+
minor_version = version.split('.')[0..1].join('.')
43+
uri_path = "http://ftp.ruby-lang.org/pub/ruby/#{minor_version}/#{ruby_dir}.tar.gz"
44+
puts "Downloading #{uri_path}..."
45+
temp = open(uri_path)
46+
end
2747
puts "Unpacking #{uri_path}..."
2848
tgz = Zlib::GzipReader.new(File.open(temp, "rb"))
2949

30-
FileUtils.mkdir_p(dest_dir)
3150
Dir.mktmpdir do |dir|
3251
inc_dir = dir + "/" + ruby_dir + "/*.inc"
3352
hdr_dir = dir + "/" + ruby_dir + "/*.h"
3453
more_hdr_dir = dir + "/" + ruby_dir + "/ccan/**/*.h"
3554
Archive::Tar::Minitar.unpack(tgz, dir)
55+
56+
dest_dir = get_dest_dir(ruby_dir, version, dir)
57+
puts dest_dir
58+
FileUtils.mkdir_p(dest_dir)
3659
Dir.glob([ inc_dir, hdr_dir, more_hdr_dir ]).each do |file|
3760
target = file.sub(dir + '/' + ruby_dir, dest_dir)
3861
FileUtils.mkdir_p(File.dirname(target))

0 commit comments

Comments
 (0)