http: raise empty backtrace for HttpParserError
[unicorn.git] / GNUmakefile
blobcee604214690a82a05564964e6467505182a1287
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all:: test
4 GIT_URL = git://git.bogomips.org/unicorn.git
5 RLFLAGS = -G2
7 MRI = ruby
8 RUBY = ruby
9 RAKE = rake
10 RAGEL = ragel
11 RSYNC = rsync
13 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
14 @./GIT-VERSION-GEN
15 -include GIT-VERSION-FILE
16 -include local.mk
17 ruby_bin := $(shell which $(RUBY))
18 ifeq ($(DLEXT),) # "so" for Linux
19 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
20 endif
21 ifeq ($(RUBY_VERSION),)
22 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
23 endif
25 RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
27 isolate_libs := tmp/isolate/.$(RUBY_ENGINE)-$(RUBY_VERSION).libs
28 MYLIBS = $(RUBYLIB):$(shell cat $(isolate_libs) 2>/dev/null || \
29 (test -f $(isolate_libs) && \
30 $(RUBY) ./script/isolate_for_tests >/dev/null && \
31 cat $(isolate_libs) 2>/dev/null))
33 echo:
34 @echo $(MYLIBS)
36 # dunno how to implement this as concisely in Ruby, and hell, I love awk
37 awk_slow := awk '/def test_/{print FILENAME"--"$$2".n"}' 2>/dev/null
39 rails_vers := $(subst test/rails/app-,,$(wildcard test/rails/app-*))
40 slow_tests := test/unit/test_server.rb test/exec/test_exec.rb \
41 test/unit/test_signals.rb test/unit/test_upload.rb
42 log_suffix = .$(RUBY_ENGINE).$(RUBY_VERSION).log
43 T_r := $(wildcard test/rails/test*.rb)
44 T := $(filter-out $(slow_tests) $(T_r), $(wildcard test/*/test*.rb))
45 T_n := $(shell $(awk_slow) $(slow_tests))
46 T_log := $(subst .rb,$(log_suffix),$(T))
47 T_n_log := $(subst .n,$(log_suffix),$(T_n))
48 T_r_log := $(subst .r,$(log_suffix),$(T_r))
49 test_prefix = $(CURDIR)/test/$(RUBY_ENGINE)-$(RUBY_VERSION)
51 ext := ext/unicorn_http
52 c_files := $(ext)/unicorn_http.c $(wildcard $(ext)/*.h)
53 rl_files := $(wildcard $(ext)/*.rl)
54 base_bins := unicorn unicorn_rails
55 bins := $(addprefix bin/, $(base_bins))
56 man1_rdoc := $(addsuffix _1, $(base_bins))
57 man1_bins := $(addsuffix .1, $(base_bins))
58 man1_paths := $(addprefix man/man1/, $(man1_bins))
59 rb_files := $(bins) $(shell find lib ext -type f -name '*.rb')
60 inst_deps := $(c_files) $(rb_files) GNUmakefile test/test_helper.rb
62 ragel: $(ext)/unicorn_http.c
63 $(ext)/unicorn_http.c: $(rl_files)
64 cd $(@D) && $(RAGEL) unicorn_http.rl -C $(RLFLAGS) -o $(@F)
65 $(ext)/Makefile: $(ext)/extconf.rb $(c_files)
66 cd $(@D) && $(RUBY) extconf.rb
67 $(ext)/unicorn_http.$(DLEXT): $(ext)/Makefile
68 $(MAKE) -C $(@D)
69 lib/unicorn_http.$(DLEXT): $(ext)/unicorn_http.$(DLEXT)
70 @mkdir -p lib
71 install -m644 $< $@
72 http: lib/unicorn_http.$(DLEXT)
74 test-install: $(test_prefix)/.stamp
75 $(test_prefix)/.stamp: $(inst_deps)
76 mkdir -p $(test_prefix)/.ccache
77 tar cf - $(inst_deps) GIT-VERSION-GEN | \
78 (cd $(test_prefix) && tar xf -)
79 $(MAKE) -C $(test_prefix) clean
80 $(MAKE) -C $(test_prefix) http shebang RUBY="$(RUBY)"
81 > $@
83 # this is only intended to be run within $(test_prefix)
84 shebang: $(bins)
85 $(MRI) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
87 t_log := $(T_log) $(T_n_log)
88 test: $(T) $(T_n)
89 @cat $(t_log) | $(MRI) test/aggregate.rb
90 @$(RM) $(t_log)
92 test-exec: $(wildcard test/exec/test_*.rb)
93 test-unit: $(wildcard test/unit/test_*.rb)
94 $(slow_tests): $(test_prefix)/.stamp
95 @$(MAKE) $(shell $(awk_slow) $@)
97 test-integration: $(test_prefix)/.stamp
98 $(MAKE) -C t
100 test-all: test test-rails test-integration
102 TEST_OPTS = -v
103 check_test = grep '0 failures, 0 errors' $(t) >/dev/null
104 ifndef V
105 quiet_pre = @echo '* $(arg)$(extra)';
106 quiet_post = >$(t) 2>&1 && $(check_test)
107 else
108 # we can't rely on -o pipefail outside of bash 3+,
109 # so we use a stamp file to indicate success and
110 # have rm fail if the stamp didn't get created
111 stamp = $@$(log_suffix).ok
112 quiet_pre = @echo $(RUBY) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
113 quiet_post = && > $(stamp) )2>&1 | tee $(t); \
114 rm $(stamp) 2>/dev/null && $(check_test)
115 endif
117 # not all systems have setsid(8), we need it because we spam signals
118 # stupidly in some tests...
119 rb_setsid := $(RUBY) -e 'Process.setsid' -e 'exec *ARGV'
121 # TRACER='strace -f -o $(t).strace -s 100000'
122 run_test = $(quiet_pre) \
123 $(rb_setsid) $(TRACER) $(RUBY) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
124 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
126 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
127 %.n: t = $(subst .n,$(log_suffix),$@)
128 %.n: export PATH := $(test_prefix)/bin:$(PATH)
129 %.n: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(MYLIBS)
130 %.n: $(test_prefix)/.stamp
131 $(run_test)
133 $(T): arg = $@
134 $(T): t = $(subst .rb,$(log_suffix),$@)
135 $(T): export PATH := $(test_prefix)/bin:$(PATH)
136 $(T): export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(MYLIBS)
137 $(T): $(test_prefix)/.stamp
138 $(run_test)
140 install: $(bins) $(ext)/unicorn_http.c
141 $(prep_setup_rb)
142 $(RM) lib/unicorn_http.$(DLEXT)
143 $(RM) -r .install-tmp
144 mkdir .install-tmp
145 cp -p bin/* .install-tmp
146 $(RUBY) setup.rb all
147 $(RM) $^
148 mv .install-tmp/* bin/
149 $(RM) -r .install-tmp
150 $(prep_setup_rb)
152 setup_rb_files := .config InstalledFiles
153 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
155 clean:
156 -$(MAKE) -C $(ext) clean
157 -$(MAKE) -C Documentation clean
158 $(RM) $(ext)/Makefile lib/unicorn_http.$(DLEXT)
159 $(RM) $(setup_rb_files) $(t_log)
160 $(RM) -r $(test_prefix) man
162 man:
163 $(MAKE) -C Documentation install-man
165 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog $(ext)/unicorn_http.c
166 manifest: $(pkg_extra) man
167 $(RM) .manifest
168 $(MAKE) .manifest
170 .manifest:
171 (git ls-files && \
172 for i in $@ $(pkg_extra) $(man1_paths); \
173 do echo $$i; done) | LC_ALL=C sort > $@+
174 cmp $@+ $@ || mv $@+ $@
175 $(RM) $@+
177 NEWS: GIT-VERSION-FILE .manifest
178 $(RAKE) -s news_rdoc > $@+
179 mv $@+ $@
181 SINCE = 0.991.0
182 ChangeLog: LOG_VERSION = \
183 $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
184 echo $(GIT_VERSION) || git describe)
185 ChangeLog: log_range = v$(SINCE)..$(LOG_VERSION)
186 ChangeLog: GIT-VERSION-FILE
187 @echo "ChangeLog from $(GIT_URL) ($(log_range))" > $@+
188 @echo >> $@+
189 git log $(log_range) | sed -e 's/^/ /' >> $@+
190 mv $@+ $@
192 news_atom := http://unicorn.bogomips.org/NEWS.atom.xml
193 cgit_atom := http://git.bogomips.org/cgit/unicorn.git/atom/?h=master
194 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
195 type="application/atom+xml"/>
197 # using rdoc 2.5.x+
198 doc: .document $(ext)/unicorn_http.c NEWS ChangeLog
199 for i in $(man1_rdoc); do echo > $$i; done
200 find bin lib -type f -name '*.rbc' -exec rm -f '{}' ';'
201 rdoc -a -t "$(shell sed -ne '1s/^= //p' README)"
202 install -m644 COPYING doc/COPYING
203 install -m644 $(shell grep '^[A-Z]' .document) doc/
204 $(MAKE) -C Documentation install-html install-man
205 install -m644 $(man1_paths) doc/
206 cd doc && for i in $(base_bins); do \
207 $(RM) 1.html $${i}.1.html; \
208 sed -e '/"documentation">/r man1/'$$i'.1.html' \
209 < $${i}_1.html > tmp && mv tmp $${i}_1.html; \
210 ln $${i}_1.html $${i}.1.html; \
211 done
212 $(RUBY) -i -p -e \
213 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
214 doc/ChangeLog.html
215 $(RUBY) -i -p -e \
216 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
217 doc/NEWS.html doc/README.html
218 $(RAKE) -s news_atom > doc/NEWS.atom.xml
219 cd doc && ln README.html tmp && mv tmp index.html
220 $(RM) $(man1_rdoc)
222 # publishes docs to http://unicorn.bogomips.org
223 publish_doc:
224 -git set-file-times
225 $(RM) -r doc ChangeLog NEWS
226 $(MAKE) doc LOG_VERSION=$(shell git tag -l | tail -1)
227 @awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' \
228 < NEWS > doc/LATEST
229 find doc/images doc/js -type f | \
230 TZ=UTC xargs touch -d '1970-01-01 00:00:00' doc/rdoc.css
231 $(MAKE) doc_gz
232 tar cf - $$(git ls-files examples/) | (cd doc && tar xf -)
233 chmod 644 $$(find doc -type f)
234 $(RSYNC) -av doc/ unicorn.bogomips.org:/srv/unicorn/
235 git ls-files | xargs touch
237 # Create gzip variants of the same timestamp as the original so nginx
238 # "gzip_static on" can serve the gzipped versions directly.
239 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
240 doc_gz:
241 touch doc/NEWS.atom.xml -d "$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
242 for i in $(docs); do \
243 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
245 rails_git_url = git://github.com/rails/rails.git
246 rails_git := vendor/rails.git
247 $(rails_git)/info/cloned-stamp:
248 git clone --mirror -q $(rails_git_url) $(rails_git)
249 > $@
251 $(rails_git)/info/v2.3.8-stamp: $(rails_git)/info/cloned-stamp
252 cd $(rails_git) && git fetch
253 cd $(rails_git) && git rev-parse --verify refs/tags/v2.3.8
254 > $@
256 rails_tests := $(addsuffix .r,$(addprefix $(T_r).,$(rails_vers)))
257 test-rails: $(rails_tests)
258 $(T_r).%.r: t = $(addsuffix $(log_suffix),$@)
259 $(T_r).%.r: rv = $(subst .r,,$(subst $(T_r).,,$@))
260 $(T_r).%.r: extra = ' 'v$(rv)
261 $(T_r).%.r: arg = $(T_r)
262 $(T_r).%.r: export PATH := $(test_prefix)/bin:$(PATH)
263 $(T_r).%.r: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(MYLIBS)
264 $(T_r).%.r: export UNICORN_RAILS_TEST_VERSION = $(rv)
265 $(T_r).%.r: export RAILS_GIT_REPO = $(CURDIR)/$(rails_git)
266 $(T_r).%.r: $(test_prefix)/.stamp $(rails_git)/info/v2.3.8-stamp
267 $(run_test)
269 ifneq ($(VERSION),)
270 rfproject := mongrel
271 rfpackage := unicorn
272 pkggem := pkg/$(rfpackage)-$(VERSION).gem
273 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
274 release_notes := release_notes-$(VERSION)
275 release_changes := release_changes-$(VERSION)
277 release-notes: $(release_notes)
278 release-changes: $(release_changes)
279 $(release_changes):
280 $(RAKE) -s release_changes > $@+
281 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
282 $(release_notes):
283 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
284 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
286 # ensures we're actually on the tagged $(VERSION), only used for release
287 verify:
288 test x"$(shell umask)" = x0022
289 git rev-parse --verify refs/tags/v$(VERSION)^{}
290 git diff-index --quiet HEAD^0
291 test `git rev-parse --verify HEAD^0` = \
292 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
294 fix-perms:
295 git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
296 git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
298 gem: $(pkggem)
300 install-gem: $(pkggem)
301 gem install $(CURDIR)/$<
303 $(pkggem): manifest fix-perms
304 gem build $(rfpackage).gemspec
305 mkdir -p pkg
306 mv $(@F) $@
308 $(pkgtgz): distdir = $(basename $@)
309 $(pkgtgz): HEAD = v$(VERSION)
310 $(pkgtgz): manifest fix-perms
311 @test -n "$(distdir)"
312 $(RM) -r $(distdir)
313 mkdir -p $(distdir)
314 tar cf - `cat .manifest` | (cd $(distdir) && tar xf -)
315 cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
316 mv $@+ $@
318 package: $(pkgtgz) $(pkggem)
320 release: verify package $(release_notes) $(release_changes)
321 # make tgz release on RubyForge
322 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
323 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
324 # push gem to Gemcutter
325 gem push $(pkggem)
326 # in case of gem downloads from RubyForge releases page
327 -rubyforge add_file \
328 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
329 $(RAKE) raa_update VERSION=$(VERSION)
330 $(RAKE) fm_update VERSION=$(VERSION)
331 else
332 gem install-gem: GIT-VERSION-FILE
333 $(MAKE) $@ VERSION=$(GIT_VERSION)
334 endif
336 .PHONY: .FORCE-GIT-VERSION-FILE doc $(T) $(slow_tests) manifest man
337 .PHONY: test-install