This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
require 'rubygems/package_task'
|
||||
require 'rake/extensiontask'
|
||||
require 'rake/javaextensiontask'
|
||||
|
||||
def gemspec
|
||||
@clean_gemspec ||= eval(File.read(File.expand_path('../../http_parser.rb.gemspec', __FILE__)))
|
||||
end
|
||||
|
||||
Gem::PackageTask.new(gemspec) do |pkg|
|
||||
end
|
||||
|
||||
if RUBY_PLATFORM =~ /java/
|
||||
Rake::JavaExtensionTask.new("ruby_http_parser", gemspec) do |ext|
|
||||
ext.classpath = File.expand_path('../../ext/ruby_http_parser/vendor/http-parser-java/ext/primitives.jar', __FILE__)
|
||||
end
|
||||
else
|
||||
Rake::ExtensionTask.new("ruby_http_parser", gemspec) do |ext|
|
||||
unless RUBY_PLATFORM =~ /mswin|mingw/
|
||||
ext.cross_compile = true
|
||||
ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
|
||||
|
||||
# inject 1.8/1.9 pure-ruby entry point
|
||||
ext.cross_compiling do |spec|
|
||||
spec.files += ['lib/ruby_http_parser.rb']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
file 'lib/ruby_http_parser.rb' do |t|
|
||||
File.open(t.name, 'wb') do |f|
|
||||
f.write <<-eoruby
|
||||
RUBY_VERSION =~ /(\\d+.\\d+)/
|
||||
require "\#{$1}/ruby_http_parser"
|
||||
eoruby
|
||||
end
|
||||
at_exit{ FileUtils.rm t.name if File.exists?(t.name) }
|
||||
end
|
||||
|
||||
if Rake::Task.task_defined?(:cross)
|
||||
task :cross => 'lib/ruby_http_parser.rb'
|
||||
end
|
||||
@@ -0,0 +1,71 @@
|
||||
desc "Generate test fixtures"
|
||||
task :fixtures => :submodules do
|
||||
require 'yajl'
|
||||
data = File.read File.expand_path('../../ext/ruby_http_parser/vendor/http-parser/test.c', __FILE__)
|
||||
|
||||
%w[ requests responses ].each do |type|
|
||||
# find test definitions in between requests/responses[]= and .name=NULL
|
||||
tmp = data[/#{type}\[\]\s*=(.+?),\s*\{\s*\.name=\s*NULL/m, 1]
|
||||
|
||||
# replace first { with a [ (parsing an array of test cases)
|
||||
tmp.sub!('{','[')
|
||||
|
||||
# replace booleans
|
||||
tmp.gsub!('TRUE', 'true')
|
||||
tmp.gsub!('FALSE', 'false')
|
||||
|
||||
# mark strict mode tests
|
||||
tmp.gsub!(%r|#if\s+!HTTP_PARSER_STRICT(.+?)#endif\s*/\*\s*!HTTP_PARSER_STRICT.+\n|m){
|
||||
$1.gsub(/^(.+,\.type= .+)$/, "\\1\n, .strict= false")
|
||||
}
|
||||
|
||||
# remove macros and comments
|
||||
tmp.gsub!(/^#(if|elif|endif|define).+$/,'')
|
||||
tmp.gsub!(/\/\*(.+?)\*\/$/,'')
|
||||
|
||||
# HTTP_* enums become strings
|
||||
tmp.gsub!(/(= )(HTTP_\w+)/){
|
||||
"#{$1}#{$2.sub('MSEARCH','M-SEARCH').dump}"
|
||||
}
|
||||
|
||||
# join multiline strings for body and raw data
|
||||
tmp.gsub!(/((body|raw)\s*=)(.+?)(\n\s+[\},])/m){
|
||||
before, after = $1, $4
|
||||
raw = $3.split("\n").map{ |l| l.strip[1..-2] }.join('')
|
||||
"#{before} \"#{raw}\" #{after}"
|
||||
}
|
||||
|
||||
# make headers an array of array tuples
|
||||
tmp.gsub!(/(\.headers\s*=)(.+?)(\s*,\.)/m){
|
||||
before, after = $1, $3
|
||||
raw = $2.gsub('{', '[').gsub('}', ']')
|
||||
"#{before} #{raw} #{after}"
|
||||
}
|
||||
|
||||
# .name= becomes "name":
|
||||
tmp.gsub!(/^(.{2,5})\.(\w+)\s*=/){
|
||||
"#{$1}#{$2.dump}: "
|
||||
}
|
||||
|
||||
# evaluate addition expressions
|
||||
tmp.gsub!(/(body_size\":\s*)(\d+)\+(\d+)/){
|
||||
"#{$1}#{$2.to_i+$3.to_i}"
|
||||
}
|
||||
|
||||
# end result array
|
||||
tmp << ']'
|
||||
|
||||
# normalize data
|
||||
results = Yajl.load(tmp, :symbolize_keys => true)
|
||||
results.map{ |res|
|
||||
res[:headers] and res[:headers] = Hash[*res[:headers].flatten]
|
||||
res[:method] and res[:method].gsub!(/^HTTP_/, '')
|
||||
res[:strict] = true unless res.has_key?(:strict)
|
||||
}
|
||||
|
||||
# write to a file
|
||||
File.open("spec/support/#{type}.json", 'w'){ |f|
|
||||
f.write Yajl.dump(results, :pretty => true)
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
require "rspec/core/rake_task"
|
||||
|
||||
RSpec::Core::RakeTask.new do |t|
|
||||
t.rspec_opts = %w(--format documentation --color)
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
desc "Fetch upstream submodules"
|
||||
task :submodules do
|
||||
if Dir['ext/ruby_http_parser/vendor/http-parser/*'].empty?
|
||||
sh 'git submodule init'
|
||||
sh 'git submodule update'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user