1 # use GNU Make to run tests in parallel, and without depending on RubyGems
15 GIT-VERSION-FILE
: .FORCE-GIT-VERSION-FILE
17 -include GIT-VERSION-FILE
19 ruby_bin
:= $(shell which
$(RUBY
))
20 ifeq ($(DLEXT
),) # "so" for Linux
21 DLEXT
:= $(shell $(RUBY
) -rrbconfig
-e
'puts RbConfig::CONFIG["DLEXT"]')
23 ifeq ($(RUBY_VERSION
),)
24 RUBY_VERSION
:= $(shell $(RUBY
) -e
'puts RUBY_VERSION')
27 RUBY_ENGINE
:= $(shell $(RUBY
) -e
'puts((RUBY_ENGINE rescue "ruby"))')
29 # we should never package more than one ext to avoid DSO proliferation:
30 # https://udrepper.livejournal.com/8790.html
31 ext
:= $(firstword $(wildcard ext
/*))
33 ragel
: $(ext
)/unicorn_http.c
35 rl_files
:= $(wildcard $(ext
)/*.rl
)
36 ragel
: $(ext
)/unicorn_http.c
37 $(ext
)/unicorn_http.c
: $(rl_files
)
38 cd
$(@D
) && $(RAGEL
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
39 ext_pfx
:= test/$(RUBY_ENGINE
)-$(RUBY_VERSION
)
40 tmp_bin
:= $(ext_pfx
)/bin
41 ext_h
:= $(wildcard $(ext
)/*/*.h
$(ext
)/*.h
)
42 ext_src
:= $(sort $(wildcard $(ext
)/*.c
) $(ext_h
) $(ext
)/unicorn_http.c
)
43 ext_pfx_src
:= $(addprefix $(ext_pfx
)/,$(ext_src
))
44 ext_dir
:= $(ext_pfx
)/$(ext
)
45 $(ext
)/extconf.rb
: $(wildcard $(ext
)/*.h
)
47 $(ext_dir
) $(tmp_bin
) man
/man1 doc
/man1 pkg t
/trash
:
49 $(ext_pfx
)/$(ext
)/%: $(ext
)/% |
$(ext_dir
)
50 $(INSTALL
) -m
644 $< $@
51 $(ext_pfx
)/$(ext
)/Makefile
: $(ext
)/extconf.rb
$(ext_h
) |
$(ext_dir
)
53 cd
$(@D
) && $(RUBY
) $(CURDIR
)/$(ext
)/extconf.rb
$(EXTCONF_ARGS
)
54 ext_sfx
:= _ext.
$(DLEXT
)
55 ext_dl
:= $(ext_pfx
)/$(ext
)/$(notdir $(ext
)_ext.
$(DLEXT
))
56 $(ext_dl
): $(ext_src
) $(ext_pfx_src
) $(ext_pfx
)/$(ext
)/Makefile
58 lib
:= $(CURDIR
)/lib
:$(CURDIR
)/$(ext_pfx
)/$(ext
)
60 $(ext_pfx
)/$(ext
)/unicorn_http.c
: ext
/unicorn_http
/unicorn_http.c
62 # dunno how to implement this as concisely in Ruby, and hell, I love awk
63 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
65 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
66 test/unit
/test_signals.rb
test/unit
/test_upload.rb
67 log_suffix
= .
$(RUBY_ENGINE
).
$(RUBY_VERSION
).log
68 T
:= $(filter-out $(slow_tests
), $(wildcard test/*/test*.rb
))
69 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
70 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
71 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
73 base_bins
:= unicorn unicorn_rails
74 bins
:= $(addprefix bin
/, $(base_bins
))
75 man1_rdoc
:= $(addsuffix _1
, $(base_bins
))
76 man1_bins
:= $(addsuffix .1, $(base_bins
))
77 man1_paths
:= $(addprefix man
/man1
/, $(man1_bins
))
78 tmp_bins
= $(addprefix $(tmp_bin
)/, unicorn unicorn_rails
)
79 pid
:= $(shell echo
$$PPID)
81 $(tmp_bin
)/%: bin
/% |
$(tmp_bin
)
82 $(INSTALL
) -m
755 $< $@.
$(pid
)
83 $(MRI
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.
$(pid
)
88 t_log
:= $(T_log
) $(T_n_log
)
90 @cat
$(t_log
) |
$(MRI
) test/aggregate.rb
93 test-exec
: $(wildcard test/exec
/test_
*.rb
)
94 test-unit
: $(wildcard test/unit
/test_
*.rb
)
95 $(slow_tests
): $(ext_dl
)
96 @
$(MAKE
) $(shell $(awk_slow
) $@
)
98 # ensure we can require just the HTTP parser without the rest of unicorn
99 test-require
: $(ext_dl
)
100 $(RUBY
) --disable-gems
-I
$(ext_pfx
)/$(ext
) -runicorn_http
-e Unicorn
102 test_prereq
:= $(tmp_bins
) $(ext_dl
)
107 SH_TEST_OPTS
+= --trace
109 SH_TEST_OPTS
+= --verbose
113 # do we trust Ruby behavior to be stable? some tests are
114 # (mostly) POSIX sh (not bash or ksh93, so no "set -o pipefail"
115 # TRACER = strace -f -o $(t_pfx).strace -s 100000
116 # TRACER = /usr/bin/time -o $(t_pfx).time
117 t_pfx
= trash
/$@
-$(RUBY_ENGINE
)-$(RUBY_VERSION
)
118 T_sh
= $(wildcard t
/t
[0-9][0-9][0-9][0-9]-*.sh
)
119 $(T_sh
): export RUBY
:= $(RUBY
)
120 $(T_sh
): export PATH
:= $(CURDIR
)/$(tmp_bin
):$(PATH
)
121 $(T_sh
): export RUBYLIB
:= $(lib
):$(RUBYLIB
)
122 $(T_sh
): dep
$(test_prereq
) t
/random_blob t
/trash
/.gitignore
123 cd t
&& $(TRACER
) $(SHELL
) $(SH_TEST_OPTS
) $(@F
) $(TEST_OPTS
)
125 t
/trash
/.gitignore
: | t
/trash
128 dependencies
:= socat curl
129 deps
:= $(addprefix t
/.dep
+,$(dependencies
))
130 $(deps
): dep_bin
= $(lastword
$(subst +, ,$@
))
132 @which
$(dep_bin
) > $@.
$(pid
) 2>/dev
/null ||
:
133 @
test -s
$@.
$(pid
) || \
134 { echo
>&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit
1; }
139 dd if
=/dev
/urandom bs
=1M count
=30 of
=$@.
$(pid
)
142 test-integration
: $(T_sh
)
144 check: test-require
test test-integration
148 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
150 quiet_pre
= @echo
'* $(arg)$(extra)';
151 quiet_post
= >$(t
) 2>&1 && $(check_test
)
153 # we can't rely on -o pipefail outside of bash 3+,
154 # so we use a stamp file to indicate success and
155 # have rm fail if the stamp didn't get created
156 stamp
= $@
$(log_suffix
).ok
157 quiet_pre
= @echo
$(RUBY
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
158 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
159 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
162 # not all systems have setsid(8), we need it because we spam signals
163 # stupidly in some tests...
164 rb_setsid
:= $(RUBY
) -e
'Process.setsid' -e
'exec *ARGV'
166 # TRACER='strace -f -o $(t).strace -s 100000'
167 run_test
= $(quiet_pre
) \
168 $(rb_setsid
) $(TRACER
) $(RUBY
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
169 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
171 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
172 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
173 %.n
: export PATH
:= $(CURDIR
)/$(tmp_bin
):$(PATH
)
174 %.n
: export RUBYLIB
:= $(lib
):$(RUBYLIB
)
179 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
180 $(T
): export PATH
:= $(CURDIR
)/$(tmp_bin
):$(PATH
)
181 $(T
): export RUBYLIB
:= $(lib
):$(RUBYLIB
)
185 install: $(bins
) $(ext
)/unicorn_http.c
187 $(RM
) -r .install-tmp
189 cp
-p bin
/* .install-tmp
192 mv .install-tmp
/* bin
/
193 $(RM
) -r .install-tmp
196 setup_rb_files
:= .config InstalledFiles
197 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
200 -$(MAKE
) -C
$(ext
) clean
201 $(RM
) $(ext
)/Makefile
202 $(RM
) $(setup_rb_files
) $(t_log
)
203 $(RM
) -r
$(ext_pfx
) man t
/trash
206 man1
:= $(addprefix Documentation
/, unicorn
.1 unicorn_rails
.1)
207 html1
:= $(addsuffix .html
, $(man1
))
208 man
: $(man1
) | man
/man1
209 $(INSTALL
) -m
644 $(man1
) man
/man1
211 html
: $(html1
) | doc
/man1
212 $(INSTALL
) -m
644 $(html1
) doc
/man1
215 $(OLDDOC
) man2html
-o
$@ .
/$<
217 pkg_extra
:= GIT-VERSION-FILE lib
/unicorn
/version.rb LATEST NEWS \
218 $(ext
)/unicorn_http.c
$(man1_paths
)
223 .manifest
: $(ext
)/unicorn_http.c man NEWS
224 (git ls-files
&& for i in
$@
$(pkg_extra
); do echo
$$i; done
) | \
226 cmp
$@
+ $@ || mv
$@
+ $@
229 PLACEHOLDERS
= $(man1_rdoc
)
230 doc
: .document
$(ext
)/unicorn_http.c man html .olddoc.yml
$(PLACEHOLDERS
)
231 find bin lib
-type f
-name
'*.rbc' -exec
rm -f
'{}' ';'
236 $(INSTALL
) -m
644 COPYING doc
/COPYING
237 $(INSTALL
) -m
644 NEWS.atom.xml doc
/NEWS.atom.xml
238 $(INSTALL
) -m
644 $(shell LC_ALL
=C grep
'^[A-Z]' .document
) doc
/
239 $(INSTALL
) -m
644 $(man1_paths
) doc
/
240 tar cf
- $$(git ls-files examples
/) |
(cd doc
&& tar xf
-)
242 # publishes docs to https://yhbt.net/unicorn/
247 chmod
644 $$(find doc
-type f
)
248 $(RSYNC
) -av doc
/ yhbt.net
:/srv
/yhbt
/unicorn
/
249 git ls-files | xargs touch
251 # Create gzip variants of the same timestamp as the original so nginx
252 # "gzip_static on" can serve the gzipped versions directly.
253 doc_gz
: docs
= $(shell find doc
-type f
! -regex
'^.*\.gz$$')
255 for i in
$(docs
); do \
256 gzip
--rsyncable
-9 < $$i > $$i.gz
; touch
-r
$$i $$i.gz
; done
260 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
261 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
263 # ensures we're actually on the tagged $(VERSION), only used for release
265 test x
"$(shell umask)" = x0022
266 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
267 git diff-index
--quiet HEAD^
0
268 test `git rev-parse --verify HEAD^0` = \
269 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
272 git ls-tree
-r HEAD | awk
'/^100644 / {print $$NF}' | xargs chmod
644
273 git ls-tree
-r HEAD | awk
'/^100755 / {print $$NF}' | xargs chmod
755
277 install-gem
: $(pkggem
)
278 gem
install --local
$(CURDIR
)/$<
280 $(pkggem
): .manifest fix-perms | pkg
281 gem build
$(rfpackage
).gemspec
284 $(pkgtgz
): distdir
= $(basename $@
)
285 $(pkgtgz
): HEAD
= v
$(VERSION
)
286 $(pkgtgz
): .manifest fix-perms
287 @
test -n
"$(distdir)"
290 tar cf
- $$(cat .manifest
) |
(cd
$(distdir
) && tar xf
-)
291 cd pkg
&& tar cf
- $(basename $(@F
)) | gzip
-9 > $(@F
)+
294 package
: $(pkgtgz
) $(pkggem
)
296 release
: verify package
297 # push gem to Gemcutter
300 gem install-gem
: GIT-VERSION-FILE
301 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
305 echo olddoc_placeholder
> $@
308 @
(for i in
$$(git ls-files
'*.rb' bin | grep
-v
'^setup\.rb$$'); \
309 do
$(RUBY
) --disable-gems
-d
-W2
-c \
310 $$i; done
) | grep
-v
'^Syntax OK$$' ||
:
312 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) man
$(T_sh
) clean