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
) $@
)
69 run_test
= @echo
'*** $(arg)$(extra) ***'; \
70 setsid
$(ruby
) $(arg
) $(TEST_OPTS
) >$(t
) 2>&1 || \
71 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
73 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
74 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
75 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
76 %.n
: export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
77 %.n
: $(test_prefix
)/.stamp
81 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
82 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
83 $(T
): export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
84 $(T
): $(test_prefix
)/.stamp
87 install: bin
/unicorn bin
/unicorn_rails
94 mv
$(addprefix .install-tmp
/,$(^F
)) bin
/
99 -$(MAKE
) -C ext
/unicorn
/http11
clean
100 $(RM
) ext
/unicorn
/http11
/Makefile lib
/unicorn
/http11.
$(DLEXT
)
102 setup_rb_files
:= .config InstalledFiles
103 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C ext
/unicorn
/http11
clean
106 $(RM
) $(setup_rb_files
)
108 $(RM
) -r
$(test_prefix
)
112 cmp
$@
+ $@ || mv
$@
+ $@
117 rdoc
-Na
-m README
-t
"$(shell sed -ne '1s/^= //p' README)"
119 rails_git_url
= git
://github.com
/rails
/rails.git
120 rails_git
:= vendor
/rails.git
121 $(rails_git
)/info/cloned-stamp
:
122 git clone
--mirror
-q
$(rails_git_url
) $(rails_git
)
125 rails_tests
:= $(addsuffix .r
,$(addprefix $(T_r
).
,$(rails_vers
)))
126 test-rails
: $(rails_tests
)
127 $(T_r
).
%.r
: t
= $(addsuffix $(log_suffix
),$@
)
128 $(T_r
).
%.r
: rv
= $(subst .r
,,$(subst $(T_r
).
,,$@
))
129 $(T_r
).
%.r
: extra
= ' 'v
$(rv
)
130 $(T_r
).
%.r
: arg
= $(T_r
)
131 $(T_r
).
%.r
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
132 $(T_r
).
%.r
: export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
133 $(T_r
).
%.r
: export UNICORN_RAILS_TEST_VERSION
= $(rv
)
134 $(T_r
).
%.r
: export RAILS_GIT_REPO
= $(CURDIR
)/$(rails_git
)
135 $(T_r
).
%.r
: $(test_prefix
)/.stamp
$(rails_git
)/info/cloned-stamp
137 @sed
's,^,$(rv): ,' < $(t
)
139 .PHONY
: doc
$(T
) $(slow_tests
) Manifest