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