1 # use GNU Make to run tests in parallel, and without depending on Rubygems
5 ruby_bin
:= $(shell which
$(ruby
))
6 ifeq ($(DLEXT
),) # "so" for Linux
7 DLEXT
:= $(shell $(ruby
) -rrbconfig
-e
'puts Config::CONFIG["DLEXT"]')
9 ifeq ($(RUBY_VERSION
),)
10 RUBY_VERSION
:= $(shell $(ruby
) -e
'puts RUBY_VERSION')
13 # dunno how to implement this as concisely in Ruby, and hell, I love awk
14 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
16 rails_vers
:= $(subst test/rails
/app-
,,$(wildcard test/rails
/app-
*))
17 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
18 test/unit
/test_signals.rb
19 log_suffix
= .
$(RUBY_VERSION
).log
20 T_r
:= $(wildcard test/rails
/test*.rb
)
21 T
:= $(filter-out $(slow_tests
) $(T_r
), $(wildcard test/*/test*.rb
))
22 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
23 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
24 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
25 T_r_log
:= $(subst .r
,$(log_suffix
),$(T_r
))
26 test_prefix
= $(CURDIR
)/test/install-
$(RUBY_VERSION
)
28 http11_deps
:= $(addprefix ext
/unicorn
/http11
/, \
29 ext_help.h http11.c http11_parser.h \
30 http11_parser.rl http11_parser_common.rl
)
31 inst_deps
:= $(wildcard bin
/*) $(wildcard lib
/*.rb
) \
32 $(wildcard lib
/*/*.rb
) $(http11_deps
)
34 ext
/unicorn
/http11
/http11_parser.h
: $(wildcard ext
/unicorn
/http11
/*.rl
)
35 cd
$(@D
) && ragel http11_parser.rl
-C
-G2
-o
$(@F
)
36 $(ruby
) -i
-p
-e
'$$_.gsub!(%r{[ \t]*$$},"")' $@
37 ext
/unicorn
/http11
/Makefile
: ext
/unicorn
/http11
/extconf.rb
$(http11_deps
)
38 cd
$(@D
) && $(ruby
) $(<F
)
39 ext
/unicorn
/http11
/http11.
$(DLEXT
): ext
/unicorn
/http11
/Makefile
41 lib
/unicorn
/http11.
$(DLEXT
): ext
/unicorn
/http11
/http11.
$(DLEXT
)
44 http11
: lib
/unicorn
/http11.
$(DLEXT
)
46 $(test_prefix
)/.stamp
: install-test
49 install-test
: $(inst_deps
)
50 test -n
"$(test_prefix)"
51 mkdir
-p
$(test_prefix
)/.ccache
52 tar c bin ext lib GNUmakefile |
(cd
$(test_prefix
) && tar x
)
53 $(MAKE
) -C
$(test_prefix
) clean
54 $(MAKE
) -C
$(test_prefix
) http11 shebang
56 # this is only intended to be run within $(test_prefix)
57 shebang
: bin
/unicorn bin
/unicorn_rails
58 $(ruby
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
60 t_log
:= $(T_log
) $(T_n_log
)
62 @cat
$(t_log
) |
$(ruby
) test/aggregate.rb
65 test-exec
: $(wildcard test/exec
/test_
*.rb
)
66 test-unit
: $(wildcard test/unit
/test_
*.rb
)
67 $(slow_tests
): $(test_prefix
)/.stamp
68 @
$(MAKE
) $(shell $(awk_slow
) $@
)
73 quiet_pre
= @echo
'* $(arg)$(extra)';
74 quiet_post
= >$(t
) 2>&1
76 # we can't rely on -o pipefail outside of bash 3+,
77 # so we use a stamp file to indicate success and
78 # have rm fail if the stamp didn't get created
79 stamp
= $@
$(log_suffix
).ok
80 quiet_pre
= @echo
$(ruby
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
81 quiet_post
= && > $(stamp
) )>&2 | tee
$(t
); rm $(stamp
) 2>/dev
/null
83 run_test
= $(quiet_pre
) setsid
$(ruby
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
84 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
86 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
87 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
88 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
89 %.n
: export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
90 %.n
: $(test_prefix
)/.stamp
94 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
95 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
96 $(T
): export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
97 $(T
): $(test_prefix
)/.stamp
100 install: bin
/unicorn bin
/unicorn_rails
102 $(RM
) -r .install-tmp
104 cp
-p
$^ .install-tmp
107 mv
$(addprefix .install-tmp
/,$(^F
)) bin
/
108 $(RM
) -r .install-tmp
112 -$(MAKE
) -C ext
/unicorn
/http11
clean
113 $(RM
) ext
/unicorn
/http11
/Makefile lib
/unicorn
/http11.
$(DLEXT
)
115 setup_rb_files
:= .config InstalledFiles
116 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C ext
/unicorn
/http11
clean
119 $(RM
) $(setup_rb_files
)
121 $(RM
) -r
$(test_prefix
)
125 cmp
$@
+ $@ || mv
$@
+ $@
130 rdoc
-Na
-m README
-t
"$(shell sed -ne '1s/^= //p' README)"
132 rails_git_url
= git
://github.com
/rails
/rails.git
133 rails_git
:= vendor
/rails.git
134 $(rails_git
)/info/cloned-stamp
:
135 git clone
--mirror
-q
$(rails_git_url
) $(rails_git
)
138 rails_tests
:= $(addsuffix .r
,$(addprefix $(T_r
).
,$(rails_vers
)))
139 test-rails
: $(rails_tests
)
140 $(T_r
).
%.r
: t
= $(addsuffix $(log_suffix
),$@
)
141 $(T_r
).
%.r
: rv
= $(subst .r
,,$(subst $(T_r
).
,,$@
))
142 $(T_r
).
%.r
: extra
= ' 'v
$(rv
)
143 $(T_r
).
%.r
: arg
= $(T_r
)
144 $(T_r
).
%.r
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
145 $(T_r
).
%.r
: export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
146 $(T_r
).
%.r
: export UNICORN_RAILS_TEST_VERSION
= $(rv
)
147 $(T_r
).
%.r
: export RAILS_GIT_REPO
= $(CURDIR
)/$(rails_git
)
148 $(T_r
).
%.r
: $(test_prefix
)/.stamp
$(rails_git
)/info/cloned-stamp
151 .PHONY
: doc
$(T
) $(slow_tests
) Manifest