1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Merge pull request #33 from luislavena/build-cleanup

Build cleanup and better Windows support
This commit is contained in:
Evan Phoenix 2012-01-08 16:43:32 -08:00
commit 6461a18769
11 changed files with 81 additions and 72 deletions

View file

@ -1,90 +1,96 @@
require 'rubygems'
require 'hoe'
require "hoe"
require "rake/extensiontask"
require "rake/javaextensiontask"
IS_JRUBY = defined?(RUBY_ENGINE) ? RUBY_ENGINE == "jruby" : false
HOE = Hoe.spec 'puma' do
HOE = Hoe.spec "puma" do
self.rubyforge_name = 'puma'
self.readme_file = "README.md"
developer 'Evan Phoenix', 'evan@phx.io'
spec_extras[:extensions] = ["ext/puma_http11/extconf.rb"]
spec_extras[:executables] = ['puma', 'pumactl']
dependency 'rack', '~> 1.2'
require_ruby_version ">= 1.8.7"
extra_dev_deps << ['rake-compiler', "~> 0.7.0"]
dependency "rack", "~> 1.2"
clean_globs.push('test_*.log', 'log')
extra_dev_deps << ["rake-compiler", "~> 0.8.0"]
end
task :test => [:compile]
# hoe/test and rake-compiler don't seem to play well together, so disable
# hoe/test's .gemtest touch file thingy for now
HOE.spec.files -= [".gemtest"]
# puma.gemspec
file "#{HOE.spec.name}.gemspec" => ['Rakefile'] do |t|
puts "Generating #{t.name}"
File.open(t.name, 'w') { |f| f.puts HOE.spec.to_ruby }
File.open(t.name, 'wb') { |f| f.write HOE.spec.to_ruby }
end
desc "Generate or update the standalone gemspec file for the project"
task :gemspec => ["#{HOE.spec.name}.gemspec"]
# the following tasks ease the build of C file from Ragel one
# generate extension code using Ragel (C and Java)
desc "Generate extension code (C and Java) using Ragel"
task :ragel
file 'ext/puma_http11/http11_parser.c' => ['ext/puma_http11/http11_parser.rl'] do |t|
begin
sh "ragel #{t.prerequisites.last} -C -G2 -o #{t.name}"
sh "ragel #{t.prerequisites.last} -C -G2 -I ext/puma_http11 -o #{t.name}"
rescue
fail "Could not build wrapper using Ragel (it failed or not installed?)"
end
end
task :ragel => ['ext/puma_http11/http11_parser.c']
file 'ext/puma_http11/org/jruby/puma/Http11Parser.java' => ['ext/puma_http11/http11_parser.java.rl'] do |t|
begin
sh "ragel #{t.prerequisites.last} -J -G2 -o #{t.name}"
sh "ragel #{t.prerequisites.last} -J -G2 -I ext/puma_http11 -o #{t.name}"
rescue
fail "Could not build wrapper using Ragel (it failed or not installed?)"
end
end
task :ragel => ['ext/puma_http11/org/jruby/puma/Http11Parser.java']
if IS_JRUBY
require 'rake/javaextensiontask'
# compile extensions using rake-compiler
# C (MRI, Rubinius)
Rake::ExtensionTask.new("puma_http11", HOE.spec) do |ext|
# place extension inside namespace
ext.lib_dir = "lib/puma"
# build http11 java extension
Rake::JavaExtensionTask.new('puma_http11', HOE.spec)
task :ragel => 'ext/puma_http11/org/jruby/puma/Http11Parser.java'
else
# use rake-compiler for building the extension
require 'rake/extensiontask'
# build http11 C extension
Rake::ExtensionTask.new('puma_http11', HOE.spec) do |ext|
# define target for extension (supporting fat binaries)
if RUBY_PLATFORM =~ /mingw|mswin/ then
RUBY_VERSION =~ /(\d+\.\d+)/
ext.lib_dir = "lib/#{$1}"
elsif ENV['CROSS']
# define cross-compilation tasks when not on Windows.
ext.cross_compile = true
ext.cross_platform = ['i386-mswin32', 'i386-mingw32']
ext.cross_platform = ['i386-mswin32-60', 'i386-mingw32']
ext.cross_compiling do |spec|
# add fat-binary stub only when cross compiling
spec.files << "lib/puma/puma_http11.rb"
end
# cleanup versioned library directory
CLEAN.include 'lib/{1.8,1.9}'
CLEAN.include "lib/puma/{1.8,1.9}"
CLEAN.include "lib/puma/puma_http11.rb"
end
task :ragel => 'ext/puma_http11/http11_parser.c'
# Java (JRuby)
Rake::JavaExtensionTask.new("puma_http11", HOE.spec) do |ext|
ext.lib_dir = "lib/puma"
end
task :ext_clean do
sh "rm -rf lib/puma_http11.bundle"
sh "rm -rf lib/puma_http11.jar"
sh "rm -rf lib/puma_http11.so"
# the following is a fat-binary stub that will be used when
# require 'puma/puma_http11' and will use either 1.8 or 1.9 version depending
# on RUBY_VERSION
file "lib/puma/puma_http11.rb" do |t|
File.open(t.name, "w") do |f|
f.puts "RUBY_VERSION =~ /(\d+.\d+)/"
f.puts 'require "puma/#{$1}/puma_http11"'
end
end
task :clean => :ext_clean
# tests require extension be compiled, but depend on the platform
if IS_JRUBY
task :test => [:java]
else
task :test => [:compile]
end

