1 # use GNU Make to run tests in parallel, and without depending on RubyGems
4 GIT_URL
= git
://git.bogomips.org
/unicorn.git
13 GIT-VERSION-FILE
: .FORCE-GIT-VERSION-FILE
15 -include GIT-VERSION-FILE
17 ruby_bin
:= $(shell which
$(RUBY
))
18 ifeq ($(DLEXT
),) # "so" for Linux
19 DLEXT
:= $(shell $(RUBY
) -rrbconfig
-e
'puts Config::CONFIG["DLEXT"]')
21 ifeq ($(RUBY_VERSION
),)
22 RUBY_VERSION
:= $(shell $(RUBY
) -e
'puts RUBY_VERSION')
25 RUBY_ENGINE
:= $(shell $(RUBY
) -e
'puts((RUBY_ENGINE rescue "ruby"))')
27 # dunno how to implement this as concisely in Ruby, and hell, I love awk
28 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
30 rails_vers
:= $(subst test/rails
/app-
,,$(wildcard test/rails
/app-
*))
31 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
32 test/unit
/test_signals.rb
test/unit
/test_upload.rb
33 log_suffix
= .
$(RUBY_ENGINE
).
$(RUBY_VERSION
).log
34 T_r
:= $(wildcard test/rails
/test*.rb
)
35 T
:= $(filter-out $(slow_tests
) $(T_r
), $(wildcard test/*/test*.rb
))
36 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
37 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
38 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
39 T_r_log
:= $(subst .r
,$(log_suffix
),$(T_r
))
40 test_prefix
= $(CURDIR
)/test/$(RUBY_ENGINE
)-$(RUBY_VERSION
)
42 ext
:= ext
/unicorn_http
43 c_files
:= $(ext
)/unicorn_http.c
$(wildcard $(ext
)/*.h
)
44 rl_files
:= $(wildcard $(ext
)/*.rl
)
45 base_bins
:= unicorn unicorn_rails
46 bins
:= $(addprefix bin
/, $(base_bins
))
47 man1_rdoc
:= $(addsuffix _1
, $(base_bins
))
48 man1_bins
:= $(addsuffix .1, $(base_bins
))
49 man1_paths
:= $(addprefix man
/man1
/, $(man1_bins
))
50 rb_files
:= $(bins
) $(shell find lib ext
-type f
-name
'*.rb')
51 inst_deps
:= $(c_files
) $(rb_files
) GNUmakefile
test/test_helper.rb
53 ragel
: $(ext
)/unicorn_http.c
54 $(ext
)/unicorn_http.c
: $(rl_files
)
55 cd
$(@D
) && $(RAGEL
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
56 $(ext
)/Makefile
: $(ext
)/extconf.rb
$(c_files
)
57 cd
$(@D
) && $(RUBY
) extconf.rb
58 $(ext
)/unicorn_http.
$(DLEXT
): $(ext
)/Makefile
60 lib
/unicorn_http.
$(DLEXT
): $(ext
)/unicorn_http.
$(DLEXT
)
63 http
: lib
/unicorn_http.
$(DLEXT
)
65 test-install
: $(test_prefix
)/.stamp
66 $(test_prefix
)/.stamp
: $(inst_deps
)
67 mkdir
-p
$(test_prefix
)/.ccache
68 tar cf
- $(inst_deps
) GIT-VERSION-GEN | \
69 (cd
$(test_prefix
) && tar xf
-)
70 $(MAKE
) -C
$(test_prefix
) clean
71 $(MAKE
) -C
$(test_prefix
) http shebang RUBY
="$(RUBY)"
74 # this is only intended to be run within $(test_prefix)
76 $(MRI
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
78 t_log
:= $(T_log
) $(T_n_log
)
80 @cat
$(t_log
) |
$(MRI
) test/aggregate.rb
83 test-exec
: $(wildcard test/exec
/test_
*.rb
)
84 test-unit
: $(wildcard test/unit
/test_
*.rb
)
85 $(slow_tests
): $(test_prefix
)/.stamp
86 @
$(MAKE
) $(shell $(awk_slow
) $@
)
88 test-integration
: $(test_prefix
)/.stamp
91 test-all
: test test-rails test-integration
94 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
96 quiet_pre
= @echo
'* $(arg)$(extra)';
97 quiet_post
= >$(t
) 2>&1 && $(check_test
)
99 # we can't rely on -o pipefail outside of bash 3+,
100 # so we use a stamp file to indicate success and
101 # have rm fail if the stamp didn't get created
102 stamp
= $@
$(log_suffix
).ok
103 quiet_pre
= @echo
$(RUBY
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
104 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
105 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
108 # not all systems have setsid(8), we need it because we spam signals
109 # stupidly in some tests...
110 rb_setsid
:= $(RUBY
) -e
'Process.setsid' -e
'exec *ARGV'
112 # TRACER='strace -f -o $(t).strace -s 100000'
113 run_test
= $(quiet_pre
) \
114 $(rb_setsid
) $(TRACER
) $(RUBY
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
115 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
117 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
118 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
119 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
120 %.n
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(RUBYLIB
)
121 %.n
: $(test_prefix
)/.stamp
125 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
126 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
127 $(T
): export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(RUBYLIB
)
128 $(T
): $(test_prefix
)/.stamp
131 install: $(bins
) $(ext
)/unicorn_http.c
133 $(RM
) lib
/unicorn_http.
$(DLEXT
)
134 $(RM
) -r .install-tmp
136 cp
-p bin
/* .install-tmp
139 mv .install-tmp
/* bin
/
140 $(RM
) -r .install-tmp
143 setup_rb_files
:= .config InstalledFiles
144 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
147 -$(MAKE
) -C
$(ext
) clean
148 -$(MAKE
) -C Documentation
clean
149 $(RM
) $(ext
)/Makefile lib
/unicorn_http.
$(DLEXT
)
150 $(RM
) $(setup_rb_files
) $(t_log
)
151 $(RM
) -r
$(test_prefix
) man
154 $(MAKE
) -C Documentation install-man
156 pkg_extra
:= GIT-VERSION-FILE NEWS ChangeLog
$(ext
)/unicorn_http.c
157 manifest
: $(pkg_extra
) man
163 for i in
$@
$(pkg_extra
) $(man1_paths
); \
164 do echo
$$i; done
) | LC_ALL
=C
sort > $@
+
165 cmp
$@
+ $@ || mv
$@
+ $@
168 NEWS
: GIT-VERSION-FILE .manifest
169 $(RAKE
) -s news_rdoc
> $@
+
173 ChangeLog
: LOG_VERSION
= \
174 $(shell git rev-parse
-q
"$(GIT_VERSION)" >/dev
/null
2>&1 && \
175 echo
$(GIT_VERSION
) || git describe
)
176 ChangeLog
: log_range
= v
$(SINCE
)..
$(LOG_VERSION
)
177 ChangeLog
: GIT-VERSION-FILE
178 @echo
"ChangeLog from $(GIT_URL) ($(log_range))" > $@
+
180 git log
$(log_range
) | sed
-e
's/^/ /' >> $@
+
183 news_atom
:= http
://unicorn.bogomips.org
/NEWS.atom.xml
184 cgit_atom
:= http
://git.bogomips.org
/cgit
/unicorn.git
/atom
/?h
=master
185 atom
= <link rel
="alternate" title
="Atom feed" href
="$(1)" \
186 type
="application/atom+xml"/>
189 doc
: .document
$(ext
)/unicorn_http.c NEWS ChangeLog
190 for i in
$(man1_rdoc
); do echo
> $$i; done
191 find bin lib
-type f
-name
'*.rbc' -exec
rm -f
'{}' ';'
192 rdoc
-a
-t
"$(shell sed -ne '1s/^= //p' README)"
193 install -m644 COPYING doc
/COPYING
194 install -m644
$(shell grep
'^[A-Z]' .document
) doc
/
195 $(MAKE
) -C Documentation install-html install-man
196 install -m644
$(man1_paths
) doc
/
197 cd doc
&& for i in
$(base_bins
); do \
198 $(RM
) 1.html
$${i}.1.html
; \
199 sed
-e
'/"documentation">/r man1/'$$i'.1.html' \
200 < $${i}_1.html
> tmp
&& mv tmp
$${i}_1.html
; \
201 ln
$${i}_1.html
$${i}.1.html
; \
204 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
207 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
208 doc
/NEWS.html doc
/README.html
209 $(RAKE
) -s news_atom
> doc
/NEWS.atom.xml
210 cd doc
&& ln README.html tmp
&& mv tmp index.html
213 # publishes docs to http://unicorn.bogomips.org
216 $(RM
) -r doc ChangeLog NEWS
217 $(MAKE
) doc LOG_VERSION
=$(shell git tag
-l | tail
-1)
218 @awk
'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' \
220 find doc
/images doc
/js
-type f | \
221 TZ
=UTC xargs touch
-d
'1970-01-01 00:00:00' doc
/rdoc.css
223 tar cf
- $$(git ls-files examples
/) |
(cd doc
&& tar xf
-)
224 chmod
644 $$(find doc
-type f
)
225 $(RSYNC
) -av doc
/ unicorn.bogomips.org
:/srv
/unicorn
/
226 git ls-files | xargs touch
228 # Create gzip variants of the same timestamp as the original so nginx
229 # "gzip_static on" can serve the gzipped versions directly.
230 doc_gz
: docs
= $(shell find doc
-type f
! -regex
'^.*\.\(gif\|jpg\|png\|gz\)$$')
232 touch doc
/NEWS.atom.xml
-d
"$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
233 for i in
$(docs
); do \
234 gzip
--rsyncable
-9 < $$i > $$i.gz
; touch
-r
$$i $$i.gz
; done
236 rails_git_url
= git
://github.com
/rails
/rails.git
237 rails_git
:= vendor
/rails.git
238 $(rails_git
)/info/cloned-stamp
:
239 git clone
--mirror
-q
$(rails_git_url
) $(rails_git
)
242 $(rails_git
)/info/v2.3
.8-stamp
: $(rails_git
)/info/cloned-stamp
243 cd
$(rails_git
) && git fetch
244 cd
$(rails_git
) && git rev-parse
--verify refs
/tags/v2.3
.8
247 rails_tests
:= $(addsuffix .r
,$(addprefix $(T_r
).
,$(rails_vers
)))
248 test-rails
: $(rails_tests
)
249 $(T_r
).
%.r
: t
= $(addsuffix $(log_suffix
),$@
)
250 $(T_r
).
%.r
: rv
= $(subst .r
,,$(subst $(T_r
).
,,$@
))
251 $(T_r
).
%.r
: extra
= ' 'v
$(rv
)
252 $(T_r
).
%.r
: arg
= $(T_r
)
253 $(T_r
).
%.r
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
254 $(T_r
).
%.r
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(RUBYLIB
)
255 $(T_r
).
%.r
: export UNICORN_RAILS_TEST_VERSION
= $(rv
)
256 $(T_r
).
%.r
: export RAILS_GIT_REPO
= $(CURDIR
)/$(rails_git
)
257 $(T_r
).
%.r
: $(test_prefix
)/.stamp
$(rails_git
)/info/v2.3
.8-stamp
263 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
264 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
265 release_notes
:= release_notes-
$(VERSION
)
266 release_changes
:= release_changes-
$(VERSION
)
268 release-notes
: $(release_notes
)
269 release-changes
: $(release_changes
)
271 $(RAKE
) -s release_changes
> $@
+
272 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
274 GIT_URL
=$(GIT_URL
) $(RAKE
) -s release_notes
> $@
+
275 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
277 # ensures we're actually on the tagged $(VERSION), only used for release
279 test x
"$(shell umask)" = x0022
280 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
281 git diff-index
--quiet HEAD^
0
282 test `git rev-parse --verify HEAD^0` = \
283 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
286 git ls-tree
-r HEAD | awk
'/^100644 / {print $$NF}' | xargs chmod
644
287 git ls-tree
-r HEAD | awk
'/^100755 / {print $$NF}' | xargs chmod
755
291 install-gem
: $(pkggem
)
292 gem
install $(CURDIR
)/$<
294 $(pkggem
): manifest fix-perms
295 gem build
$(rfpackage
).gemspec
299 $(pkgtgz
): distdir
= $(basename $@
)
300 $(pkgtgz
): HEAD
= v
$(VERSION
)
301 $(pkgtgz
): manifest fix-perms
302 @
test -n
"$(distdir)"
305 tar cf
- `cat .manifest` |
(cd
$(distdir
) && tar xf
-)
306 cd pkg
&& tar cf
- $(basename $(@F
)) | gzip
-9 > $(@F
)+
309 package
: $(pkgtgz
) $(pkggem
)
311 release
: verify package
$(release_notes
) $(release_changes
)
312 # make tgz release on RubyForge
313 rubyforge add_release
-f
-n
$(release_notes
) -a
$(release_changes
) \
314 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkgtgz
)
315 # push gem to Gemcutter
317 # in case of gem downloads from RubyForge releases page
318 -rubyforge add_file \
319 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkggem
)
320 $(RAKE
) raa_update VERSION
=$(VERSION
)
321 $(RAKE
) fm_update VERSION
=$(VERSION
)
323 gem install-gem
: GIT-VERSION-FILE
324 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
327 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) manifest man