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 isolate_libs
:= tmp
/isolate
/$(RUBY_ENGINE
)-$(RUBY_VERSION
).mk
28 $(isolate_libs
): script
/isolate_for_tests
29 @
$(RUBY
) script
/isolate_for_tests
30 -include $(isolate_libs
)
31 MYLIBS
= $(RUBYLIB
):$(ISOLATE_LIBS
)
33 # dunno how to implement this as concisely in Ruby, and hell, I love awk
34 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
36 rails_vers
:= $(subst test/rails
/app-
,,$(wildcard test/rails
/app-
*))
37 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
38 test/unit
/test_signals.rb
test/unit
/test_upload.rb
39 log_suffix
= .
$(RUBY_ENGINE
).
$(RUBY_VERSION
).log
40 T_r
:= $(wildcard test/rails
/test*.rb
)
41 T
:= $(filter-out $(slow_tests
) $(T_r
), $(wildcard test/*/test*.rb
))
42 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
43 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
44 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
45 T_r_log
:= $(subst .r
,$(log_suffix
),$(T_r
))
46 test_prefix
= $(CURDIR
)/test/$(RUBY_ENGINE
)-$(RUBY_VERSION
)
48 ext
:= ext
/unicorn_http
49 c_files
:= $(ext
)/unicorn_http.c
$(wildcard $(ext
)/*.h
)
50 rl_files
:= $(wildcard $(ext
)/*.rl
)
51 base_bins
:= unicorn unicorn_rails
52 bins
:= $(addprefix bin
/, $(base_bins
))
53 man1_rdoc
:= $(addsuffix _1
, $(base_bins
))
54 man1_bins
:= $(addsuffix .1, $(base_bins
))
55 man1_paths
:= $(addprefix man
/man1
/, $(man1_bins
))
56 rb_files
:= $(bins
) $(shell find lib ext
-type f
-name
'*.rb')
57 inst_deps
:= $(c_files
) $(rb_files
) GNUmakefile
test/test_helper.rb
59 ragel
: $(ext
)/unicorn_http.c
60 $(ext
)/unicorn_http.c
: $(rl_files
)
61 cd
$(@D
) && $(RAGEL
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
62 $(ext
)/Makefile
: $(ext
)/extconf.rb
$(c_files
)
63 cd
$(@D
) && $(RUBY
) extconf.rb
64 $(ext
)/unicorn_http.
$(DLEXT
): $(ext
)/Makefile
66 lib
/unicorn_http.
$(DLEXT
): $(ext
)/unicorn_http.
$(DLEXT
)
69 http
: lib
/unicorn_http.
$(DLEXT
)
71 test-install
: $(test_prefix
)/.stamp
72 $(test_prefix
)/.stamp
: $(inst_deps
)
73 mkdir
-p
$(test_prefix
)/.ccache
74 tar cf
- $(inst_deps
) GIT-VERSION-GEN | \
75 (cd
$(test_prefix
) && tar xf
-)
76 $(MAKE
) -C
$(test_prefix
) clean
77 $(MAKE
) -C
$(test_prefix
) http shebang RUBY
="$(RUBY)"
80 # this is only intended to be run within $(test_prefix)
82 $(MRI
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
84 t_log
:= $(T_log
) $(T_n_log
)
86 @cat
$(t_log
) |
$(MRI
) test/aggregate.rb
89 test-exec
: $(wildcard test/exec
/test_
*.rb
)
90 test-unit
: $(wildcard test/unit
/test_
*.rb
)
91 $(slow_tests
): $(test_prefix
)/.stamp
92 @
$(MAKE
) $(shell $(awk_slow
) $@
)
94 test-integration
: $(test_prefix
)/.stamp
97 test-all
: test test-rails test-integration
100 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
102 quiet_pre
= @echo
'* $(arg)$(extra)';
103 quiet_post
= >$(t
) 2>&1 && $(check_test
)
105 # we can't rely on -o pipefail outside of bash 3+,
106 # so we use a stamp file to indicate success and
107 # have rm fail if the stamp didn't get created
108 stamp
= $@
$(log_suffix
).ok
109 quiet_pre
= @echo
$(RUBY
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
110 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
111 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
114 # not all systems have setsid(8), we need it because we spam signals
115 # stupidly in some tests...
116 rb_setsid
:= $(RUBY
) -e
'Process.setsid' -e
'exec *ARGV'
118 # TRACER='strace -f -o $(t).strace -s 100000'
119 run_test
= $(quiet_pre
) \
120 $(rb_setsid
) $(TRACER
) $(RUBY
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
121 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
123 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
124 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
125 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
126 %.n
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
127 %.n
: $(test_prefix
)/.stamp
131 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
132 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
133 $(T
): export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
134 $(T
): $(test_prefix
)/.stamp
137 install: $(bins
) $(ext
)/unicorn_http.c
139 $(RM
) lib
/unicorn_http.
$(DLEXT
)
140 $(RM
) -r .install-tmp
142 cp
-p bin
/* .install-tmp
145 mv .install-tmp
/* bin
/
146 $(RM
) -r .install-tmp
149 setup_rb_files
:= .config InstalledFiles
150 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
153 -$(MAKE
) -C
$(ext
) clean
154 -$(MAKE
) -C Documentation
clean
155 $(RM
) $(ext
)/Makefile lib
/unicorn_http.
$(DLEXT
)
156 $(RM
) $(setup_rb_files
) $(t_log
)
157 $(RM
) -r
$(test_prefix
) man
160 $(MAKE
) -C Documentation install-man
162 pkg_extra
:= GIT-VERSION-FILE NEWS ChangeLog
$(ext
)/unicorn_http.c
163 manifest
: $(pkg_extra
) man
169 for i in
$@
$(pkg_extra
) $(man1_paths
); \
170 do echo
$$i; done
) | LC_ALL
=C
sort > $@
+
171 cmp
$@
+ $@ || mv
$@
+ $@
174 NEWS
: GIT-VERSION-FILE .manifest
175 $(RAKE
) -s news_rdoc
> $@
+
179 ChangeLog
: LOG_VERSION
= \
180 $(shell git rev-parse
-q
"$(GIT_VERSION)" >/dev
/null
2>&1 && \
181 echo
$(GIT_VERSION
) || git describe
)
182 ChangeLog
: log_range
= v
$(SINCE
)..
$(LOG_VERSION
)
183 ChangeLog
: GIT-VERSION-FILE
184 @echo
"ChangeLog from $(GIT_URL) ($(log_range))" > $@
+
186 git log
$(log_range
) | sed
-e
's/^/ /' >> $@
+
189 news_atom
:= http
://unicorn.bogomips.org
/NEWS.atom.xml
190 cgit_atom
:= http
://git.bogomips.org
/cgit
/unicorn.git
/atom
/?h
=master
191 atom
= <link rel
="alternate" title
="Atom feed" href
="$(1)" \
192 type
="application/atom+xml"/>
195 doc
: .document
$(ext
)/unicorn_http.c NEWS ChangeLog
196 for i in
$(man1_rdoc
); do echo
> $$i; done
197 find bin lib
-type f
-name
'*.rbc' -exec
rm -f
'{}' ';'
198 rdoc
-t
"$(shell sed -ne '1s/^= //p' README)"
199 install -m644 COPYING doc
/COPYING
200 install -m644
$(shell grep
'^[A-Z]' .document
) doc
/
201 $(MAKE
) -C Documentation install-html install-man
202 install -m644
$(man1_paths
) doc
/
203 cd doc
&& for i in
$(base_bins
); do \
204 $(RM
) 1.html
$${i}.1.html
; \
205 sed
-e
'/"documentation">/r man1/'$$i'.1.html' \
206 < $${i}_1.html
> tmp
&& mv tmp
$${i}_1.html
; \
207 ln
$${i}_1.html
$${i}.1.html
; \
210 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
213 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
214 doc
/NEWS.html doc
/README.html
215 $(RAKE
) -s news_atom
> doc
/NEWS.atom.xml
216 cd doc
&& ln README.html tmp
&& mv tmp index.html
219 # publishes docs to http://unicorn.bogomips.org
222 $(RM
) -r doc ChangeLog NEWS
223 $(MAKE
) doc LOG_VERSION
=$(shell git tag
-l | tail
-1)
224 @awk
'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' \
226 find doc
/images doc
/js
-type f | \
227 TZ
=UTC xargs touch
-d
'1970-01-01 00:00:00' doc
/rdoc.css
229 tar cf
- $$(git ls-files examples
/) |
(cd doc
&& tar xf
-)
230 chmod
644 $$(find doc
-type f
)
231 $(RSYNC
) -av doc
/ unicorn.bogomips.org
:/srv
/unicorn
/
232 git ls-files | xargs touch
234 # Create gzip variants of the same timestamp as the original so nginx
235 # "gzip_static on" can serve the gzipped versions directly.
236 doc_gz
: docs
= $(shell find doc
-type f
! -regex
'^.*\.\(gif\|jpg\|png\|gz\)$$')
238 touch doc
/NEWS.atom.xml
-d
"$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
239 for i in
$(docs
); do \
240 gzip
--rsyncable
-9 < $$i > $$i.gz
; touch
-r
$$i $$i.gz
; done
242 rails_git_url
= git
://github.com
/rails
/rails.git
243 rails_git
:= vendor
/rails.git
244 $(rails_git
)/info/cloned-stamp
:
245 git clone
--mirror
-q
$(rails_git_url
) $(rails_git
)
248 $(rails_git
)/info/v2.3
.8-stamp
: $(rails_git
)/info/cloned-stamp
249 cd
$(rails_git
) && git fetch
250 cd
$(rails_git
) && git rev-parse
--verify refs
/tags/v2.3
.8
253 rails_tests
:= $(addsuffix .r
,$(addprefix $(T_r
).
,$(rails_vers
)))
254 test-rails
: $(rails_tests
)
255 $(T_r
).
%.r
: t
= $(addsuffix $(log_suffix
),$@
)
256 $(T_r
).
%.r
: rv
= $(subst .r
,,$(subst $(T_r
).
,,$@
))
257 $(T_r
).
%.r
: extra
= ' 'v
$(rv
)
258 $(T_r
).
%.r
: arg
= $(T_r
)
259 $(T_r
).
%.r
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
260 $(T_r
).
%.r
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
261 $(T_r
).
%.r
: export UNICORN_RAILS_TEST_VERSION
= $(rv
)
262 $(T_r
).
%.r
: export RAILS_GIT_REPO
= $(CURDIR
)/$(rails_git
)
263 $(T_r
).
%.r
: $(test_prefix
)/.stamp
$(rails_git
)/info/v2.3
.8-stamp
269 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
270 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
271 release_notes
:= release_notes-
$(VERSION
)
272 release_changes
:= release_changes-
$(VERSION
)
274 release-notes
: $(release_notes
)
275 release-changes
: $(release_changes
)
277 $(RAKE
) -s release_changes
> $@
+
278 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
280 GIT_URL
=$(GIT_URL
) $(RAKE
) -s release_notes
> $@
+
281 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
283 # ensures we're actually on the tagged $(VERSION), only used for release
285 test x
"$(shell umask)" = x0022
286 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
287 git diff-index
--quiet HEAD^
0
288 test `git rev-parse --verify HEAD^0` = \
289 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
292 git ls-tree
-r HEAD | awk
'/^100644 / {print $$NF}' | xargs chmod
644
293 git ls-tree
-r HEAD | awk
'/^100755 / {print $$NF}' | xargs chmod
755
297 install-gem
: $(pkggem
)
298 gem
install $(CURDIR
)/$<
300 $(pkggem
): manifest fix-perms
301 gem build
$(rfpackage
).gemspec
305 $(pkgtgz
): distdir
= $(basename $@
)
306 $(pkgtgz
): HEAD
= v
$(VERSION
)
307 $(pkgtgz
): manifest fix-perms
308 @
test -n
"$(distdir)"
311 tar cf
- `cat .manifest` |
(cd
$(distdir
) && tar xf
-)
312 cd pkg
&& tar cf
- $(basename $(@F
)) | gzip
-9 > $(@F
)+
315 package
: $(pkgtgz
) $(pkggem
)
317 release
: verify package
$(release_notes
) $(release_changes
)
318 # make tgz release on RubyForge
319 rubyforge add_release
-f
-n
$(release_notes
) -a
$(release_changes
) \
320 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkgtgz
)
321 # push gem to Gemcutter
323 # in case of gem downloads from RubyForge releases page
324 -rubyforge add_file \
325 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkggem
)
326 $(RAKE
) raa_update VERSION
=$(VERSION
)
327 $(RAKE
) fm_update VERSION
=$(VERSION
)
329 gem install-gem
: GIT-VERSION-FILE
330 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
333 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) manifest man