View file

@ -2,4 +2,4 @@ require 'mkmf'
dir_config("puma_http11")
create_makefile("puma_http11")
create_makefile("puma/puma_http11")

View file

@ -1,4 +1,3 @@
# Standard libraries
require 'socket'
require 'tempfile'

View file

@ -46,7 +46,7 @@ module Puma
@parser.parse! @argv
@state = YAML.load_file(@path)
@state = YAML.load File.read(@path)
@config = @state['config']
cmd = @argv.shift

View file

@ -1,4 +1,3 @@
require 'rubygems'
require 'rack'
require 'stringio'
@ -7,7 +6,7 @@ require 'puma/const'
require 'puma/events'
require 'puma/null_io'
require 'puma_http11'
require 'puma/puma_http11'
require 'socket'

View file

@ -6,8 +6,8 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Evan Phoenix"]
s.date = "2011-12-19"
s.description = "Puma is a small library that provides a very fast and concurrent HTTP 1.1 server for Ruby web applications. It is designed for running rack apps only.\n\nWhat makes Puma so fast is the careful use of an Ragel extension to provide fast, accurate HTTP 1.1 protocol parsing. This makes the server scream without too many portability issues."
s.date = "2012-01-08"
s.description = "Puma is a simple, fast, and highly concurrent HTTP 1.1 server for Ruby web applications. It can be used with any application that supports Rack, and is considered the replacement for Webrick and Mongrel. It was designed to be the go-to server for [Rubinius](http://rubini.us), but also works well with JRuby and MRI. Puma is intended for use in both development and production environments.\n\nUnder the hood, Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way. Puma then serves the request in a thread from an internal thread pool (which you can control). This allows Puma to provide real concurrency for your web application!\n\nWith Rubinius 2.0, Puma will utilize all cores on your CPU with real threads, meaning you won't have to spawn multiple processes to increase throughput. You can expect to see a similar benefit from JRuby.\n\nOn MRI, there is a Global Interpreter Lock (GIL) that ensures only one thread can be run at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing blocking IO to be run concurrently (EventMachine-based servers such as Thin turn off this ability, requiring you to use special libraries). Your mileage may vary.. in order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like [Rubinius](http://rubini.us) or [JRuby](http://jruby.org)."
s.email = ["evan@phx.io"]
s.executables = ["puma", "pumactl"]
s.extensions = ["ext/puma_http11/extconf.rb"]
@ -15,9 +15,10 @@ Gem::Specification.new do |s|
s.files = ["COPYING", "Gemfile", "History.txt", "LICENSE", "Manifest.txt", "README.md", "Rakefile", "TODO", "bin/puma", "bin/pumactl", "examples/config.rb", "ext/puma_http11/PumaHttp11Service.java", "ext/puma_http11/ext_help.h", "ext/puma_http11/extconf.rb", "ext/puma_http11/http11_parser.c", "ext/puma_http11/http11_parser.h", "ext/puma_http11/http11_parser.java.rl", "ext/puma_http11/http11_parser.rl", "ext/puma_http11/http11_parser_common.rl", "ext/puma_http11/org/jruby/puma/Http11.java", "ext/puma_http11/org/jruby/puma/Http11Parser.java", "ext/puma_http11/puma_http11.c", "lib/puma.rb", "lib/puma/app/status.rb", "lib/puma/cli.rb", "lib/puma/configuration.rb", "lib/puma/const.rb", "lib/puma/control_cli.rb", "lib/puma/events.rb", "lib/puma/jruby_restart.rb", "lib/puma/null_io.rb", "lib/puma/rack_patch.rb", "lib/puma/server.rb", "lib/puma/thread_pool.rb", "lib/rack/handler/puma.rb", "puma.gemspec", "test/ab_rs.rb", "test/config/app.rb", "test/hello.ru", "test/lobster.ru", "test/mime.yaml", "test/slow.ru", "test/test_app_status.rb", "test/test_cli.rb", "test/test_config.rb", "test/test_http10.rb", "test/test_http11.rb", "test/test_integration.rb", "test/test_persistent.rb", "test/test_rack_handler.rb", "test/test_rack_server.rb", "test/test_thread_pool.rb", "test/test_unix_socket.rb", "test/test_ws.rb", "test/testhelp.rb", "tools/trickletest.rb"]
s.rdoc_options = ["--main", "README.md"]
s.require_paths = ["lib"]
s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
s.rubyforge_project = "puma"
s.rubygems_version = "1.8.12"
s.summary = "Puma is a small library that provides a very fast and concurrent HTTP 1.1 server for Ruby web applications"
s.rubygems_version = "1.8.15"
s.summary = "Puma is a simple, fast, and highly concurrent HTTP 1.1 server for Ruby web applications"
s.test_files = ["test/test_app_status.rb", "test/test_cli.rb", "test/test_config.rb", "test/test_http10.rb", "test/test_http11.rb", "test/test_integration.rb", "test/test_persistent.rb", "test/test_rack_handler.rb", "test/test_rack_server.rb", "test/test_thread_pool.rb", "test/test_unix_socket.rb", "test/test_ws.rb"]
if s.respond_to? :specification_version then
@ -25,19 +26,19 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rack>, ["~> 1.2"])
s.add_development_dependency(%q<rake-compiler>, ["~> 0.7.0"])
s.add_development_dependency(%q<hoe>, ["~> 2.12"])
s.add_development_dependency(%q<rake-compiler>, ["~> 0.8.0"])
s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
s.add_development_dependency(%q<hoe>, ["~> 2.12"])
else
s.add_dependency(%q<rack>, ["~> 1.2"])
s.add_dependency(%q<rake-compiler>, ["~> 0.7.0"])
s.add_dependency(%q<hoe>, ["~> 2.12"])
s.add_dependency(%q<rake-compiler>, ["~> 0.8.0"])
s.add_dependency(%q<rdoc>, ["~> 3.10"])
s.add_dependency(%q<hoe>, ["~> 2.12"])
end
else
s.add_dependency(%q<rack>, ["~> 1.2"])
s.add_dependency(%q<rake-compiler>, ["~> 0.7.0"])
s.add_dependency(%q<hoe>, ["~> 2.12"])
s.add_dependency(%q<rake-compiler>, ["~> 0.8.0"])
s.add_dependency(%q<rdoc>, ["~> 3.10"])
s.add_dependency(%q<hoe>, ["~> 2.12"])
end
end

