1 # use GNU Make to run tests in parallel, and without depending on RubyGems
16 GIT-VERSION-FILE
: .FORCE-GIT-VERSION-FILE
18 -include GIT-VERSION-FILE
20 ruby_bin
:= $(shell which
$(RUBY
))
21 ifeq ($(DLEXT
),) # "so" for Linux
22 DLEXT
:= $(shell $(RUBY
) -rrbconfig
-e
'puts RbConfig::CONFIG["DLEXT"]')
24 ifeq ($(RUBY_VERSION
),)
25 RUBY_VERSION
:= $(shell $(RUBY
) -e
'puts RUBY_VERSION')
28 RUBY_ENGINE
:= $(shell $(RUBY
) -e
'puts((RUBY_ENGINE rescue "ruby"))')
30 # we should never package more than one ext to avoid DSO proliferation:
31 # https://udrepper.livejournal.com/8790.html
32 ext
:= $(firstword $(wildcard ext
/*))
34 ragel
: $(ext
)/unicorn_http.c
36 rl_files
:= $(wildcard $(ext
)/*.rl
)
37 ragel
: $(ext
)/unicorn_http.c
38 $(ext
)/unicorn_http.c
: $(rl_files
)
39 cd
$(@D
) && $(RAGEL
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
40 ext_pfx
:= test/$(RUBY_ENGINE
)-$(RUBY_VERSION
)
41 tmp_bin
:= $(ext_pfx
)/bin
42 ext_h
:= $(wildcard $(ext
)/*/*.h
$(ext
)/*.h
)
43 ext_src
:= $(sort $(wildcard $(ext
)/*.c
) $(ext_h
) $(ext
)/unicorn_http.c
)
44 ext_pfx_src
:= $(addprefix $(ext_pfx
)/,$(ext_src
))
45 ext_dir
:= $(ext_pfx
)/$(ext
)
48 $(ext_dir
) $(tmp_bin
) man
/man1 doc
/man1 pkg t
/trash
:
50 $(ext_pfx
)/$(ext
)/%: $(ext
)/% |
$(ext_dir
)
51 $(INSTALL
) -m
644 $< $@
52 $(ext_pfx
)/$(ext
)/Makefile
: $(ext
)/extconf.rb |
$(ext_dir
)
54 cd
$(@D
) && $(RUBY
) $(CURDIR
)/$(ext
)/extconf.rb
$(EXTCONF_ARGS
)
55 ext_sfx
:= _ext.
$(DLEXT
)
56 ext_dl
:= $(ext_pfx
)/$(ext
)/$(notdir $(ext
)_ext.
$(DLEXT
))
57 $(ext_dl
): $(ext_src
) $(ext_pfx_src
) $(ext_pfx
)/$(ext
)/Makefile
59 lib
:= $(CURDIR
)/lib
:$(CURDIR
)/$(ext_pfx
)/$(ext
)
61 $(ext_pfx
)/$(ext
)/unicorn_http.c
: ext
/unicorn_http
/unicorn_http.c
63 # dunno how to implement this as concisely in Ruby, and hell, I love awk
64 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
66 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
67 test/unit
/test_signals.rb
test/unit
/test_upload.rb
68 log_suffix
= .
$(RUBY_ENGINE
).
$(RUBY_VERSION
).log
69 T
:= $(filter-out $(slow_tests
), $(wildcard test/*/test*.rb
))
70 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
71 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
72 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
74 base_bins
:= unicorn unicorn_rails
75 bins
:= $(addprefix bin
/, $(base_bins
))
76 man1_rdoc
:= $(addsuffix _1
, $(base_bins
))
77 man1_bins
:= $(addsuffix .1, $(base_bins
))
78 man1_paths
:= $(addprefix man
/man1
/, $(man1_bins
))
79 tmp_bins
= $(addprefix $(tmp_bin
)/, unicorn unicorn_rails
)
80 pid
:= $(shell echo
$$PPID)
83 $(tmp_bin
)/%: bin
/% |
$(tmp_bin
)
84 $(INSTALL
) -m
755 $< $@.
$(pid
)
85 $(MRI
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $@.
$(pid
)
90 t_log
:= $(T_log
) $(T_n_log
)
91 test: $(T
) $(T_n
) test-prove
92 @cat
$(t_log
) |
$(MRI
) test/aggregate.rb
95 test-exec
: $(wildcard test/exec
/test_
*.rb
)
96 test-unit
: $(wildcard test/unit
/test_
*.rb
)
97 $(slow_tests
): $(ext_dl
)
98 @
$(MAKE
) $(shell $(awk_slow
) $@
)
100 # ensure we can require just the HTTP parser without the rest of unicorn
101 test-require
: $(ext_dl
)
102 $(RUBY
) --disable-gems
-I
$(ext_pfx
)/$(ext
) -runicorn_http
-e Unicorn
104 test_prereq
:= $(tmp_bins
) $(ext_dl
)
109 SH_TEST_OPTS
+= --trace
111 SH_TEST_OPTS
+= --verbose
115 # do we trust Ruby behavior to be stable? some tests are
116 # (mostly) POSIX sh (not bash or ksh93, so no "set -o pipefail"
117 # TRACER = strace -f -o $(t_pfx).strace -s 100000
118 # TRACER = /usr/bin/time -o $(t_pfx).time
119 t_pfx
= trash
/$@
-$(RUBY_ENGINE
)-$(RUBY_VERSION
)
120 T_sh
= $(wildcard t
/t
[0-9][0-9][0-9][0-9]-*.sh
)
121 $(T_sh
): export RUBY
:= $(RUBY
)
122 $(T_sh
): export PATH
:= $(CURDIR
)/$(tmp_bin
):$(PATH
)
123 $(T_sh
): export RUBYLIB
:= $(lib
):$(RUBYLIB
)
124 $(T_sh
): dep
$(test_prereq
) t
/random_blob t
/trash
/.gitignore
125 cd t
&& $(TRACER
) $(SHELL
) $(SH_TEST_OPTS
) $(@F
) $(TEST_OPTS
)
127 t
/trash
/.gitignore
: | t
/trash
131 deps
:= $(addprefix t
/.dep
+,$(dependencies
))
132 $(deps
): dep_bin
= $(lastword
$(subst +, ,$@
))
134 @which
$(dep_bin
) > $@.
$(pid
) 2>/dev
/null ||
:
135 @
test -s
$@.
$(pid
) || \
136 { echo
>&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit
1; }
141 dd if
=/dev
/urandom bs
=1M count
=30 of
=$@.
$(pid
)
144 test-integration
: $(T_sh
)
146 test-prove
: t
/random_blob
149 check: test-require
test test-integration
153 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
155 quiet_pre
= @echo
'* $(arg)$(extra)';
156 quiet_post
= >$(t
) 2>&1 && $(check_test
)
158 # we can't rely on -o pipefail outside of bash 3+,
159 # so we use a stamp file to indicate success and
160 # have rm fail if the stamp didn't get created
161 stamp
= $@
$(log_suffix
).ok
162 quiet_pre
= @echo
$(RUBY
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
163 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
164 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
167 # not all systems have setsid(8), we need it because we spam signals
168 # stupidly in some tests...
169 rb_setsid
:= $(RUBY
) -e
'Process.setsid' -e
'exec *ARGV'
171 # TRACER='strace -f -o $(t).strace -s 100000'
172 run_test
= $(quiet_pre
) \
173 $(rb_setsid
) $(TRACER
) $(RUBY
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
174 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
176 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
177 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
178 %.n
: export PATH
:= $(CURDIR
)/$(tmp_bin
):$(PATH
)
179 %.n
: export RUBYLIB
:= $(lib
):$(RUBYLIB
)
184 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
185 $(T
): export PATH
:= $(CURDIR
)/$(tmp_bin
):$(PATH
)
186 $(T
): export RUBYLIB
:= $(lib
):$(RUBYLIB
)
190 install: $(bins
) $(ext
)/unicorn_http.c
192 $(RM
) -r .install-tmp
194 cp
-p bin
/* .install-tmp
197 mv .install-tmp
/* bin
/
198 $(RM
) -r .install-tmp
201 setup_rb_files
:= .config InstalledFiles
202 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
205 -$(MAKE
) -C
$(ext
) clean
206 $(RM
) $(ext
)/Makefile
207 $(RM
) $(setup_rb_files
) $(t_log
)
208 $(RM
) -r
$(ext_pfx
) man t
/trash
211 man1
:= $(addprefix Documentation
/, unicorn
.1 unicorn_rails
.1)
212 html1
:= $(addsuffix .html
, $(man1
))
213 man
: $(man1
) | man
/man1
214 $(INSTALL
) -m
644 $(man1
) man
/man1
216 html
: $(html1
) | doc
/man1
217 $(INSTALL
) -m
644 $(html1
) doc
/man1
220 $(OLDDOC
) man2html
-o
$@ .
/$<
222 pkg_extra
:= GIT-VERSION-FILE lib
/unicorn
/version.rb LATEST NEWS \
223 $(ext
)/unicorn_http.c
$(man1_paths
)
228 .manifest
: $(ext
)/unicorn_http.c man NEWS
229 (git ls-files
&& for i in
$@
$(pkg_extra
); do echo
$$i; done
) | \
231 cmp
$@
+ $@ || mv
$@
+ $@
234 PLACEHOLDERS
= $(man1_rdoc
)
235 doc
: .document
$(ext
)/unicorn_http.c man html .olddoc.yml
$(PLACEHOLDERS
)
236 find bin lib
-type f
-name
'*.rbc' -exec
rm -f
'{}' ';'
241 $(INSTALL
) -m
644 COPYING doc
/COPYING
242 $(INSTALL
) -m
644 NEWS.atom.xml doc
/NEWS.atom.xml
243 $(INSTALL
) -m
644 $(shell LC_ALL
=C grep
'^[A-Z]' .document
) doc
/
244 $(INSTALL
) -m
644 $(man1_paths
) doc
/
245 tar cf
- $$(git ls-files examples
/) |
(cd doc
&& tar xf
-)
247 # publishes docs to https://yhbt.net/unicorn/
252 chmod
644 $$(find doc
-type f
)
253 $(RSYNC
) -av doc
/ yhbt.net
:/srv
/yhbt
/unicorn
/ \
254 --exclude index.html
* --exclude created.rid
*
255 git ls-files | xargs touch
257 # Create gzip variants of the same timestamp as the original so nginx
258 # "gzip_static on" can serve the gzipped versions directly.
259 doc_gz
: docs
= $(shell find doc
-type f
! -regex
'^.*\.gz$$')
261 for i in
$(docs
); do \
262 gzip
--rsyncable
-9 < $$i > $$i.gz
; touch
-r
$$i $$i.gz
; done
266 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
267 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
269 # ensures we're actually on the tagged $(VERSION), only used for release
271 test x
"$(shell umask)" = x0022
272 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
273 git diff-index
--quiet HEAD^
0
274 test `git rev-parse --verify HEAD^0` = \
275 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
278 git ls-tree
-r HEAD | awk
'/^100644 / {print $$NF}' | xargs chmod
644
279 git ls-tree
-r HEAD | awk
'/^100755 / {print $$NF}' | xargs chmod
755
283 install-gem
: $(pkggem
)
284 gem
install --local
$(CURDIR
)/$<
286 $(pkggem
): .manifest fix-perms | pkg
287 gem build
$(rfpackage
).gemspec
290 $(pkgtgz
): distdir
= $(basename $@
)
291 $(pkgtgz
): HEAD
= v
$(VERSION
)
292 $(pkgtgz
): .manifest fix-perms
293 @
test -n
"$(distdir)"
296 tar cf
- $$(cat .manifest
) |
(cd
$(distdir
) && tar xf
-)
297 cd pkg
&& tar cf
- $(basename $(@F
)) | gzip
-9 > $(@F
)+
300 package
: $(pkgtgz
) $(pkggem
)
302 release
: verify package
303 # push gem to Gemcutter
306 gem install-gem
: GIT-VERSION-FILE
307 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
311 echo olddoc_placeholder
> $@
314 @
(for i in
$$(git ls-files
'*.rb' bin | grep
-v
'^setup\.rb$$'); \
315 do
$(RUBY
) --disable-gems
-d
-W2
-c \
316 $$i; done
) | grep
-v
'^Syntax OK$$' ||
:
318 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) man
$(T_sh
) clean