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 test-all
: test test-integration
96 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
98 quiet_pre
= @echo
'* $(arg)$(extra)';
99 quiet_post
= >$(t
) 2>&1 && $(check_test
)
101 # we can't rely on -o pipefail outside of bash 3+,
102 # so we use a stamp file to indicate success and
103 # have rm fail if the stamp didn't get created
104 stamp
= $@
$(log_suffix
).ok
105 quiet_pre
= @echo
$(RUBY
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
106 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
107 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
110 # not all systems have setsid(8), we need it because we spam signals
111 # stupidly in some tests...
112 rb_setsid
:= $(RUBY
) -e
'Process.setsid' -e
'exec *ARGV'
114 # TRACER='strace -f -o $(t).strace -s 100000'
115 run_test
= $(quiet_pre
) \
116 $(rb_setsid
) $(TRACER
) $(RUBY
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
117 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
119 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
120 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
121 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
122 %.n
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
123 %.n
: $(test_prefix
)/.stamp
127 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
128 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
129 $(T
): export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
130 $(T
): $(test_prefix
)/.stamp
133 install: $(bins
) $(ext
)/unicorn_http.c
135 $(RM
) lib
/unicorn_http.
$(DLEXT
)
136 $(RM
) -r .install-tmp
138 cp
-p bin
/* .install-tmp
141 mv .install-tmp
/* bin
/
142 $(RM
) -r .install-tmp
145 setup_rb_files
:= .config InstalledFiles
146 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
149 -$(MAKE
) -C
$(ext
) clean
150 -$(MAKE
) -C Documentation
clean
151 $(RM
) $(ext
)/Makefile lib
/unicorn_http.
$(DLEXT
)
152 $(RM
) $(setup_rb_files
) $(t_log
)
153 $(RM
) -r
$(test_prefix
) man
156 $(MAKE
) -C Documentation install-
$@
158 pkg_extra
:= GIT-VERSION-FILE lib
/unicorn
/version.rb ChangeLog LATEST NEWS \
159 $(ext
)/unicorn_http.c
$(man1_paths
)
161 ChangeLog
: GIT-VERSION-FILE .wrongdoc.yml
164 .manifest
: ChangeLog
$(ext
)/unicorn_http.c man
165 (git ls-files
&& for i in
$@
$(pkg_extra
); do echo
$$i; done
) | \
167 cmp
$@
+ $@ || mv
$@
+ $@
170 doc
: .document
$(ext
)/unicorn_http.c man html .wrongdoc.yml
171 for i in
$(man1_rdoc
); do echo
> $$i; done
172 find bin lib
-type f
-name
'*.rbc' -exec
rm -f
'{}' ';'
175 install -m644 COPYING doc
/COPYING
176 install -m644
$(shell LC_ALL
=C grep
'^[A-Z]' .document
) doc
/
177 install -m644
$(man1_paths
) doc
/
178 tar cf
- $$(git ls-files examples
/) |
(cd doc
&& tar xf
-)
181 # publishes docs to http://unicorn.bogomips.org
185 find doc
/images
-type f | \
186 TZ
=UTC xargs touch
-d
'1970-01-01 00:00:02' doc
/rdoc.css
188 chmod
644 $$(find doc
-type f
)
189 $(RSYNC
) -av doc
/ unicorn.bogomips.org
:/srv
/unicorn
/
190 git ls-files | xargs touch
192 # Create gzip variants of the same timestamp as the original so nginx
193 # "gzip_static on" can serve the gzipped versions directly.
194 doc_gz
: docs
= $(shell find doc
-type f
! -regex
'^.*\.\(gif\|jpg\|png\|gz\)$$')
196 for i in
$(docs
); do \
197 gzip
--rsyncable
-9 < $$i > $$i.gz
; touch
-r
$$i $$i.gz
; done
202 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
203 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
204 release_notes
:= release_notes-
$(VERSION
)
205 release_changes
:= release_changes-
$(VERSION
)
207 release-notes
: $(release_notes
)
208 release-changes
: $(release_changes
)
210 wrongdoc release_changes
> $@
+
211 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
213 wrongdoc release_notes
> $@
+
214 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
216 # ensures we're actually on the tagged $(VERSION), only used for release
218 test x
"$(shell umask)" = x0022
219 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
220 git diff-index
--quiet HEAD^
0
221 test `git rev-parse --verify HEAD^0` = \
222 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
225 git ls-tree
-r HEAD | awk
'/^100644 / {print $$NF}' | xargs chmod
644
226 git ls-tree
-r HEAD | awk
'/^100755 / {print $$NF}' | xargs chmod
755
230 install-gem
: $(pkggem
)
231 gem
install $(CURDIR
)/$<
233 $(pkggem
): .manifest fix-perms
234 gem build
$(rfpackage
).gemspec
238 $(pkgtgz
): distdir
= $(basename $@
)
239 $(pkgtgz
): HEAD
= v
$(VERSION
)
240 $(pkgtgz
): .manifest fix-perms
241 @
test -n
"$(distdir)"
244 tar cf
- $$(cat .manifest
) |
(cd
$(distdir
) && tar xf
-)
245 cd pkg
&& tar cf
- $(basename $(@F
)) | gzip
-9 > $(@F
)+
248 package
: $(pkgtgz
) $(pkggem
)
250 release
: verify package
$(release_notes
) $(release_changes
)
251 # make tgz release on RubyForge
252 rubyforge add_release
-f
-n
$(release_notes
) -a
$(release_changes
) \
253 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkgtgz
)
254 # push gem to Gemcutter
256 # in case of gem downloads from RubyForge releases page
257 -rubyforge add_file \
258 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkggem
)
259 $(RAKE
) fm_update VERSION
=$(VERSION
)
261 gem install-gem
: GIT-VERSION-FILE
262 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
265 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) man