View file

@ -1 +1 @@
run lambda { |env| [200, {}, ["Hello World"]] }
run lambda { |env| [200, {"Content-Type" => "text/plain"}, ["Hello World"]] }

View file

@ -1,3 +1,4 @@
require "rbconfig"
require 'test/unit'
require 'puma/cli'
require 'tempfile'
@ -27,7 +28,7 @@ class TestCLI < Test::Unit::TestCase
assert_equal File.read(@tmp_path).strip.to_i, Process.pid
end
unless defined? JRUBY_VERSION
unless defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
def test_control
url = "unix://#{@tmp_path}"
@ -85,7 +86,7 @@ class TestCLI < Test::Unit::TestCase
cli.parse_options
cli.write_state
data = YAML.load_file(@tmp_path)
data = YAML.load File.read(@tmp_path)
assert_equal Process.pid, data["pid"]
@ -95,7 +96,7 @@ class TestCLI < Test::Unit::TestCase
assert m, "'#{url}' is not a URL"
end
end
end # JRUBY or Windows
def test_state
url = "tcp://127.0.0.1:8232"
@ -103,7 +104,7 @@ class TestCLI < Test::Unit::TestCase
cli.parse_options
cli.write_state
data = YAML.load_file(@tmp_path)
data = YAML.load File.read(@tmp_path)
assert_equal Process.pid, data["pid"]
assert_equal url, data["config"].options[:control_url]

View file

@ -1,5 +1,5 @@
require "rbconfig"
require 'test/unit'
require 'rubygems'
require 'socket'
require 'puma/cli'
@ -19,7 +19,7 @@ class TestIntegration < Test::Unit::TestCase
end
def test_stop_via_pumactl
if defined? JRUBY_VERSION
if defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
assert true
return
end

View file

@ -1,10 +1,12 @@
require "rbconfig"
require 'test/unit'
require 'puma/server'
require 'socket'
# UNIX sockets are not recommended on JRuby
unless defined?(JRUBY_VERSION)
# (or Windows)
unless defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
class TestPumaUnixSocket < Test::Unit::TestCase
App = lambda { |env| [200, {}, ["Works"]] }

View file

@ -2,8 +2,9 @@
# Copyright (c) 2005 Zed A. Shaw
%w(lib ext bin test).each do |dir|
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
%w(lib test).each do |d|
dir = File.expand_path("../../#{d}", __FILE__)
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
end
require 'rubygems'