1 # use GNU Make to run tests in parallel, and without depending on Rubygems
6 GIT_URL
= git
://git.bogomips.org
/unicorn.git
9 GIT-VERSION-FILE
: .FORCE-GIT-VERSION-FILE
11 -include GIT-VERSION-FILE
13 ruby_bin
:= $(shell which
$(ruby
))
14 ifeq ($(DLEXT
),) # "so" for Linux
15 DLEXT
:= $(shell $(ruby
) -rrbconfig
-e
'puts Config::CONFIG["DLEXT"]')
17 ifeq ($(RUBY_VERSION
),)
18 RUBY_VERSION
:= $(shell $(ruby
) -e
'puts RUBY_VERSION')
21 # dunno how to implement this as concisely in Ruby, and hell, I love awk
22 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
24 rails_vers
:= $(subst test/rails
/app-
,,$(wildcard test/rails
/app-
*))
25 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
26 test/unit
/test_signals.rb
test/unit
/test_upload.rb
27 log_suffix
= .
$(RUBY_VERSION
).log
28 T_r
:= $(wildcard test/rails
/test*.rb
)
29 T
:= $(filter-out $(slow_tests
) $(T_r
), $(wildcard test/*/test*.rb
))
30 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
31 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
32 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
33 T_r_log
:= $(subst .r
,$(log_suffix
),$(T_r
))
34 test_prefix
= $(CURDIR
)/test/install-
$(RUBY_VERSION
)
36 ext
:= ext
/unicorn_http
37 c_files
:= $(ext
)/unicorn_http.c
$(wildcard $(ext
)/*.h
)
38 rl_files
:= $(wildcard $(ext
)/*.rl
)
39 base_bins
:= unicorn unicorn_rails
40 bins
:= $(addprefix bin
/, $(base_bins
))
41 man1_bins
:= $(addsuffix .1, $(base_bins
))
42 man1_paths
:= $(addprefix man
/man1
/, $(man1_bins
))
43 rb_files
:= $(bins
) $(shell find lib
-type f
-name
'*.rb')
44 inst_deps
:= $(c_files
) $(rb_files
)
46 ragel
: $(ext
)/unicorn_http.c
47 $(ext
)/unicorn_http.c
: $(rl_files
)
48 cd
$(@D
) && $(ragel
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
49 $(ruby
) -i
-p
-e
'$$_.gsub!(%r{[ \t]*$$},"")' $@
50 $(ext
)/Makefile
: $(ext
)/extconf.rb
$(c_files
)
51 cd
$(@D
) && $(ruby
) extconf.rb
52 $(ext
)/unicorn_http.
$(DLEXT
): $(ext
)/Makefile
54 lib
/unicorn_http.
$(DLEXT
): $(ext
)/unicorn_http.
$(DLEXT
)
57 http
: lib
/unicorn_http.
$(DLEXT
)
59 $(test_prefix
)/.stamp
: $(inst_deps
) .manifest
60 mkdir
-p
$(test_prefix
)/.ccache
61 tar c
`cat .manifest` |
(cd
$(test_prefix
) && tar x
)
62 $(MAKE
) -C
$(test_prefix
) clean
63 $(MAKE
) -C
$(test_prefix
) http shebang
66 # this is only intended to be run within $(test_prefix)
68 $(ruby
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
70 t_log
:= $(T_log
) $(T_n_log
)
72 @cat
$(t_log
) |
$(ruby
) test/aggregate.rb
75 test-exec
: $(wildcard test/exec
/test_
*.rb
)
76 test-unit
: $(wildcard test/unit
/test_
*.rb
)
77 $(slow_tests
): $(test_prefix
)/.stamp
78 @
$(MAKE
) $(shell $(awk_slow
) $@
)
81 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
83 quiet_pre
= @echo
'* $(arg)$(extra)';
84 quiet_post
= >$(t
) 2>&1 && $(check_test
)
86 # we can't rely on -o pipefail outside of bash 3+,
87 # so we use a stamp file to indicate success and
88 # have rm fail if the stamp didn't get created
89 stamp
= $@
$(log_suffix
).ok
90 quiet_pre
= @echo
$(ruby
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
91 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
92 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
95 # TRACER='strace -f -o $(t).strace -s 100000'
96 run_test
= $(quiet_pre
) \
97 setsid
$(TRACER
) $(ruby
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
98 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
100 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
101 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
102 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
103 %.n
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(RUBYLIB
)
104 %.n
: $(test_prefix
)/.stamp
108 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
109 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
110 $(T
): export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(RUBYLIB
)
111 $(T
): $(test_prefix
)/.stamp
114 install: $(bins
) $(ext
)/unicorn_http.c
116 $(RM
) lib
/unicorn_http.
$(DLEXT
)
117 $(RM
) -r .install-tmp
119 cp
-p bin
/* .install-tmp
122 mv .install-tmp
/* bin
/
123 $(RM
) -r .install-tmp
126 setup_rb_files
:= .config InstalledFiles
127 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
130 -$(MAKE
) -C
$(ext
) clean
131 -$(MAKE
) -C Documentation
clean
132 $(RM
) $(ext
)/Makefile lib
/unicorn_http.
$(DLEXT
)
133 $(RM
) $(setup_rb_files
) $(t_log
)
134 $(RM
) -r
$(test_prefix
) man
137 $(MAKE
) -C Documentation install-man
139 pkg_extra
:= GIT-VERSION-FILE NEWS ChangeLog
$(ext
)/unicorn_http.c
140 manifest
: $(pkg_extra
) man
146 for i in
$@
$(pkg_extra
) $(man1_paths
); \
147 do echo
$$i; done
) | LC_ALL
=C
sort > $@
+
148 cmp
$@
+ $@ || mv
$@
+ $@
151 NEWS
: GIT-VERSION-FILE
152 $(rake
) -s news_rdoc
> $@
+
156 ChangeLog
: GIT-VERSION-FILE
157 @echo
"ChangeLog from $(GIT_URL) ($(SINCE)..$(GIT_VERSION))" > $@
+
159 git log v
$(SINCE
).. | sed
-e
's/^/ /' >> $@
+
162 news_atom
:= http
://unicorn.bogomips.org
/NEWS.atom.xml
163 cgit_atom
:= http
://git.bogomips.org
/cgit
/unicorn.git
/atom
/?h
=master
164 atom
= <link rel
="alternate" title
="Atom feed" href
="$(1)" \
165 type
="application/atom+xml"/>
168 doc
: .document
$(ext
)/unicorn_http.c NEWS ChangeLog
169 for i in
$(man1_bins
); do
> $$i; done
170 rdoc
-Na
-t
"$(shell sed -ne '1s/^= //p' README)"
171 install -m644
$(shell grep
'^[A-Z]' .document
) doc
/
172 $(MAKE
) -C Documentation install-html install-man
173 install -m644
$(man1_paths
) doc
/
174 cd doc
&& for i in
$(base_bins
); do \
175 sed
-e
'/"documentation">/r man1/'$$i'.1.html' \
176 < $${i}_1.html
> tmp
&& mv tmp
$${i}_1.html
; done
178 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
181 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
182 doc
/NEWS.html doc
/README.html
183 $(rake
) -s news_atom
> doc
/NEWS.atom.xml
184 cd doc
&& ln README.html tmp
&& mv tmp index.html
187 rails_git_url
= git
://github.com
/rails
/rails.git
188 rails_git
:= vendor
/rails.git
189 $(rails_git
)/info/cloned-stamp
:
190 git clone
--mirror
-q
$(rails_git_url
) $(rails_git
)
193 rails_tests
:= $(addsuffix .r
,$(addprefix $(T_r
).
,$(rails_vers
)))
194 test-rails
: $(rails_tests
)
195 $(T_r
).
%.r
: t
= $(addsuffix $(log_suffix
),$@
)
196 $(T_r
).
%.r
: rv
= $(subst .r
,,$(subst $(T_r
).
,,$@
))
197 $(T_r
).
%.r
: extra
= ' 'v
$(rv
)
198 $(T_r
).
%.r
: arg
= $(T_r
)
199 $(T_r
).
%.r
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
200 $(T_r
).
%.r
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(RUBYLIB
)
201 $(T_r
).
%.r
: export UNICORN_RAILS_TEST_VERSION
= $(rv
)
202 $(T_r
).
%.r
: export RAILS_GIT_REPO
= $(CURDIR
)/$(rails_git
)
203 $(T_r
).
%.r
: $(test_prefix
)/.stamp
$(rails_git
)/info/cloned-stamp
209 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
210 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
211 release_notes
:= release_notes-
$(VERSION
)
212 release_changes
:= release_changes-
$(VERSION
)
214 release-notes
: $(release_notes
)
215 release-changes
: $(release_changes
)
217 $(rake
) -s release_changes
> $@
+
218 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
220 GIT_URL
=$(GIT_URL
) $(rake
) -s release_notes
> $@
+
221 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
223 # ensures we're actually on the tagged $(VERSION), only used for release
225 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
226 git diff-index
--quiet HEAD^
0
227 test `git rev-parse --verify HEAD^0` = \
228 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
232 install-gem
: $(pkggem
)
233 gem
install $(CURDIR
)/$<
236 gem build
$(rfpackage
).gemspec
240 $(pkgtgz
): distdir
= $(basename $@
)
241 $(pkgtgz
): HEAD
= v
$(VERSION
)
243 @
test -n
"$(distdir)"
246 tar c
`cat .manifest` |
(cd
$(distdir
) && tar x
)
247 cd pkg
&& tar c
$(basename $(@F
)) | gzip
-9 > $(@F
)+
250 package
: $(pkgtgz
) $(pkggem
)
252 release
: verify package
$(release_notes
) $(release_changes
)
253 rubyforge add_release
-f
-n
$(release_notes
) -a
$(release_changes
) \
254 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkggem
)
256 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkgtgz
)
258 gem install-gem
: GIT-VERSION-FILE
259 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
262 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) manifest man