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
).libs
28 MYLIBS
= $(RUBYLIB
):$(shell cat
$(isolate_libs
) 2>/dev
/null || \
29 ($(RUBY
) .
/script
/isolate_for_tests
>/dev
/null
&& \
30 cat
$(isolate_libs
) 2>/dev
/null
))
35 # dunno how to implement this as concisely in Ruby, and hell, I love awk
36 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
38 rails_vers
:= $(subst test/rails
/app-
,,$(wildcard test/rails
/app-
*))
39 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
40 test/unit
/test_signals.rb
test/unit
/test_upload.rb
41 log_suffix
= .
$(RUBY_ENGINE
).
$(RUBY_VERSION
).log
42 T_r
:= $(wildcard test/rails
/test*.rb
)
43 T
:= $(filter-out $(slow_tests
) $(T_r
), $(wildcard test/*/test*.rb
))
44 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
45 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
46 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
47 T_r_log
:= $(subst .r
,$(log_suffix
),$(T_r
))
48 test_prefix
= $(CURDIR
)/test/$(RUBY_ENGINE
)-$(RUBY_VERSION
)
50 ext
:= ext
/unicorn_http
51 c_files
:= $(ext
)/unicorn_http.c
$(wildcard $(ext
)/*.h
)
52 rl_files
:= $(wildcard $(ext
)/*.rl
)
53 base_bins
:= unicorn unicorn_rails
54 bins
:= $(addprefix bin
/, $(base_bins
))
55 man1_rdoc
:= $(addsuffix _1
, $(base_bins
))
56 man1_bins
:= $(addsuffix .1, $(base_bins
))
57 man1_paths
:= $(addprefix man
/man1
/, $(man1_bins
))
58 rb_files
:= $(bins
) $(shell find lib ext
-type f
-name
'*.rb')
59 inst_deps
:= $(c_files
) $(rb_files
) GNUmakefile
test/test_helper.rb
61 ragel
: $(ext
)/unicorn_http.c
62 $(ext
)/unicorn_http.c
: $(rl_files
)
63 cd
$(@D
) && $(RAGEL
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
64 $(ext
)/Makefile
: $(ext
)/extconf.rb
$(c_files
)
65 cd
$(@D
) && $(RUBY
) extconf.rb
66 $(ext
)/unicorn_http.
$(DLEXT
): $(ext
)/Makefile
68 lib
/unicorn_http.
$(DLEXT
): $(ext
)/unicorn_http.
$(DLEXT
)
71 http
: lib
/unicorn_http.
$(DLEXT
)
73 test-install
: $(test_prefix
)/.stamp
74 $(test_prefix
)/.stamp
: $(inst_deps
)
75 mkdir
-p
$(test_prefix
)/.ccache
76 tar cf
- $(inst_deps
) GIT-VERSION-GEN | \
77 (cd
$(test_prefix
) && tar xf
-)
78 $(MAKE
) -C
$(test_prefix
) clean
79 $(MAKE
) -C
$(test_prefix
) http shebang RUBY
="$(RUBY)"
82 # this is only intended to be run within $(test_prefix)
84 $(MRI
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
86 t_log
:= $(T_log
) $(T_n_log
)
88 @cat
$(t_log
) |
$(MRI
) test/aggregate.rb
91 test-exec
: $(wildcard test/exec
/test_
*.rb
)
92 test-unit
: $(wildcard test/unit
/test_
*.rb
)
93 $(slow_tests
): $(test_prefix
)/.stamp
94 @
$(MAKE
) $(shell $(awk_slow
) $@
)
96 test-integration
: $(test_prefix
)/.stamp
99 test-all
: test test-rails test-integration
102 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
104 quiet_pre
= @echo
'* $(arg)$(extra)';
105 quiet_post
= >$(t
) 2>&1 && $(check_test
)
107 # we can't rely on -o pipefail outside of bash 3+,
108 # so we use a stamp file to indicate success and
109 # have rm fail if the stamp didn't get created
110 stamp
= $@
$(log_suffix
).ok
111 quiet_pre
= @echo
$(RUBY
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
112 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
113 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
116 # not all systems have setsid(8), we need it because we spam signals
117 # stupidly in some tests...
118 rb_setsid
:= $(RUBY
) -e
'Process.setsid' -e
'exec *ARGV'
120 # TRACER='strace -f -o $(t).strace -s 100000'
121 run_test
= $(quiet_pre
) \
122 $(rb_setsid
) $(TRACER
) $(RUBY
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
123 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
125 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
126 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
127 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
128 %.n
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
129 %.n
: $(test_prefix
)/.stamp
133 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
134 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
135 $(T
): export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
136 $(T
): $(test_prefix
)/.stamp
139 install: $(bins
) $(ext
)/unicorn_http.c
141 $(RM
) lib
/unicorn_http.
$(DLEXT
)
142 $(RM
) -r .install-tmp
144 cp
-p bin
/* .install-tmp
147 mv .install-tmp
/* bin
/
148 $(RM
) -r .install-tmp
151 setup_rb_files
:= .config InstalledFiles
152 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
155 -$(MAKE
) -C
$(ext
) clean
156 -$(MAKE
) -C Documentation
clean
157 $(RM
) $(ext
)/Makefile lib
/unicorn_http.
$(DLEXT
)
158 $(RM
) $(setup_rb_files
) $(t_log
)
159 $(RM
) -r
$(test_prefix
) man
162 $(MAKE
) -C Documentation install-man
164 pkg_extra
:= GIT-VERSION-FILE NEWS ChangeLog
$(ext
)/unicorn_http.c
165 manifest
: $(pkg_extra
) man
171 for i in
$@
$(pkg_extra
) $(man1_paths
); \
172 do echo
$$i; done
) | LC_ALL
=C
sort > $@
+
173 cmp
$@
+ $@ || mv
$@
+ $@
176 NEWS
: GIT-VERSION-FILE .manifest
177 $(RAKE
) -s news_rdoc
> $@
+
181 ChangeLog
: LOG_VERSION
= \
182 $(shell git rev-parse
-q
"$(GIT_VERSION)" >/dev
/null
2>&1 && \
183 echo
$(GIT_VERSION
) || git describe
)
184 ChangeLog
: log_range
= v
$(SINCE
)..
$(LOG_VERSION
)
185 ChangeLog
: GIT-VERSION-FILE
186 @echo
"ChangeLog from $(GIT_URL) ($(log_range))" > $@
+
188 git log
$(log_range
) | sed
-e
's/^/ /' >> $@
+
191 news_atom
:= http
://unicorn.bogomips.org
/NEWS.atom.xml
192 cgit_atom
:= http
://git.bogomips.org
/cgit
/unicorn.git
/atom
/?h
=master
193 atom
= <link rel
="alternate" title
="Atom feed" href
="$(1)" \
194 type
="application/atom+xml"/>
197 doc
: .document
$(ext
)/unicorn_http.c NEWS ChangeLog
198 for i in
$(man1_rdoc
); do echo
> $$i; done
199 find bin lib
-type f
-name
'*.rbc' -exec
rm -f
'{}' ';'
200 rdoc
-a
-t
"$(shell sed -ne '1s/^= //p' README)"
201 install -m644 COPYING doc
/COPYING
202 install -m644
$(shell grep
'^[A-Z]' .document
) doc
/
203 $(MAKE
) -C Documentation install-html install-man
204 install -m644
$(man1_paths
) doc
/
205 cd doc
&& for i in
$(base_bins
); do \
206 $(RM
) 1.html
$${i}.1.html
; \
207 sed
-e
'/"documentation">/r man1/'$$i'.1.html' \
208 < $${i}_1.html
> tmp
&& mv tmp
$${i}_1.html
; \
209 ln
$${i}_1.html
$${i}.1.html
; \
212 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
215 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
216 doc
/NEWS.html doc
/README.html
217 $(RAKE
) -s news_atom
> doc
/NEWS.atom.xml
218 cd doc
&& ln README.html tmp
&& mv tmp index.html
221 # publishes docs to http://unicorn.bogomips.org
224 $(RM
) -r doc ChangeLog NEWS
225 $(MAKE
) doc LOG_VERSION
=$(shell git tag
-l | tail
-1)
226 @awk
'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' \
228 find doc
/images doc
/js
-type f | \
229 TZ
=UTC xargs touch
-d
'1970-01-01 00:00:00' doc
/rdoc.css
231 tar cf
- $$(git ls-files examples
/) |
(cd doc
&& tar xf
-)
232 chmod
644 $$(find doc
-type f
)
233 $(RSYNC
) -av doc
/ unicorn.bogomips.org
:/srv
/unicorn
/
234 git ls-files | xargs touch
236 # Create gzip variants of the same timestamp as the original so nginx
237 # "gzip_static on" can serve the gzipped versions directly.
238 doc_gz
: docs
= $(shell find doc
-type f
! -regex
'^.*\.\(gif\|jpg\|png\|gz\)$$')
240 touch doc
/NEWS.atom.xml
-d
"$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
241 for i in
$(docs
); do \
242 gzip
--rsyncable
-9 < $$i > $$i.gz
; touch
-r
$$i $$i.gz
; done
244 rails_git_url
= git
://github.com
/rails
/rails.git
245 rails_git
:= vendor
/rails.git
246 $(rails_git
)/info/cloned-stamp
:
247 git clone
--mirror
-q
$(rails_git_url
) $(rails_git
)
250 $(rails_git
)/info/v2.3
.8-stamp
: $(rails_git
)/info/cloned-stamp
251 cd
$(rails_git
) && git fetch
252 cd
$(rails_git
) && git rev-parse
--verify refs
/tags/v2.3
.8
255 rails_tests
:= $(addsuffix .r
,$(addprefix $(T_r
).
,$(rails_vers
)))
256 test-rails
: $(rails_tests
)
257 $(T_r
).
%.r
: t
= $(addsuffix $(log_suffix
),$@
)
258 $(T_r
).
%.r
: rv
= $(subst .r
,,$(subst $(T_r
).
,,$@
))
259 $(T_r
).
%.r
: extra
= ' 'v
$(rv
)
260 $(T_r
).
%.r
: arg
= $(T_r
)
261 $(T_r
).
%.r
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
262 $(T_r
).
%.r
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
263 $(T_r
).
%.r
: export UNICORN_RAILS_TEST_VERSION
= $(rv
)
264 $(T_r
).
%.r
: export RAILS_GIT_REPO
= $(CURDIR
)/$(rails_git
)
265 $(T_r
).
%.r
: $(test_prefix
)/.stamp
$(rails_git
)/info/v2.3
.8-stamp
271 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
272 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
273 release_notes
:= release_notes-
$(VERSION
)
274 release_changes
:= release_changes-
$(VERSION
)
276 release-notes
: $(release_notes
)
277 release-changes
: $(release_changes
)
279 $(RAKE
) -s release_changes
> $@
+
280 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
282 GIT_URL
=$(GIT_URL
) $(RAKE
) -s release_notes
> $@
+
283 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
285 # ensures we're actually on the tagged $(VERSION), only used for release
287 test x
"$(shell umask)" = x0022
288 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
289 git diff-index
--quiet HEAD^
0
290 test `git rev-parse --verify HEAD^0` = \
291 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
294 git ls-tree
-r HEAD | awk
'/^100644 / {print $$NF}' | xargs chmod
644
295 git ls-tree
-r HEAD | awk
'/^100755 / {print $$NF}' | xargs chmod
755
299 install-gem
: $(pkggem
)
300 gem
install $(CURDIR
)/$<
302 $(pkggem
): manifest fix-perms
303 gem build
$(rfpackage
).gemspec
307 $(pkgtgz
): distdir
= $(basename $@
)
308 $(pkgtgz
): HEAD
= v
$(VERSION
)
309 $(pkgtgz
): manifest fix-perms
310 @
test -n
"$(distdir)"
313 tar cf
- `cat .manifest` |
(cd
$(distdir
) && tar xf
-)
314 cd pkg
&& tar cf
- $(basename $(@F
)) | gzip
-9 > $(@F
)+
317 package
: $(pkgtgz
) $(pkggem
)
319 release
: verify package
$(release_notes
) $(release_changes
)
320 # make tgz release on RubyForge
321 rubyforge add_release
-f
-n
$(release_notes
) -a
$(release_changes
) \
322 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkgtgz
)
323 # push gem to Gemcutter
325 # in case of gem downloads from RubyForge releases page
326 -rubyforge add_file \
327 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkggem
)
328 $(RAKE
) raa_update VERSION
=$(VERSION
)
329 $(RAKE
) fm_update VERSION
=$(VERSION
)
331 gem install-gem
: GIT-VERSION-FILE
332 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
335 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) manifest man