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 log_suffix
= .
$(RUBY_VERSION
).log
19 T_r
:= $(wildcard test/rails
/test*.rb
)
20 T
:= $(filter-out $(slow_tests
) $(T_r
), $(wildcard test/*/test*.rb
))
21 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
22 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
23 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
24 T_r_log
:= $(subst .r
,$(log_suffix
),$(T_r
))
25 test_prefix
= $(CURDIR
)/test/install-
$(RUBY_VERSION
)
27 http11_deps
:= $(addprefix ext
/unicorn
/http11
/, \
28 ext_help.h http11.c http11_parser.c http11_parser.h \
29 http11_parser.rl http11_parser_common.rl
)
30 inst_deps
:= $(wildcard bin
/*) $(wildcard lib
/*.rb
) \
31 $(wildcard lib
/*/*.rb
) $(http11_deps
)
33 ext
/unicorn
/http11
/http11_parser.c
: ext
/unicorn
/http11
/http11_parser.rl
34 cd
$(@D
) && ragel
$(<F
) -C
-G2
-o
$(@F
)
35 ext
/unicorn
/http11
/Makefile
: ext
/unicorn
/http11
/extconf.rb
36 cd
$(@D
) && $(ruby
) $(<F
)
37 ext
/unicorn
/http11
/http11.
$(DLEXT
): $(http11_deps
) ext
/unicorn
/http11
/Makefile
39 lib
/unicorn
/http11.
$(DLEXT
): ext
/unicorn
/http11
/http11.
$(DLEXT
)
42 http11
: lib
/unicorn
/http11.
$(DLEXT
)
44 $(test_prefix
)/.stamp
: $(inst_deps
)
50 mkdir
-p
$(test_prefix
)/.ccache
51 tar c bin ext lib GNUmakefile |
(cd
$(test_prefix
) && tar x
)
52 $(MAKE
) -C
$(test_prefix
) http11 shebang
54 # this is only intended to be run within $(test_prefix)
55 shebang
: bin
/unicorn bin
/unicorn_rails
56 $(ruby
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
58 t_log
:= $(T_log
) $(T_n_log
)
60 @cat
$(t_log
) |
$(ruby
) test/aggregate.rb
63 test-exec
: $(wildcard test/exec
/test_
*.rb
)
64 test-unit
: $(wildcard test/unit
/test_
*.rb
)
66 @
$(MAKE
) $(shell $(awk_slow
) $@
)
71 quiet_pre
= @echo
'* $(arg)$(extra)';
72 quiet_post
= >$(t
) 2>&1
74 # we can't rely on -o pipefail outside of bash 3+,
75 # so we use a stamp file to indicate success and
76 # have rm fail if the stamp didn't get created
77 stamp
= $@
$(log_suffix
).ok
78 quiet_pre
= @echo
$(ruby
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
79 quiet_post
= && > $(stamp
) )>&2 | tee
$(t
); rm $(stamp
) 2>/dev
/null
81 run_test
= $(quiet_pre
) setsid
$(ruby
) $(arg
) $(TEST_OPTS
) $(quiet_post
) || \
82 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
84 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
85 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
86 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
87 %.n
: export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
88 %.n
: $(test_prefix
)/.stamp
92 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
93 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
94 $(T
): export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
95 $(T
): $(test_prefix
)/.stamp
98 install: bin
/unicorn bin
/unicorn_rails
100 $(RM
) -r .install-tmp
102 cp
-p
$^ .install-tmp
105 mv
$(addprefix .install-tmp
/,$(^F
)) bin
/
106 $(RM
) -r .install-tmp
110 -$(MAKE
) -C ext
/unicorn
/http11
clean
111 $(RM
) ext
/unicorn
/http11
/Makefile lib
/unicorn
/http11.
$(DLEXT
)
113 setup_rb_files
:= .config InstalledFiles
114 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C ext
/unicorn
/http11
clean
117 $(RM
) $(setup_rb_files
)
119 $(RM
) -r
$(test_prefix
)
123 cmp
$@
+ $@ || mv
$@
+ $@
128 rdoc
-Na
-m README
-t
"$(shell sed -ne '1s/^= //p' README)"
130 rails_git_url
= git
://github.com
/rails
/rails.git
131 rails_git
:= vendor
/rails.git
132 $(rails_git
)/info/cloned-stamp
:
133 git clone
--mirror
-q
$(rails_git_url
) $(rails_git
)
136 rails_tests
:= $(addsuffix .r
,$(addprefix $(T_r
).
,$(rails_vers
)))
137 test-rails
: $(rails_tests
)
138 $(T_r
).
%.r
: t
= $(addsuffix $(log_suffix
),$@
)
139 $(T_r
).
%.r
: rv
= $(subst .r
,,$(subst $(T_r
).
,,$@
))
140 $(T_r
).
%.r
: extra
= ' 'v
$(rv
)
141 $(T_r
).
%.r
: arg
= $(T_r
)
142 $(T_r
).
%.r
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
143 $(T_r
).
%.r
: export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
144 $(T_r
).
%.r
: export UNICORN_RAILS_TEST_VERSION
= $(rv
)
145 $(T_r
).
%.r
: export RAILS_GIT_REPO
= $(CURDIR
)/$(rails_git
)
146 $(T_r
).
%.r
: $(test_prefix
)/.stamp
$(rails_git
)/info/cloned-stamp
149 .PHONY
: doc
$(T
) $(slow_tests
) Manifest