wendell-puma 2.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +55 -0
  3. data/DEPLOYMENT.md +92 -0
  4. data/Gemfile +17 -0
  5. data/History.txt +588 -0
  6. data/LICENSE +26 -0
  7. data/Manifest.txt +68 -0
  8. data/README.md +251 -0
  9. data/Rakefile +158 -0
  10. data/bin/puma +10 -0
  11. data/bin/puma-wild +31 -0
  12. data/bin/pumactl +12 -0
  13. data/docs/config.md +0 -0
  14. data/docs/nginx.md +80 -0
  15. data/docs/signals.md +43 -0
  16. data/ext/puma_http11/PumaHttp11Service.java +17 -0
  17. data/ext/puma_http11/ext_help.h +15 -0
  18. data/ext/puma_http11/extconf.rb +9 -0
  19. data/ext/puma_http11/http11_parser.c +1225 -0
  20. data/ext/puma_http11/http11_parser.h +64 -0
  21. data/ext/puma_http11/http11_parser.java.rl +161 -0
  22. data/ext/puma_http11/http11_parser.rl +146 -0
  23. data/ext/puma_http11/http11_parser_common.rl +54 -0
  24. data/ext/puma_http11/io_buffer.c +155 -0
  25. data/ext/puma_http11/mini_ssl.c +198 -0
  26. data/ext/puma_http11/org/jruby/puma/Http11.java +225 -0
  27. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +488 -0
  28. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +391 -0
  29. data/ext/puma_http11/puma_http11.c +491 -0
  30. data/lib/puma.rb +14 -0
  31. data/lib/puma/accept_nonblock.rb +23 -0
  32. data/lib/puma/app/status.rb +59 -0
  33. data/lib/puma/binder.rb +298 -0
  34. data/lib/puma/capistrano.rb +86 -0
  35. data/lib/puma/cli.rb +606 -0
  36. data/lib/puma/client.rb +289 -0
  37. data/lib/puma/cluster.rb +404 -0
  38. data/lib/puma/compat.rb +18 -0
  39. data/lib/puma/configuration.rb +377 -0
  40. data/lib/puma/const.rb +165 -0
  41. data/lib/puma/control_cli.rb +251 -0
  42. data/lib/puma/daemon_ext.rb +25 -0
  43. data/lib/puma/delegation.rb +11 -0
  44. data/lib/puma/detect.rb +4 -0
  45. data/lib/puma/events.rb +130 -0
  46. data/lib/puma/io_buffer.rb +7 -0
  47. data/lib/puma/java_io_buffer.rb +45 -0
  48. data/lib/puma/jruby_restart.rb +83 -0
  49. data/lib/puma/minissl.rb +187 -0
  50. data/lib/puma/null_io.rb +34 -0
  51. data/lib/puma/rack_default.rb +7 -0
  52. data/lib/puma/rack_patch.rb +45 -0
  53. data/lib/puma/reactor.rb +183 -0
  54. data/lib/puma/runner.rb +146 -0
  55. data/lib/puma/server.rb +801 -0
  56. data/lib/puma/single.rb +102 -0
  57. data/lib/puma/tcp_logger.rb +32 -0
  58. data/lib/puma/thread_pool.rb +185 -0
  59. data/lib/puma/util.rb +9 -0
  60. data/lib/rack/handler/puma.rb +66 -0
  61. data/test/test_app_status.rb +92 -0
  62. data/test/test_cli.rb +173 -0
  63. data/test/test_config.rb +26 -0
  64. data/test/test_http10.rb +27 -0
  65. data/test/test_http11.rb +144 -0
  66. data/test/test_integration.rb +165 -0
  67. data/test/test_iobuffer.rb +38 -0
  68. data/test/test_minissl.rb +29 -0
  69. data/test/test_null_io.rb +31 -0
  70. data/test/test_persistent.rb +238 -0
  71. data/test/test_puma_server.rb +288 -0
  72. data/test/test_puma_server_ssl.rb +137 -0
  73. data/test/test_rack_handler.rb +10 -0
  74. data/test/test_rack_server.rb +141 -0
  75. data/test/test_tcp_rack.rb +42 -0
  76. data/test/test_thread_pool.rb +156 -0
  77. data/test/test_unix_socket.rb +39 -0
  78. data/test/test_ws.rb +89 -0
  79. data/tools/jungle/README.md +9 -0
  80. data/tools/jungle/init.d/README.md +54 -0
  81. data/tools/jungle/init.d/puma +332 -0
  82. data/tools/jungle/init.d/run-puma +3 -0
  83. data/tools/jungle/upstart/README.md +61 -0
  84. data/tools/jungle/upstart/puma-manager.conf +31 -0
  85. data/tools/jungle/upstart/puma.conf +63 -0
  86. data/tools/trickletest.rb +45 -0
  87. data/wendell-puma.gemspec +55 -0
  88. metadata +225 -0
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Some code copyright (c) 2005, Zed Shaw
2
+ Copyright (c) 2011, Evan Phoenix
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above copyright notice
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+ * Neither the name of the Evan Phoenix nor the names of its contributors
14
+ may be used to endorse or promote products derived from this software
15
+ without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,68 @@
1
+ COPYING
2
+ DEPLOYMENT.md
3
+ Gemfile
4
+ History.txt
5
+ LICENSE
6
+ Manifest.txt
7
+ README.md
8
+ Rakefile
9
+ bin/puma
10
+ bin/puma-wild
11
+ bin/pumactl
12
+ docs/config.md
13
+ docs/nginx.md
14
+ docs/signals.md
15
+ ext/puma_http11/PumaHttp11Service.java
16
+ ext/puma_http11/ext_help.h
17
+ ext/puma_http11/extconf.rb
18
+ ext/puma_http11/http11_parser.c
19
+ ext/puma_http11/http11_parser.h
20
+ ext/puma_http11/http11_parser.java.rl
21
+ ext/puma_http11/http11_parser.rl
22
+ ext/puma_http11/http11_parser_common.rl
23
+ ext/puma_http11/io_buffer.c
24
+ ext/puma_http11/mini_ssl.c
25
+ ext/puma_http11/org/jruby/puma/Http11.java
26
+ ext/puma_http11/org/jruby/puma/Http11Parser.java
27
+ ext/puma_http11/org/jruby/puma/MiniSSL.java
28
+ ext/puma_http11/puma_http11.c
29
+ lib/puma.rb
30
+ lib/puma/accept_nonblock.rb
31
+ lib/puma/app/status.rb
32
+ lib/puma/binder.rb
33
+ lib/puma/capistrano.rb
34
+ lib/puma/cli.rb
35
+ lib/puma/client.rb
36
+ lib/puma/cluster.rb
37
+ lib/puma/compat.rb
38
+ lib/puma/configuration.rb
39
+ lib/puma/const.rb
40
+ lib/puma/control_cli.rb
41
+ lib/puma/daemon_ext.rb
42
+ lib/puma/delegation.rb
43
+ lib/puma/detect.rb
44
+ lib/puma/events.rb
45
+ lib/puma/io_buffer.rb
46
+ lib/puma/java_io_buffer.rb
47
+ lib/puma/jruby_restart.rb
48
+ lib/puma/minissl.rb
49
+ lib/puma/null_io.rb
50
+ lib/puma/rack_default.rb
51
+ lib/puma/rack_patch.rb
52
+ lib/puma/reactor.rb
53
+ lib/puma/runner.rb
54
+ lib/puma/server.rb
55
+ lib/puma/single.rb
56
+ lib/puma/tcp_logger.rb
57
+ lib/puma/thread_pool.rb
58
+ lib/puma/util.rb
59
+ lib/rack/handler/puma.rb
60
+ wendell-puma.gemspec
61
+ tools/jungle/README.md
62
+ tools/jungle/init.d/README.md
63
+ tools/jungle/init.d/puma
64
+ tools/jungle/init.d/run-puma
65
+ tools/jungle/upstart/README.md
66
+ tools/jungle/upstart/puma-manager.conf
67
+ tools/jungle/upstart/puma.conf
68
+ tools/trickletest.rb
@@ -0,0 +1,251 @@
1
+ # Puma: A Ruby Web Server Built For Concurrency
2
+
3
+ [![Build Status](https://secure.travis-ci.org/puma/puma.png)](http://travis-ci.org/puma/puma) [![Dependency Status](https://gemnasium.com/puma/puma.png)](https://gemnasium.com/puma/puma) <a href="https://codeclimate.com/github/puma/puma"><img src="https://codeclimate.com/github/puma/puma.png" /></a>
4
+
5
+ ## Description
6
+
7
+ Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications. Puma is intended for use in both development and production environments. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like Rubinius or JRuby.
8
+
9
+ ## Built For Speed &amp; Concurrency
10
+
11
+ 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.
12
+
13
+ Under 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!
14
+
15
+ With 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.
16
+
17
+ On 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).
18
+
19
+ ## Quick Start
20
+
21
+ The easiest way to get started with Puma is to install it via RubyGems. You can do this easily:
22
+
23
+ $ gem install puma
24
+
25
+ Now you should have the `puma` command available in your PATH, so just do the following in the root folder of your Rack application:
26
+
27
+ $ puma app.ru
28
+
29
+ ## Advanced Setup
30
+
31
+ ### Sinatra
32
+
33
+ You can run your Sinatra application with Puma from the command line like this:
34
+
35
+ $ ruby app.rb -s Puma
36
+
37
+ Or you can configure your application to always use Puma:
38
+
39
+ require 'sinatra'
40
+ configure { set :server, :puma }
41
+
42
+ If you use Bundler, make sure you add Puma to your Gemfile (see below).
43
+
44
+ ### Rails
45
+
46
+ First, make sure Puma is in your Gemfile:
47
+
48
+ gem 'puma'
49
+
50
+ Then start your server with the `rails` command:
51
+
52
+ $ rails s Puma
53
+
54
+ ### Rackup
55
+
56
+ You can pass it as an option to `rackup`:
57
+
58
+ $ rackup -s Puma
59
+
60
+ Alternatively, you can modify your `config.ru` to choose Puma by default, by adding the following as the first line:
61
+
62
+ #\ -s puma
63
+
64
+ ## Configuration
65
+
66
+ Puma provides numerous options for controlling the operation of the server. Consult `puma -h` (or `puma --help`) for a full list.
67
+
68
+ ### Thread Pool
69
+
70
+ Puma utilizes a dynamic thread pool which you can modify. You can set the minimum and maximum number of threads that are available in the pool with the `-t` (or `--threads`) flag:
71
+
72
+ $ puma -t 8:32
73
+
74
+ Puma will automatically scale the number of threads based on how much traffic is present. The current default is `0:16`. Feel free to experiment, but be careful not to set the number of maximum threads to a very large number, as you may exhaust resources on the system (or hit resource limits).
75
+
76
+ ### Clustered mode
77
+
78
+ Puma 2 offers clustered mode, allowing you to use forked processes to handle multiple incoming requests concurrently, in addition to threads already provided. You can tune the number of workers with the `-w` (or `--workers`) flag:
79
+
80
+ $ puma -t 8:32 -w 3
81
+
82
+ On a ruby implementation that offers native threads, you should tune this number to match the number of cores available.
83
+ Note that threads are still used in clustered mode, and the `-t` thread flag setting is per worker, so `-w 2 -t 16:16` will be 32 threads.
84
+
85
+ If you're running in Clustered Mode you can optionally choose to preload your application before starting up the workers. This is necessary in order to take advantage of the [Copy on Write](http://en.wikipedia.org/wiki/Copy-on-write) feature introduced in [MRI Ruby 2.0](https://blog.heroku.com/archives/2013/3/6/matz_highlights_ruby_2_0_at_waza). To do this simply specify the `--preload` flag in invocation:
86
+
87
+ # CLI invocation
88
+ $ puma -t 8:32 -w 3 --preload
89
+
90
+ If you're using a configuration file, use the `preload_app!` method, and be sure to specify your config file's location with the `-C` flag:
91
+
92
+ $ puma -C config/puma.rb
93
+
94
+ # config/puma.rb
95
+ threads 8,32
96
+ workers 3
97
+ preload_app!
98
+
99
+ Additionally, you can specify a block in your configuration file that will be run on boot of each worker:
100
+
101
+ # config/puma.rb
102
+ on_worker_boot do
103
+ # configuration here
104
+ end
105
+
106
+ This code can be used to setup the process before booting the application, allowing
107
+ you to do some Puma-specific things that you don't want to embed in your application.
108
+ For instance, you could fire a log notification that a worker booted or send something to statsd.
109
+ This can be called multiple times to add hooks.
110
+
111
+ If you're preloading your application and using ActiveRecord, it's recommend you setup your connection pool here:
112
+
113
+ # config/puma.rb
114
+ on_worker_boot do
115
+ ActiveSupport.on_load(:active_record) do
116
+ ActiveRecord::Base.establish_connection
117
+ end
118
+ end
119
+
120
+ When you use preload_app, your new code goes all in the master process, and is then copied in the workers (meaning it’s only compatible with cluster mode). General rule is to use preload_app when your workers die often and need fast starts. If you don’t have many workers, you probably should not use preload_app.
121
+
122
+ Note that preload_app can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preload_app is all about copying the code of master into the workers.
123
+
124
+ ### Binding TCP / Sockets
125
+
126
+ In contrast to many other server configs which require multiple flags, Puma simply uses one URI parameter with the `-b` (or `--bind`) flag:
127
+
128
+ $ puma -b tcp://127.0.0.1:9292
129
+
130
+ Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance boost)? No problem!
131
+
132
+ $ puma -b unix:///var/run/puma.sock
133
+
134
+ If you need to change the permissions of the UNIX socket, just add a umask parameter:
135
+
136
+ $ puma -b 'unix:///var/run/puma.sock?umask=0777'
137
+
138
+ Need a bit of security? Use SSL sockets!
139
+
140
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
141
+
142
+ ### Control/Status Server
143
+
144
+ Puma comes with a builtin status/control app that can be used query and control Puma itself. Here is an example of starting Puma with the control server:
145
+
146
+ $ puma --control tcp://127.0.0.1:9293 --control-token foo
147
+
148
+ This directs Puma to start the control server on localhost port 9293. Additionally, all requests to the control server will need to include `token=foo` as a query parameter. This allows for simple authentication. Check out [status.rb](https://github.com/puma/puma/blob/master/lib/puma/app/status.rb) to see what the app has available.
149
+
150
+ ### Configuration file
151
+
152
+ You can also provide a configuration file which Puma will use with the `-C` (or `--config`) flag:
153
+
154
+ $ puma -C /path/to/config
155
+
156
+ By default, if no configuration file is specifed, Puma will look for a configuration file at config/puma.rb. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` environment variable, the default file location will be config/puma/environment_name.rb.
157
+
158
+ If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag:
159
+
160
+ $ puma -C "-"
161
+
162
+ Take the following [sample configuration](https://github.com/puma/puma/blob/master/examples/config.rb) as inspiration or check out [configuration.rb](https://github.com/puma/puma/blob/master/lib/puma/configuration.rb) to see all available options.
163
+
164
+ ## Restart
165
+
166
+ Puma includes the ability to restart itself allowing easy upgrades to new versions. When available (MRI, Rubinius, JRuby), Puma performs a "hot restart". This is the same functionality available in *unicorn* and *nginx* which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.
167
+
168
+ To perform a restart, there are 2 builtin mechanisms:
169
+
170
+ * Send the `puma` process the `SIGUSR2` signal
171
+ * Use the status server and issue `/restart`
172
+
173
+ No code is shared between the current and restarted process, so it should be safe to issue a restart any place where you would manually stop Puma and start it again.
174
+
175
+ If the new process is unable to load, it will simply exit. You should therefore run Puma under a supervisor when using it in production.
176
+
177
+ ### Normal vs Hot vs Phased Restart
178
+
179
+ A hot restart means that no requests while deploying your new code will be lost, since the server socket is kept open between restarts.
180
+
181
+ But beware, hot restart does not mean that the incoming requests won’t hang for multiple seconds while your new code has not fully deployed. If you need a zero downtime and zero hanging requests deploy, you must use phased restart.
182
+
183
+ When you run pumactl phased-restart, Puma kills workers one-by-one, meaning that at least another worker is still available to serve requests, which lead in zero hanging request (yay!).
184
+
185
+ But again beware, upgrading an application sometimes involves upgrading the database schema. With phased restart, there may be a moment during the deployment where processes belonging to the previous version and processes belonging to the new version both exist at the same time. Any database schema upgrades you perform must therefore be backwards-compatible with the old application version.
186
+
187
+ if you perform a lot of database migrations, you probably should not use phased restart and use a normal/hot restart instead (pumactl restart). That way, no code is shared while deploying (in that case, preload_app might help for quicker deployment, see below).
188
+
189
+
190
+ ### Cleanup Code
191
+
192
+ Puma isn't able to understand all the resources that your app may use, so it provides a hook in the configuration file you pass to `-C` called `on_restart`. The block passed to `on_restart` will be called, unsurprisingly, just before Puma restarts itself.
193
+
194
+ You should place code to close global log files, redis connections, etc in this block so that their file descriptors don't leak into the restarted process. Failure to do so will result in slowly running out of descriptors and eventually obscure crashes as the server is restart many times.
195
+
196
+ ### Platform Constraints
197
+
198
+ Because of various platforms not being implement certain things, the following differences occur when Puma is used on different platforms:
199
+
200
+ * **JRuby**, **Windows**: server sockets are not seamless on restart, they must be closed and reopened. These platforms have no way to pass descriptors into a new process that is exposed to ruby
201
+ * **JRuby**, **Windows**: cluster mode is not supported due to a lack of fork(2)
202
+ * **Windows**: daemon mode is not supported due to a lack of fork(2)
203
+
204
+ ## pumactl
205
+
206
+ `pumactl` is a simple CLI frontend to the control/status app described above. Please refer to `pumactl --help` for available commands.
207
+
208
+ ## Managing multiple Pumas / init.d / upstart scripts
209
+
210
+ If you want an easy way to manage multiple scripts at once check [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for init.d and upstart scripts.
211
+
212
+ ## Capistrano deployment
213
+
214
+ Puma has support for Capistrano3 with an [external gem](https://github.com/seuros/capistrano-puma), you just need require that in Gemfile:
215
+
216
+ ```ruby
217
+ gem 'capistrano3-puma'
218
+ ```
219
+ And then execute:
220
+
221
+ ```bash
222
+ bundle
223
+ ```
224
+
225
+ Then add to Capfile
226
+
227
+ ```ruby
228
+ require 'capistrano/puma'
229
+ ```
230
+
231
+ and then
232
+
233
+ ```bash
234
+ $ bundle exec cap puma:start
235
+ $ bundle exec cap puma:restart
236
+ $ bundle exec cap puma:stop
237
+ $ bundle exec cap puma:phased_restart
238
+ ```
239
+
240
+ ## Contributing
241
+
242
+ To run the test suite:
243
+
244
+ ```bash
245
+ $ bundle install
246
+ $ bundle exec rake
247
+ ```
248
+
249
+ ## License
250
+
251
+ Puma is copyright 2014 Evan Phoenix and contributors. It is licensed under the BSD 3-Clause license. See the include LICENSE file for details.
@@ -0,0 +1,158 @@
1
+ require "hoe"
2
+ require "rake/extensiontask"
3
+ require "rake/javaextensiontask"
4
+
5
+ IS_JRUBY = defined?(RUBY_ENGINE) ? RUBY_ENGINE == "jruby" : false
6
+
7
+ Hoe.plugin :git
8
+ Hoe.plugin :ignore
9
+
10
+ HOE = Hoe.spec "wendell-puma" do
11
+ self.readme_file = "README.md"
12
+ self.urls = %w!http://puma.io https://github.com/puma/puma!
13
+
14
+ license "BSD-3-Clause"
15
+ developer 'Evan Phoenix', 'evan@phx.io'
16
+
17
+ spec_extras[:extensions] = ["ext/puma_http11/extconf.rb"]
18
+ spec_extras[:executables] = ['puma', 'pumactl']
19
+ spec_extras[:homepage] = self.urls.first
20
+
21
+ require_ruby_version ">= 1.8.7"
22
+
23
+ dependency "rack", [">= 1.1", "< 2.0"]
24
+
25
+ extra_dev_deps << ["rake-compiler", "~> 0.8"]
26
+ end
27
+
28
+ task :prerelease => [:clobber, :check_manifest, :test]
29
+
30
+ # hoe/test and rake-compiler don't seem to play well together, so disable
31
+ # hoe/test's .gemtest touch file thingy for now
32
+ HOE.spec.files -= [".gemtest"]
33
+
34
+ include Hoe::Git
35
+
36
+ desc "Print the current changelog."
37
+ task "changelog" do
38
+ tag = ENV["FROM"] || git_tags.last
39
+ range = [tag, "HEAD"].compact.join ".."
40
+ cmd = "git log #{range} '--format=tformat:%B|||%aN|||%aE|||'"
41
+ now = Time.new.strftime "%Y-%m-%d"
42
+
43
+ changes = `#{cmd}`.split(/\|\|\|/).each_slice(3).map { |msg, author, email|
44
+ msg.split(/\n/).reject { |s| s.empty? }.first
45
+ }.flatten.compact
46
+
47
+ $changes = Hash.new { |h,k| h[k] = [] }
48
+
49
+ codes = {
50
+ "!" => :major,
51
+ "+" => :minor,
52
+ "*" => :minor,
53
+ "-" => :bug,
54
+ "?" => :unknown,
55
+ }
56
+
57
+ codes_re = Regexp.escape codes.keys.join
58
+
59
+ changes.each do |change|
60
+ if change =~ /^\s*([#{codes_re}])\s*(.*)/ then
61
+ code, line = codes[$1], $2
62
+ else
63
+ code, line = codes["?"], change.chomp
64
+ end
65
+
66
+ $changes[code] << line
67
+ end
68
+
69
+ puts "=== #{ENV['VERSION'] || 'NEXT'} / #{now}"
70
+ puts
71
+ changelog_section :major
72
+ changelog_section :minor
73
+ changelog_section :bug
74
+ changelog_section :unknown
75
+ puts
76
+ end
77
+
78
+ # generate extension code using Ragel (C and Java)
79
+ desc "Generate extension code (C and Java) using Ragel"
80
+ task :ragel
81
+
82
+ file 'ext/puma_http11/http11_parser.c' => ['ext/puma_http11/http11_parser.rl'] do |t|
83
+ begin
84
+ sh "ragel #{t.prerequisites.last} -C -G2 -I ext/puma_http11 -o #{t.name}"
85
+ rescue
86
+ fail "Could not build wrapper using Ragel (it failed or not installed?)"
87
+ end
88
+ end
89
+ task :ragel => ['ext/puma_http11/http11_parser.c']
90
+
91
+ file 'ext/puma_http11/org/jruby/puma/Http11Parser.java' => ['ext/puma_http11/http11_parser.java.rl'] do |t|
92
+ begin
93
+ sh "ragel #{t.prerequisites.last} -J -G2 -I ext/puma_http11 -o #{t.name}"
94
+ rescue
95
+ fail "Could not build wrapper using Ragel (it failed or not installed?)"
96
+ end
97
+ end
98
+ task :ragel => ['ext/puma_http11/org/jruby/puma/Http11Parser.java']
99
+
100
+ if !IS_JRUBY
101
+
102
+ # compile extensions using rake-compiler
103
+ # C (MRI, Rubinius)
104
+ Rake::ExtensionTask.new("puma_http11", HOE.spec) do |ext|
105
+ # place extension inside namespace
106
+ ext.lib_dir = "lib/puma"
107
+
108
+ ext.cross_compile = true
109
+ ext.cross_platform = ['i386-mswin32-60', 'i386-mingw32']
110
+ ext.cross_compiling do |spec|
111
+ # add fat-binary stub only when cross compiling
112
+ spec.files << "lib/puma/puma_http11.rb"
113
+ end
114
+
115
+ CLEAN.include "lib/puma/{1.8,1.9}"
116
+ CLEAN.include "lib/puma/puma_http11.rb"
117
+ end
118
+
119
+ else
120
+
121
+ # Java (JRuby)
122
+ Rake::JavaExtensionTask.new("puma_http11", HOE.spec) do |ext|
123
+ ext.lib_dir = "lib/puma"
124
+ end
125
+
126
+ end
127
+
128
+ # the following is a fat-binary stub that will be used when
129
+ # require 'puma/puma_http11' and will use either 1.8 or 1.9 version depending
130
+ # on RUBY_VERSION
131
+ file "lib/puma/puma_http11.rb" do |t|
132
+ File.open(t.name, "w") do |f|
133
+ f.puts "RUBY_VERSION =~ /(\d+.\d+)/"
134
+ f.puts 'require "puma/#{$1}/puma_http11"'
135
+ end
136
+ end
137
+
138
+ # tests require extension be compiled, but depend on the platform
139
+ if IS_JRUBY
140
+ task :test => [:java]
141
+ else
142
+ task :test => [:compile]
143
+ end
144
+
145
+ namespace :test do
146
+ desc "Run the integration tests"
147
+ task :integration do
148
+ sh "cd test/shell; sh run.sh"
149
+ end
150
+
151
+ desc "Run all tests"
152
+ if defined?(JRUBY_VERSION) and ENV['TRAVIS']
153
+ task :all => :test
154
+ else
155
+ task :all => [:test, "test:integration"]
156
+ end
157
+ end
158
+