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 bins
:= $(wildcard bin
/*)
40 rb_files
:= $(bins
) $(shell find lib
-type f
-name
'*.rb')
41 inst_deps
:= $(c_files
) $(rb_files
)
43 ragel
: $(ext
)/unicorn_http.c
44 $(ext
)/unicorn_http.c
: $(rl_files
)
45 cd
$(@D
) && $(ragel
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
46 $(ruby
) -i
-p
-e
'$$_.gsub!(%r{[ \t]*$$},"")' $@
47 $(ext
)/Makefile
: $(ext
)/extconf.rb
$(c_files
)
48 cd
$(@D
) && $(ruby
) extconf.rb
49 $(ext
)/unicorn_http.
$(DLEXT
): $(ext
)/Makefile
51 lib
/unicorn_http.
$(DLEXT
): $(ext
)/unicorn_http.
$(DLEXT
)
54 http
: lib
/unicorn_http.
$(DLEXT
)
56 $(test_prefix
)/.stamp
: $(inst_deps
)
57 mkdir
-p
$(test_prefix
)/.ccache
58 tar c
`cat .manifest` |
(cd
$(test_prefix
) && tar x
)
59 $(MAKE
) -C
$(test_prefix
) clean
60 $(MAKE
) -C
$(test_prefix
) http shebang
63 # this is only intended to be run within $(test_prefix)
65 $(ruby
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
67 t_log
:= $(T_log
) $(T_n_log
)
69 @cat
$(t_log
) |
$(ruby
) test/aggregate.rb
72 test-exec
: $(wildcard test/exec
/test_
*.rb
)
73 test-unit
: $(wildcard test/unit
/test_
*.rb
)
74 $(slow_tests
): $(test_prefix
)/.stamp
75 @
$(MAKE
) $(shell $(awk_slow
) $@
)
78 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
80 quiet_pre
= @echo
'* $(arg)$(extra)';
81 quiet_post
= >$(t
) 2>&1 && $(check_test
)
83 # we can't rely on -o pipefail outside of bash 3+,
84 # so we use a stamp file to indicate success and
85 # have rm fail if the stamp didn't get created
86 stamp
= $@
$(log_suffix
).ok
87 quiet_pre
= @echo
$(ruby
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
88 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
89 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
92 # TRACER='strace -f -o $(t).strace -s 100000'
93 run_test
= $(quiet_pre
) \
94 setsid
$(TRACER
) $(ruby
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
95 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
97 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
98 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
99 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
100 %.n
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(RUBYLIB
)
101 %.n
: $(test_prefix
)/.stamp
105 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
106 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
107 $(T
): export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(RUBYLIB
)
108 $(T
): $(test_prefix
)/.stamp
111 install: $(bins
) $(ext
)/unicorn_http.c
113 $(RM
) -r .install-tmp
115 cp
-p bin
/* .install-tmp
118 mv .install-tmp
/* bin
/
119 $(RM
) -r .install-tmp
122 setup_rb_files
:= .config InstalledFiles
123 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
126 -$(MAKE
) -C
$(ext
) clean
127 -$(MAKE
) -C Documentation
clean
128 $(RM
) $(ext
)/Makefile lib
/unicorn_http.
$(DLEXT
)
129 $(RM
) $(setup_rb_files
) $(t_log
)
130 $(RM
) -r
$(test_prefix
) man
133 $(MAKE
) -C Documentation install-man
134 .manifest
: GIT-VERSION-FILE NEWS ChangeLog
$(ext
)/unicorn_http.c
138 for i in
$@
$^ man
/man1
/*.1; \
139 do echo
$$i; done
) | LC_ALL
=C
sort > $@
+
140 cmp
$@
+ $@ || mv
$@
+ $@
143 NEWS
: GIT-VERSION-FILE
144 $(rake
) -s news_rdoc
> $@
+
148 ChangeLog
: GIT-VERSION-FILE
149 @echo
"ChangeLog from $(GIT_URL) ($(SINCE)..$(GIT_VERSION))" > $@
+
151 git log v
$(SINCE
).. | sed
-e
's/^/ /' >> $@
+
154 news_atom
:= http
://unicorn.bogomips.org
/NEWS.atom.xml
155 cgit_atom
:= http
://git.bogomips.org
/cgit
/unicorn.git
/atom
/?h
=master
156 atom
= <link rel
="alternate" title
="Atom feed" href
="$(1)" \
157 type
="application/atom+xml"/>
160 doc
: .document
$(ext
)/unicorn_http.c NEWS ChangeLog
161 > unicorn
.1 && > unicorn_rails
.1
162 rdoc
-Na
-t
"$(shell sed -ne '1s/^= //p' README)"
163 install -m644
$(shell grep
'^[A-Z]' .document
) doc
/
164 $(MAKE
) -C Documentation install-html install-man
165 install -m644 man
/man1
/*.1 doc
/
166 cd doc
&& for i in unicorn unicorn_rails
; do \
167 sed
-e
'/"documentation">/r man1/'$$i'.1.html' \
168 < $${i}_1.html
> tmp
&& mv tmp
$${i}_1.html
; done
170 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
173 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
174 doc
/NEWS.html doc
/README.html
175 $(rake
) -s news_atom
> doc
/NEWS.atom.xml
176 cd doc
&& ln README.html tmp
&& mv tmp index.html
177 $(RM
) unicorn
.1 unicorn_rails
.1
179 rails_git_url
= git
://github.com
/rails
/rails.git
180 rails_git
:= vendor
/rails.git
181 $(rails_git
)/info/cloned-stamp
:
182 git clone
--mirror
-q
$(rails_git_url
) $(rails_git
)
185 rails_tests
:= $(addsuffix .r
,$(addprefix $(T_r
).
,$(rails_vers
)))
186 test-rails
: $(rails_tests
)
187 $(T_r
).
%.r
: t
= $(addsuffix $(log_suffix
),$@
)
188 $(T_r
).
%.r
: rv
= $(subst .r
,,$(subst $(T_r
).
,,$@
))
189 $(T_r
).
%.r
: extra
= ' 'v
$(rv
)
190 $(T_r
).
%.r
: arg
= $(T_r
)
191 $(T_r
).
%.r
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
192 $(T_r
).
%.r
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(RUBYLIB
)
193 $(T_r
).
%.r
: export UNICORN_RAILS_TEST_VERSION
= $(rv
)
194 $(T_r
).
%.r
: export RAILS_GIT_REPO
= $(CURDIR
)/$(rails_git
)
195 $(T_r
).
%.r
: $(test_prefix
)/.stamp
$(rails_git
)/info/cloned-stamp
201 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
202 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
203 release_notes
:= release_notes-
$(VERSION
)
204 release_changes
:= release_changes-
$(VERSION
)
206 release-notes
: $(release_notes
)
207 release-changes
: $(release_changes
)
209 $(rake
) -s release_changes
> $@
+
210 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
212 GIT_URL
=$(GIT_URL
) $(rake
) -s release_notes
> $@
+
213 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
215 # ensures we're actually on the tagged $(VERSION), only used for release
217 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
218 git diff-index
--quiet HEAD^
0
219 test `git rev-parse --verify HEAD^0` = \
220 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
223 gem build
$(rfpackage
).gemspec
227 $(pkgtgz
): distdir
= $(basename $@
)
228 $(pkgtgz
): HEAD
= v
$(VERSION
)
230 @
test -n
"$(distdir)"
233 tar c
`cat .manifest` |
(cd
$(distdir
) && tar x
)
234 cd pkg
&& tar c
$(basename $(@F
)) | gzip
-9 > $(@F
)+
237 package
: $(pkgtgz
) $(pkggem
)
239 release
: verify package
$(release_notes
) $(release_changes
)
240 rubyforge add_release
-f
-n
$(release_notes
) -a
$(release_changes
) \
241 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkggem
)
243 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkgtgz
)
246 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) .manifest man