test_server: drop early_hints test
[unicorn.git] / GNUmakefile
blobeab90829d90919ed7cac0bb27d6a39b6ddcdeeb5
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all:: test
4 RLFLAGS = -G2
6 MRI = ruby
7 RUBY = ruby
8 RAKE = rake
9 RAGEL = ragel
10 RSYNC = rsync
11 OLDDOC = olddoc
12 RDOC = rdoc
13 INSTALL = install
15 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
16 @./GIT-VERSION-GEN
17 -include GIT-VERSION-FILE
18 -include local.mk
19 ruby_bin := $(shell which $(RUBY))
20 ifeq ($(DLEXT),) # "so" for Linux
21 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts RbConfig::CONFIG["DLEXT"]')
22 endif
23 ifeq ($(RUBY_VERSION),)
24 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
25 endif
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:
46 @>>$@
47 $(ext_dir) $(tmp_bin) man/man1 doc/man1 pkg t/trash:
48 @mkdir -p $@
49 $(ext_pfx)/$(ext)/%: $(ext)/% | $(ext_dir)
50 $(INSTALL) -m 644 $< $@
51 $(ext_pfx)/$(ext)/Makefile: $(ext)/extconf.rb | $(ext_dir)
52 $(RM) -f $(@D)/*.o
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
57 $(MAKE) -C $(@D)
58 lib := $(CURDIR)/lib:$(CURDIR)/$(ext_pfx)/$(ext)
59 http build: $(ext_dl)
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)
84 mv $@.$(pid) $@
86 bins: $(tmp_bins)
88 t_log := $(T_log) $(T_n_log)
89 test: $(T) $(T_n) test-prove
90 @cat $(t_log) | $(MRI) test/aggregate.rb
91 @$(RM) $(t_log)
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)
104 SH_TEST_OPTS =
105 ifdef V
106 ifeq ($(V),2)
107 SH_TEST_OPTS += --trace
108 else
109 SH_TEST_OPTS += --verbose
110 endif
111 endif
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
126 echo '*' >$@
128 dependencies := curl
129 deps := $(addprefix t/.dep+,$(dependencies))
130 $(deps): dep_bin = $(lastword $(subst +, ,$@))
131 $(deps):
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; }
135 @mv $@.$(pid) $@
136 dep: $(deps)
138 t/random_blob:
139 dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
140 mv $@.$(pid) $@
142 test-integration: $(T_sh)
144 test-prove:
145 prove -vw
147 check: test-require test test-integration
148 test-all: check
150 TEST_OPTS = -v
151 check_test = grep '0 failures, 0 errors' $(t) >/dev/null
152 ifndef V
153 quiet_pre = @echo '* $(arg)$(extra)';
154 quiet_post = >$(t) 2>&1 && $(check_test)
155 else
156 # we can't rely on -o pipefail outside of bash 3+,
157 # so we use a stamp file to indicate success and
158 # have rm fail if the stamp didn't get created
159 stamp = $@$(log_suffix).ok
160 quiet_pre = @echo $(RUBY) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
161 quiet_post = && > $(stamp) )2>&1 | tee $(t); \
162 rm $(stamp) 2>/dev/null && $(check_test)
163 endif
165 # not all systems have setsid(8), we need it because we spam signals
166 # stupidly in some tests...
167 rb_setsid := $(RUBY) -e 'Process.setsid' -e 'exec *ARGV'
169 # TRACER='strace -f -o $(t).strace -s 100000'
170 run_test = $(quiet_pre) \
171 $(rb_setsid) $(TRACER) $(RUBY) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
172 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
174 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
175 %.n: t = $(subst .n,$(log_suffix),$@)
176 %.n: export PATH := $(CURDIR)/$(tmp_bin):$(PATH)
177 %.n: export RUBYLIB := $(lib):$(RUBYLIB)
178 %.n: $(test_prereq)
179 $(run_test)
181 $(T): arg = $@
182 $(T): t = $(subst .rb,$(log_suffix),$@)
183 $(T): export PATH := $(CURDIR)/$(tmp_bin):$(PATH)
184 $(T): export RUBYLIB := $(lib):$(RUBYLIB)
185 $(T): $(test_prereq)
186 $(run_test)
188 install: $(bins) $(ext)/unicorn_http.c
189 $(prep_setup_rb)
190 $(RM) -r .install-tmp
191 mkdir .install-tmp
192 cp -p bin/* .install-tmp
193 $(RUBY) setup.rb all
194 $(RM) $^
195 mv .install-tmp/* bin/
196 $(RM) -r .install-tmp
197 $(prep_setup_rb)
199 setup_rb_files := .config InstalledFiles
200 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
202 clean:
203 -$(MAKE) -C $(ext) clean
204 $(RM) $(ext)/Makefile
205 $(RM) $(setup_rb_files) $(t_log)
206 $(RM) -r $(ext_pfx) man t/trash
207 $(RM) $(html1)
209 man1 := $(addprefix Documentation/, unicorn.1 unicorn_rails.1)
210 html1 := $(addsuffix .html, $(man1))
211 man : $(man1) | man/man1
212 $(INSTALL) -m 644 $(man1) man/man1
214 html : $(html1) | doc/man1
215 $(INSTALL) -m 644 $(html1) doc/man1
217 %.1.html: %.1
218 $(OLDDOC) man2html -o $@ ./$<
220 pkg_extra := GIT-VERSION-FILE lib/unicorn/version.rb LATEST NEWS \
221 $(ext)/unicorn_http.c $(man1_paths)
223 NEWS:
224 $(OLDDOC) prepare
226 .manifest: $(ext)/unicorn_http.c man NEWS
227 (git ls-files && for i in $@ $(pkg_extra); do echo $$i; done) | \
228 LC_ALL=C sort > $@+
229 cmp $@+ $@ || mv $@+ $@
230 $(RM) $@+
232 PLACEHOLDERS = $(man1_rdoc)
233 doc: .document $(ext)/unicorn_http.c man html .olddoc.yml $(PLACEHOLDERS)
234 find bin lib -type f -name '*.rbc' -exec rm -f '{}' ';'
235 $(RM) -r doc
236 $(OLDDOC) prepare
237 $(RDOC) -f dark216
238 $(OLDDOC) merge
239 $(INSTALL) -m 644 COPYING doc/COPYING
240 $(INSTALL) -m 644 NEWS.atom.xml doc/NEWS.atom.xml
241 $(INSTALL) -m 644 $(shell LC_ALL=C grep '^[A-Z]' .document) doc/
242 $(INSTALL) -m 644 $(man1_paths) doc/
243 tar cf - $$(git ls-files examples/) | (cd doc && tar xf -)
245 # publishes docs to https://yhbt.net/unicorn/
246 publish_doc:
247 -git set-file-times
248 $(MAKE) doc
249 $(MAKE) doc_gz
250 chmod 644 $$(find doc -type f)
251 $(RSYNC) -av doc/ yhbt.net:/srv/yhbt/unicorn/ \
252 --exclude index.html* --exclude created.rid*
253 git ls-files | xargs touch
255 # Create gzip variants of the same timestamp as the original so nginx
256 # "gzip_static on" can serve the gzipped versions directly.
257 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.gz$$')
258 doc_gz:
259 for i in $(docs); do \
260 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
262 ifneq ($(VERSION),)
263 rfpackage := unicorn
264 pkggem := pkg/$(rfpackage)-$(VERSION).gem
265 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
267 # ensures we're actually on the tagged $(VERSION), only used for release
268 verify:
269 test x"$(shell umask)" = x0022
270 git rev-parse --verify refs/tags/v$(VERSION)^{}
271 git diff-index --quiet HEAD^0
272 test `git rev-parse --verify HEAD^0` = \
273 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
275 fix-perms:
276 git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
277 git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
279 gem: $(pkggem)
281 install-gem: $(pkggem)
282 gem install --local $(CURDIR)/$<
284 $(pkggem): .manifest fix-perms | pkg
285 gem build $(rfpackage).gemspec
286 mv $(@F) $@
288 $(pkgtgz): distdir = $(basename $@)
289 $(pkgtgz): HEAD = v$(VERSION)
290 $(pkgtgz): .manifest fix-perms
291 @test -n "$(distdir)"
292 $(RM) -r $(distdir)
293 mkdir -p $(distdir)
294 tar cf - $$(cat .manifest) | (cd $(distdir) && tar xf -)
295 cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
296 mv $@+ $@
298 package: $(pkgtgz) $(pkggem)
300 release: verify package
301 # push gem to Gemcutter
302 gem push $(pkggem)
303 else
304 gem install-gem: GIT-VERSION-FILE
305 $(MAKE) $@ VERSION=$(GIT_VERSION)
306 endif
308 $(PLACEHOLDERS):
309 echo olddoc_placeholder > $@
311 check-warnings:
312 @(for i in $$(git ls-files '*.rb' bin | grep -v '^setup\.rb$$'); \
313 do $(RUBY) --disable-gems -d -W2 -c \
314 $$i; done) | grep -v '^Syntax OK$$' || :
316 .PHONY: .FORCE-GIT-VERSION-FILE doc $(T) $(slow_tests) man $(T_sh) clean