1 # use GNU Make to run tests in parallel, and without depending on RubyGems
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 RbConfig::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 isolate_libs
:= tmp
/isolate
/$(RUBY_ENGINE
)-$(RUBY_VERSION
).mk
27 $(isolate_libs
): script
/isolate_for_tests
28 @
$(RUBY
) script
/isolate_for_tests
29 -include $(isolate_libs
)
30 MYLIBS
= $(RUBYLIB
):$(ISOLATE_LIBS
)
32 # dunno how to implement this as concisely in Ruby, and hell, I love awk
33 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
35 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
36 test/unit
/test_signals.rb
test/unit
/test_upload.rb
37 log_suffix
= .
$(RUBY_ENGINE
).
$(RUBY_VERSION
).log
38 T
:= $(filter-out $(slow_tests
), $(wildcard test/*/test*.rb
))
39 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
40 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
41 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
42 test_prefix
= $(CURDIR
)/test/$(RUBY_ENGINE
)-$(RUBY_VERSION
)
44 ext
:= ext
/unicorn_http
45 c_files
:= $(ext
)/unicorn_http.c
$(ext
)/httpdate.c
$(wildcard $(ext
)/*.h
)
46 rl_files
:= $(wildcard $(ext
)/*.rl
)
47 base_bins
:= unicorn unicorn_rails
48 bins
:= $(addprefix bin
/, $(base_bins
))
49 man1_rdoc
:= $(addsuffix _1
, $(base_bins
))
50 man1_bins
:= $(addsuffix .1, $(base_bins
))
51 man1_paths
:= $(addprefix man
/man1
/, $(man1_bins
))
52 rb_files
:= $(bins
) $(shell find lib ext
-type f
-name
'*.rb')
53 inst_deps
:= $(c_files
) $(rb_files
) GNUmakefile
test/test_helper.rb
55 ragel
: $(ext
)/unicorn_http.c
56 $(ext
)/unicorn_http.c
: $(rl_files
)
57 cd
$(@D
) && $(RAGEL
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
58 $(ext
)/Makefile
: $(ext
)/extconf.rb
$(c_files
)
59 cd
$(@D
) && $(RUBY
) extconf.rb
60 $(ext
)/unicorn_http.
$(DLEXT
): $(ext
)/Makefile
62 lib
/unicorn_http.
$(DLEXT
): $(ext
)/unicorn_http.
$(DLEXT
)
65 http
: lib
/unicorn_http.
$(DLEXT
)
67 test-install
: $(test_prefix
)/.stamp
68 $(test_prefix
)/.stamp
: $(inst_deps
)
69 mkdir
-p
$(test_prefix
)/.ccache
70 tar cf
- $(inst_deps
) GIT-VERSION-GEN | \
71 (cd
$(test_prefix
) && tar xf
-)
72 $(MAKE
) -C
$(test_prefix
) clean
73 $(MAKE
) -C
$(test_prefix
) http shebang RUBY
="$(RUBY)"
76 # this is only intended to be run within $(test_prefix)
78 $(MRI
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
80 t_log
:= $(T_log
) $(T_n_log
)
82 @cat
$(t_log
) |
$(MRI
) test/aggregate.rb
85 test-exec
: $(wildcard test/exec
/test_
*.rb
)
86 test-unit
: $(wildcard test/unit
/test_
*.rb
)
87 $(slow_tests
): $(test_prefix
)/.stamp
88 @
$(MAKE
) $(shell $(awk_slow
) $@
)
90 test-integration
: $(test_prefix
)/.stamp
93 check: test test-integration
97 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
99 quiet_pre
= @echo
'* $(arg)$(extra)';
100 quiet_post
= >$(t
) 2>&1 && $(check_test
)
102 # we can't rely on -o pipefail outside of bash 3+,
103 # so we use a stamp file to indicate success and
104 # have rm fail if the stamp didn't get created
105 stamp
= $@
$(log_suffix
).ok
106 quiet_pre
= @echo
$(RUBY
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
107 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
108 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
111 # not all systems have setsid(8), we need it because we spam signals
112 # stupidly in some tests...
113 rb_setsid
:= $(RUBY
) -e
'Process.setsid' -e
'exec *ARGV'
115 # TRACER='strace -f -o $(t).strace -s 100000'
116 run_test
= $(quiet_pre
) \
117 $(rb_setsid
) $(TRACER
) $(RUBY
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
118 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
120 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
121 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
122 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
123 %.n
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
124 %.n
: $(test_prefix
)/.stamp
128 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
129 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
130 $(T
): export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
131 $(T
): $(test_prefix
)/.stamp
134 install: $(bins
) $(ext
)/unicorn_http.c
136 $(RM
) lib
/unicorn_http.
$(DLEXT
)
137 $(RM
) -r .install-tmp
139 cp
-p bin
/* .install-tmp
142 mv .install-tmp
/* bin
/
143 $(RM
) -r .install-tmp
146 setup_rb_files
:= .config InstalledFiles
147 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
150 -$(MAKE
) -C
$(ext
) clean
151 -$(MAKE
) -C Documentation
clean
152 $(RM
) $(ext
)/Makefile lib
/unicorn_http.
$(DLEXT
)
153 $(RM
) $(setup_rb_files
) $(t_log
)
154 $(RM
) -r
$(test_prefix
) man
157 $(MAKE
) -C Documentation install-
$@
159 pkg_extra
:= GIT-VERSION-FILE lib
/unicorn
/version.rb ChangeLog LATEST NEWS \
160 $(ext
)/unicorn_http.c
$(man1_paths
)
162 ChangeLog
: GIT-VERSION-FILE .wrongdoc.yml
165 .manifest
: ChangeLog
$(ext
)/unicorn_http.c man
166 (git ls-files
&& for i in
$@
$(pkg_extra
); do echo
$$i; done
) | \
168 cmp
$@
+ $@ || mv
$@
+ $@
171 doc
: .document
$(ext
)/unicorn_http.c man html .wrongdoc.yml
172 for i in
$(man1_rdoc
); do echo
> $$i; done
173 find bin lib
-type f
-name
'*.rbc' -exec
rm -f
'{}' ';'
176 install -m644 COPYING doc
/COPYING
177 install -m644
$(shell LC_ALL
=C grep
'^[A-Z]' .document
) doc
/
178 install -m644
$(man1_paths
) doc
/
179 tar cf
- $$(git ls-files examples
/) |
(cd doc
&& tar xf
-)
182 # publishes docs to http://unicorn.bogomips.org
186 find doc
/images
-type f | \
187 TZ
=UTC xargs touch
-d
'1970-01-01 00:00:02' doc
/rdoc.css
189 chmod
644 $$(find doc
-type f
)
190 $(RSYNC
) -av doc
/ unicorn.bogomips.org
:/srv
/unicorn
/
191 git ls-files | xargs touch
193 # Create gzip variants of the same timestamp as the original so nginx
194 # "gzip_static on" can serve the gzipped versions directly.
195 doc_gz
: docs
= $(shell find doc
-type f
! -regex
'^.*\.\(gif\|jpg\|png\|gz\)$$')
197 for i in
$(docs
); do \
198 gzip
--rsyncable
-9 < $$i > $$i.gz
; touch
-r
$$i $$i.gz
; done
203 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
204 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
205 release_notes
:= release_notes-
$(VERSION
)
206 release_changes
:= release_changes-
$(VERSION
)
208 release-notes
: $(release_notes
)
209 release-changes
: $(release_changes
)
211 wrongdoc release_changes
> $@
+
212 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
214 wrongdoc release_notes
> $@
+
215 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
217 # ensures we're actually on the tagged $(VERSION), only used for release
219 test x
"$(shell umask)" = x0022
220 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
221 git diff-index
--quiet HEAD^
0
222 test `git rev-parse --verify HEAD^0` = \
223 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
226 git ls-tree
-r HEAD | awk
'/^100644 / {print $$NF}' | xargs chmod
644
227 git ls-tree
-r HEAD | awk
'/^100755 / {print $$NF}' | xargs chmod
755
231 install-gem
: $(pkggem
)
232 gem
install $(CURDIR
)/$<
234 $(pkggem
): .manifest fix-perms
235 gem build
$(rfpackage
).gemspec
239 $(pkgtgz
): distdir
= $(basename $@
)
240 $(pkgtgz
): HEAD
= v
$(VERSION
)
241 $(pkgtgz
): .manifest fix-perms
242 @
test -n
"$(distdir)"
245 tar cf
- $$(cat .manifest
) |
(cd
$(distdir
) && tar xf
-)
246 cd pkg
&& tar cf
- $(basename $(@F
)) | gzip
-9 > $(@F
)+
249 package
: $(pkgtgz
) $(pkggem
)
251 release
: verify package
$(release_notes
) $(release_changes
)
252 # make tgz release on RubyForge
253 rubyforge add_release
-f
-n
$(release_notes
) -a
$(release_changes
) \
254 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkgtgz
)
255 # push gem to Gemcutter
257 # in case of gem downloads from RubyForge releases page
258 -rubyforge add_file \
259 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkggem
)
260 $(RAKE
) fm_update VERSION
=$(VERSION
)
262 gem install-gem
: GIT-VERSION-FILE
263 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
266 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) man