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