unicorn 0.8.4
[unicorn.git] / GNUmakefile
blob47c6b5f811c1ecd88dd14a1afc1312a298059869
1 # use GNU Make to run tests in parallel, and without depending on Rubygems
2 all:: test
3 ruby = ruby
4 ragel = ragel
5 RLFLAGS = -G2
6 -include local.mk
7 ruby_bin := $(shell which $(ruby))
8 ifeq ($(DLEXT),) # "so" for Linux
9 DLEXT := $(shell $(ruby) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
10 endif
11 ifeq ($(RUBY_VERSION),)
12 RUBY_VERSION := $(shell $(ruby) -e 'puts RUBY_VERSION')
13 endif
15 # dunno how to implement this as concisely in Ruby, and hell, I love awk
16 awk_slow := awk '/def test_/{print FILENAME"--"$$2".n"}' 2>/dev/null
18 rails_vers := $(subst test/rails/app-,,$(wildcard test/rails/app-*))
19 slow_tests := test/unit/test_server.rb test/exec/test_exec.rb \
20 test/unit/test_signals.rb test/unit/test_upload.rb
21 log_suffix = .$(RUBY_VERSION).log
22 T_r := $(wildcard test/rails/test*.rb)
23 T := $(filter-out $(slow_tests) $(T_r), $(wildcard test/*/test*.rb))
24 T_n := $(shell $(awk_slow) $(slow_tests))
25 T_log := $(subst .rb,$(log_suffix),$(T))
26 T_n_log := $(subst .n,$(log_suffix),$(T_n))
27 T_r_log := $(subst .r,$(log_suffix),$(T_r))
28 test_prefix = $(CURDIR)/test/install-$(RUBY_VERSION)
30 ext := ext/unicorn/http11
31 c_files := $(addprefix $(ext)/,ext_help.h http11.c http11_parser.h)
32 rl_files := $(addprefix $(ext)/,http11_parser.rl http11_parser_common.rl)
33 rb_files := $(shell grep '^\(bin\|lib\)' Manifest)
34 inst_deps := $(c_files) $(rb_files)
36 ragel: $(ext)/http11_parser.h
37 $(ext)/http11_parser.h: $(rl_files)
38 cd $(@D) && $(ragel) http11_parser.rl -C $(RLFLAGS) -o $(@F)
39 $(ruby) -i -p -e '$$_.gsub!(%r{[ \t]*$$},"")' $@
40 $(ext)/Makefile: $(ext)/extconf.rb $(c_files)
41 cd $(@D) && $(ruby) extconf.rb
42 $(ext)/http11.$(DLEXT): $(ext)/Makefile
43 $(MAKE) -C $(@D)
44 lib/unicorn/http11.$(DLEXT): $(ext)/http11.$(DLEXT)
45 @mkdir -p lib
46 install -m644 $< $@
47 http11: lib/unicorn/http11.$(DLEXT)
49 $(test_prefix)/.stamp: $(inst_deps)
50 mkdir -p $(test_prefix)/.ccache
51 tar c `cat Manifest` | (cd $(test_prefix) && tar x)
52 $(MAKE) -C $(test_prefix) clean
53 $(MAKE) -C $(test_prefix) http11 shebang
54 > $@
56 bins := $(wildcard bin/*)
58 # this is only intended to be run within $(test_prefix)
59 shebang: $(bins)
60 $(ruby) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
62 t_log := $(T_log) $(T_n_log)
63 test: $(T) $(T_n)
64 @cat $(t_log) | $(ruby) test/aggregate.rb
65 @$(RM) $(t_log)
67 test-exec: $(wildcard test/exec/test_*.rb)
68 test-unit: $(wildcard test/unit/test_*.rb)
69 $(slow_tests): $(test_prefix)/.stamp
70 @$(MAKE) $(shell $(awk_slow) $@)
72 TEST_OPTS = -v
73 TEST_OPTS = -v
74 ifndef V
75 quiet_pre = @echo '* $(arg)$(extra)';
76 quiet_post = >$(t) 2>&1
77 else
78 # we can't rely on -o pipefail outside of bash 3+,
79 # so we use a stamp file to indicate success and
80 # have rm fail if the stamp didn't get created
81 stamp = $@$(log_suffix).ok
82 quiet_pre = @echo $(ruby) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
83 quiet_post = && > $(stamp) )>&2 | tee $(t); rm $(stamp) 2>/dev/null
84 endif
85 run_test = $(quiet_pre) setsid $(ruby) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
86 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
88 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
89 %.n: t = $(subst .n,$(log_suffix),$@)
90 %.n: export PATH := $(test_prefix)/bin:$(PATH)
91 %.n: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
92 %.n: $(test_prefix)/.stamp
93 $(run_test)
95 $(T): arg = $@
96 $(T): t = $(subst .rb,$(log_suffix),$@)
97 $(T): export PATH := $(test_prefix)/bin:$(PATH)
98 $(T): export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
99 $(T): $(test_prefix)/.stamp
100 $(run_test)
102 install: $(bins)
103 $(prep_setup_rb)
104 $(RM) -r .install-tmp
105 mkdir .install-tmp
106 cp -p $^ .install-tmp
107 $(ruby) setup.rb all
108 $(RM) $^
109 mv $(addprefix .install-tmp/,$(^F)) bin/
110 $(RM) -r .install-tmp
111 $(prep_setup_rb)
113 setup_rb_files := .config InstalledFiles
114 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
116 clean:
117 -$(MAKE) -C $(ext) clean
118 $(RM) $(ext)/Makefile lib/unicorn/http11.$(DLEXT)
119 $(RM) $(setup_rb_files) $(t_log)
120 $(RM) -r $(test_prefix)
122 Manifest:
123 git ls-files > $@+
124 cmp $@+ $@ || mv $@+ $@
125 $(RM) -f $@+
127 # using rdoc 2.4.1
128 doc: .document
129 rdoc -Na -m README -t "$(shell sed -ne '1s/^= //p' README)"
131 rails_git_url = git://github.com/rails/rails.git
132 rails_git := vendor/rails.git
133 $(rails_git)/info/cloned-stamp:
134 git clone --mirror -q $(rails_git_url) $(rails_git)
135 > $@
137 rails_tests := $(addsuffix .r,$(addprefix $(T_r).,$(rails_vers)))
138 test-rails: $(rails_tests)
139 $(T_r).%.r: t = $(addsuffix $(log_suffix),$@)
140 $(T_r).%.r: rv = $(subst .r,,$(subst $(T_r).,,$@))
141 $(T_r).%.r: extra = ' 'v$(rv)
142 $(T_r).%.r: arg = $(T_r)
143 $(T_r).%.r: export PATH := $(test_prefix)/bin:$(PATH)
144 $(T_r).%.r: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
145 $(T_r).%.r: export UNICORN_RAILS_TEST_VERSION = $(rv)
146 $(T_r).%.r: export RAILS_GIT_REPO = $(CURDIR)/$(rails_git)
147 $(T_r).%.r: $(test_prefix)/.stamp $(rails_git)/info/cloned-stamp
148 $(run_test)
150 .PHONY: doc $(T) $(slow_tests) Manifest