test: http_parser_ng: fix broken assertion
[unicorn.git] / GNUmakefile
blob35df2f2d514bbdc3113f865cee49745b203fede6
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 # lower-case vars are deprecated
8 RUBY = ruby
9 RAKE = rake
10 RAGEL = ragel
12 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
13 @./GIT-VERSION-GEN
14 -include GIT-VERSION-FILE
15 -include local.mk
16 ruby_bin := $(shell which $(RUBY))
17 ifeq ($(DLEXT),) # "so" for Linux
18 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
19 endif
20 ifeq ($(RUBY_VERSION),)
21 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
22 endif
24 # dunno how to implement this as concisely in Ruby, and hell, I love awk
25 awk_slow := awk '/def test_/{print FILENAME"--"$$2".n"}' 2>/dev/null
27 rails_vers := $(subst test/rails/app-,,$(wildcard test/rails/app-*))
28 slow_tests := test/unit/test_server.rb test/exec/test_exec.rb \
29 test/unit/test_signals.rb test/unit/test_upload.rb
30 log_suffix = .$(RUBY_VERSION).log
31 T_r := $(wildcard test/rails/test*.rb)
32 T := $(filter-out $(slow_tests) $(T_r), $(wildcard test/*/test*.rb))
33 T_n := $(shell $(awk_slow) $(slow_tests))
34 T_log := $(subst .rb,$(log_suffix),$(T))
35 T_n_log := $(subst .n,$(log_suffix),$(T_n))
36 T_r_log := $(subst .r,$(log_suffix),$(T_r))
37 test_prefix = $(CURDIR)/test/install-$(RUBY_VERSION)
39 ext := ext/unicorn_http
40 c_files := $(ext)/unicorn_http.c $(wildcard $(ext)/*.h)
41 rl_files := $(wildcard $(ext)/*.rl)
42 base_bins := unicorn unicorn_rails
43 bins := $(addprefix bin/, $(base_bins))
44 man1_rdoc := $(addsuffix _1, $(base_bins))
45 man1_bins := $(addsuffix .1, $(base_bins))
46 man1_paths := $(addprefix man/man1/, $(man1_bins))
47 rb_files := $(bins) $(shell find lib ext -type f -name '*.rb')
48 inst_deps := $(c_files) $(rb_files) GNUmakefile test/test_helper.rb
50 ragel: $(ext)/unicorn_http.c
51 $(ext)/unicorn_http.c: $(rl_files)
52 cd $(@D) && $(RAGEL) unicorn_http.rl -C $(RLFLAGS) -o $(@F)
53 $(ext)/Makefile: $(ext)/extconf.rb $(c_files)
54 cd $(@D) && $(RUBY) extconf.rb
55 $(ext)/unicorn_http.$(DLEXT): $(ext)/Makefile
56 $(MAKE) -C $(@D)
57 lib/unicorn_http.$(DLEXT): $(ext)/unicorn_http.$(DLEXT)
58 @mkdir -p lib
59 install -m644 $< $@
60 http: lib/unicorn_http.$(DLEXT)
62 test-install: $(test_prefix)/.stamp
63 $(test_prefix)/.stamp: $(inst_deps)
64 mkdir -p $(test_prefix)/.ccache
65 tar cf - $(inst_deps) GIT-VERSION-GEN | \
66 (cd $(test_prefix) && tar xf -)
67 $(MAKE) -C $(test_prefix) clean
68 $(MAKE) -C $(test_prefix) http shebang
69 > $@
71 # this is only intended to be run within $(test_prefix)
72 shebang: $(bins)
73 $(RUBY) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
75 t_log := $(T_log) $(T_n_log)
76 test: $(T) $(T_n)
77 @cat $(t_log) | $(RUBY) test/aggregate.rb
78 @$(RM) $(t_log)
80 test-exec: $(wildcard test/exec/test_*.rb)
81 test-unit: $(wildcard test/unit/test_*.rb)
82 $(slow_tests): $(test_prefix)/.stamp
83 @$(MAKE) $(shell $(awk_slow) $@)
85 TEST_OPTS = -v
86 check_test = grep '0 failures, 0 errors' $(t) >/dev/null
87 ifndef V
88 quiet_pre = @echo '* $(arg)$(extra)';
89 quiet_post = >$(t) 2>&1 && $(check_test)
90 else
91 # we can't rely on -o pipefail outside of bash 3+,
92 # so we use a stamp file to indicate success and
93 # have rm fail if the stamp didn't get created
94 stamp = $@$(log_suffix).ok
95 quiet_pre = @echo $(RUBY) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
96 quiet_post = && > $(stamp) )2>&1 | tee $(t); \
97 rm $(stamp) 2>/dev/null && $(check_test)
98 endif
100 # not all systems have setsid(8), we need it because we spam signals
101 # stupidly in some tests...
102 rb_setsid := $(RUBY) -e 'Process.setsid' -e 'exec *ARGV'
104 # TRACER='strace -f -o $(t).strace -s 100000'
105 run_test = $(quiet_pre) \
106 $(rb_setsid) $(TRACER) $(RUBY) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
107 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
109 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
110 %.n: t = $(subst .n,$(log_suffix),$@)
111 %.n: export PATH := $(test_prefix)/bin:$(PATH)
112 %.n: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
113 %.n: $(test_prefix)/.stamp
114 $(run_test)
116 $(T): arg = $@
117 $(T): t = $(subst .rb,$(log_suffix),$@)
118 $(T): export PATH := $(test_prefix)/bin:$(PATH)
119 $(T): export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
120 $(T): $(test_prefix)/.stamp
121 $(run_test)
123 install: $(bins) $(ext)/unicorn_http.c
124 $(prep_setup_rb)
125 $(RM) lib/unicorn_http.$(DLEXT)
126 $(RM) -r .install-tmp
127 mkdir .install-tmp
128 cp -p bin/* .install-tmp
129 $(RUBY) setup.rb all
130 $(RM) $^
131 mv .install-tmp/* bin/
132 $(RM) -r .install-tmp
133 $(prep_setup_rb)
135 setup_rb_files := .config InstalledFiles
136 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
138 clean:
139 -$(MAKE) -C $(ext) clean
140 -$(MAKE) -C Documentation clean
141 $(RM) $(ext)/Makefile lib/unicorn_http.$(DLEXT)
142 $(RM) $(setup_rb_files) $(t_log)
143 $(RM) -r $(test_prefix) man
145 man:
146 $(MAKE) -C Documentation install-man
148 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog $(ext)/unicorn_http.c
149 manifest: $(pkg_extra) man
150 $(RM) .manifest
151 $(MAKE) .manifest
153 .manifest:
154 (git ls-files && \
155 for i in $@ $(pkg_extra) $(man1_paths); \
156 do echo $$i; done) | LC_ALL=C sort > $@+
157 cmp $@+ $@ || mv $@+ $@
158 $(RM) $@+
160 NEWS: GIT-VERSION-FILE .manifest
161 $(RAKE) -s news_rdoc > $@+
162 mv $@+ $@
164 SINCE = 0.97.1
165 ChangeLog: LOG_VERSION = \
166 $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
167 echo $(GIT_VERSION) || git describe)
168 ChangeLog: log_range = v$(SINCE)..$(LOG_VERSION)
169 ChangeLog: GIT-VERSION-FILE
170 @echo "ChangeLog from $(GIT_URL) ($(log_range))" > $@+
171 @echo >> $@+
172 git log $(log_range) | sed -e 's/^/ /' >> $@+
173 mv $@+ $@
175 news_atom := http://unicorn.bogomips.org/NEWS.atom.xml
176 cgit_atom := http://git.bogomips.org/cgit/unicorn.git/atom/?h=master
177 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
178 type="application/atom+xml"/>
180 # using rdoc 2.5.x+
181 doc: .document $(ext)/unicorn_http.c NEWS ChangeLog
182 for i in $(man1_rdoc); do echo > $$i; done
183 find bin lib -type f -name '*.rbc' -exec rm -f '{}' ';'
184 rdoc -a -t "$(shell sed -ne '1s/^= //p' README)"
185 install -m644 COPYING doc/COPYING
186 install -m644 $(shell grep '^[A-Z]' .document) doc/
187 $(MAKE) -C Documentation install-html install-man
188 install -m644 $(man1_paths) doc/
189 cd doc && for i in $(base_bins); do \
190 $(RM) 1.html $${i}.1.html; \
191 sed -e '/"documentation">/r man1/'$$i'.1.html' \
192 < $${i}_1.html > tmp && mv tmp $${i}_1.html; \
193 ln $${i}_1.html $${i}.1.html; \
194 done
195 $(RUBY) -i -p -e \
196 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
197 doc/ChangeLog.html
198 $(RUBY) -i -p -e \
199 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
200 doc/NEWS.html doc/README.html
201 $(RAKE) -s news_atom > doc/NEWS.atom.xml
202 cd doc && ln README.html tmp && mv tmp index.html
203 $(RM) $(man1_rdoc)
205 rails_git_url = git://github.com/rails/rails.git
206 rails_git := vendor/rails.git
207 $(rails_git)/info/cloned-stamp:
208 git clone --mirror -q $(rails_git_url) $(rails_git)
209 > $@
211 $(rails_git)/info/v2.3.8-stamp: $(rails_git)/info/cloned-stamp
212 cd $(rails_git) && git fetch
213 cd $(rails_git) && git rev-parse --verify refs/tags/v2.3.8
214 > $@
216 rails_tests := $(addsuffix .r,$(addprefix $(T_r).,$(rails_vers)))
217 test-rails: $(rails_tests)
218 $(T_r).%.r: t = $(addsuffix $(log_suffix),$@)
219 $(T_r).%.r: rv = $(subst .r,,$(subst $(T_r).,,$@))
220 $(T_r).%.r: extra = ' 'v$(rv)
221 $(T_r).%.r: arg = $(T_r)
222 $(T_r).%.r: export PATH := $(test_prefix)/bin:$(PATH)
223 $(T_r).%.r: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
224 $(T_r).%.r: export UNICORN_RAILS_TEST_VERSION = $(rv)
225 $(T_r).%.r: export RAILS_GIT_REPO = $(CURDIR)/$(rails_git)
226 $(T_r).%.r: $(test_prefix)/.stamp $(rails_git)/info/v2.3.8-stamp
227 $(run_test)
229 ifneq ($(VERSION),)
230 rfproject := mongrel
231 rfpackage := unicorn
232 pkggem := pkg/$(rfpackage)-$(VERSION).gem
233 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
234 release_notes := release_notes-$(VERSION)
235 release_changes := release_changes-$(VERSION)
237 release-notes: $(release_notes)
238 release-changes: $(release_changes)
239 $(release_changes):
240 $(RAKE) -s release_changes > $@+
241 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
242 $(release_notes):
243 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
244 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
246 # ensures we're actually on the tagged $(VERSION), only used for release
247 verify:
248 test x"$(shell umask)" = x0022
249 git rev-parse --verify refs/tags/v$(VERSION)^{}
250 git diff-index --quiet HEAD^0
251 test `git rev-parse --verify HEAD^0` = \
252 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
254 fix-perms:
255 git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
256 git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
258 gem: $(pkggem)
260 install-gem: $(pkggem)
261 gem install $(CURDIR)/$<
263 $(pkggem): manifest fix-perms
264 gem build $(rfpackage).gemspec
265 mkdir -p pkg
266 mv $(@F) $@
268 $(pkgtgz): distdir = $(basename $@)
269 $(pkgtgz): HEAD = v$(VERSION)
270 $(pkgtgz): manifest fix-perms
271 @test -n "$(distdir)"
272 $(RM) -r $(distdir)
273 mkdir -p $(distdir)
274 tar cf - `cat .manifest` | (cd $(distdir) && tar xf -)
275 cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
276 mv $@+ $@
278 package: $(pkgtgz) $(pkggem)
280 release: verify package $(release_notes) $(release_changes)
281 # make tgz release on RubyForge
282 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
283 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
284 # push gem to Gemcutter
285 gem push $(pkggem)
286 # in case of gem downloads from RubyForge releases page
287 -rubyforge add_file \
288 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
289 $(RAKE) raa_update VERSION=$(VERSION)
290 $(RAKE) fm_update VERSION=$(VERSION)
291 else
292 gem install-gem: GIT-VERSION-FILE
293 $(MAKE) $@ VERSION=$(GIT_VERSION)
294 endif
296 .PHONY: .FORCE-GIT-VERSION-FILE doc $(T) $(slow_tests) manifest man
297 .PHONY: test-install