Fix log rotation being delayed in workers when idle
[unicorn.git] / GNUmakefile
blob6beed35822a6e02f9b8d4fa11690b79b1b37ff66
1 # use GNU Make to run tests in parallel, and without depending on Rubygems
2 all:: test
3 ruby = ruby
4 ragel = ragel
5 RLFLAGS = -G2
6 -include local.mk
7 ruby_bin := $(shell which $(ruby))
8 ifeq ($(DLEXT),) # "so" for Linux
9 DLEXT := $(shell $(ruby) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
10 endif
11 ifeq ($(RUBY_VERSION),)
12 RUBY_VERSION := $(shell $(ruby) -e 'puts RUBY_VERSION')
13 endif
15 # dunno how to implement this as concisely in Ruby, and hell, I love awk
16 awk_slow := awk '/def test_/{print FILENAME"--"$$2".n"}' 2>/dev/null
18 rails_vers := $(subst test/rails/app-,,$(wildcard test/rails/app-*))
19 slow_tests := test/unit/test_server.rb test/exec/test_exec.rb \
20 test/unit/test_signals.rb test/unit/test_upload.rb
21 log_suffix = .$(RUBY_VERSION).log
22 T_r := $(wildcard test/rails/test*.rb)
23 T := $(filter-out $(slow_tests) $(T_r), $(wildcard test/*/test*.rb))
24 T_n := $(shell $(awk_slow) $(slow_tests))
25 T_log := $(subst .rb,$(log_suffix),$(T))
26 T_n_log := $(subst .n,$(log_suffix),$(T_n))
27 T_r_log := $(subst .r,$(log_suffix),$(T_r))
28 test_prefix = $(CURDIR)/test/install-$(RUBY_VERSION)
30 ext := ext/unicorn/http11
31 c_files := $(addprefix $(ext)/,ext_help.h http11.c http11_parser.h)
32 rl_files := $(addprefix $(ext)/,http11_parser.rl http11_parser_common.rl)
33 rb_files := $(shell grep '^\(bin\|lib\)' Manifest)
34 inst_deps := $(c_files) $(rb_files)
36 ragel: $(ext)/http11_parser.h
37 $(ext)/http11_parser.h: $(rl_files)
38 cd $(@D) && $(ragel) http11_parser.rl -C $(RLFLAGS) -o $(@F)
39 $(ruby) -i -p -e '$$_.gsub!(%r{[ \t]*$$},"")' $@
40 $(ext)/Makefile: $(ext)/extconf.rb $(c_files)
41 cd $(@D) && $(ruby) extconf.rb
42 $(ext)/http11.$(DLEXT): $(ext)/Makefile
43 $(MAKE) -C $(@D)
44 lib/unicorn/http11.$(DLEXT): $(ext)/http11.$(DLEXT)
45 @mkdir -p lib
46 install -m644 $< $@
47 http11: lib/unicorn/http11.$(DLEXT)
49 $(test_prefix)/.stamp: $(inst_deps)
50 mkdir -p $(test_prefix)/.ccache
51 tar c bin ext lib GNUmakefile Manifest | (cd $(test_prefix) && tar x)
52 $(MAKE) -C $(test_prefix) clean
53 $(MAKE) -C $(test_prefix) http11 shebang
54 > $@
56 # this is only intended to be run within $(test_prefix)
57 shebang: bin/unicorn bin/unicorn_rails
58 $(ruby) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
60 t_log := $(T_log) $(T_n_log)
61 test: $(T) $(T_n)
62 @cat $(t_log) | $(ruby) test/aggregate.rb
63 @$(RM) $(t_log)
65 test-exec: $(wildcard test/exec/test_*.rb)
66 test-unit: $(wildcard test/unit/test_*.rb)
67 $(slow_tests): $(test_prefix)/.stamp
68 @$(MAKE) $(shell $(awk_slow) $@)
70 TEST_OPTS = -v
71 TEST_OPTS = -v
72 ifndef V
73 quiet_pre = @echo '* $(arg)$(extra)';
74 quiet_post = >$(t) 2>&1
75 else
76 # we can't rely on -o pipefail outside of bash 3+,
77 # so we use a stamp file to indicate success and
78 # have rm fail if the stamp didn't get created
79 stamp = $@$(log_suffix).ok
80 quiet_pre = @echo $(ruby) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
81 quiet_post = && > $(stamp) )>&2 | tee $(t); rm $(stamp) 2>/dev/null
82 endif
83 run_test = $(quiet_pre) setsid $(ruby) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
84 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
86 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
87 %.n: t = $(subst .n,$(log_suffix),$@)
88 %.n: export PATH := $(test_prefix)/bin:$(PATH)
89 %.n: export RUBYLIB := $(test_prefix)/lib:$(RUBYLIB)
90 %.n: $(test_prefix)/.stamp
91 $(run_test)
93 $(T): arg = $@
94 $(T): t = $(subst .rb,$(log_suffix),$@)
95 $(T): export PATH := $(test_prefix)/bin:$(PATH)
96 $(T): export RUBYLIB := $(test_prefix)/lib:$(RUBYLIB)
97 $(T): $(test_prefix)/.stamp
98 $(run_test)
100 install: bin/unicorn bin/unicorn_rails
101 $(prep_setup_rb)
102 $(RM) -r .install-tmp
103 mkdir .install-tmp
104 cp -p $^ .install-tmp
105 $(ruby) setup.rb all
106 $(RM) $^
107 mv $(addprefix .install-tmp/,$(^F)) bin/
108 $(RM) -r .install-tmp
109 $(prep_setup_rb)
111 setup_rb_files := .config InstalledFiles
112 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
114 clean:
115 -$(MAKE) -C $(ext) clean
116 $(RM) $(ext)/Makefile lib/unicorn/http11.$(DLEXT)
117 $(RM) $(setup_rb_files) $(t_log)
118 $(RM) -r $(test_prefix)
120 Manifest:
121 git ls-files > $@+
122 cmp $@+ $@ || mv $@+ $@
123 $(RM) -f $@+
125 # using rdoc 2.4.1
126 doc: .document
127 rdoc -Na -m README -t "$(shell sed -ne '1s/^= //p' README)"
129 rails_git_url = git://github.com/rails/rails.git
130 rails_git := vendor/rails.git
131 $(rails_git)/info/cloned-stamp:
132 git clone --mirror -q $(rails_git_url) $(rails_git)
133 > $@
135 rails_tests := $(addsuffix .r,$(addprefix $(T_r).,$(rails_vers)))
136 test-rails: $(rails_tests)
137 $(T_r).%.r: t = $(addsuffix $(log_suffix),$@)
138 $(T_r).%.r: rv = $(subst .r,,$(subst $(T_r).,,$@))
139 $(T_r).%.r: extra = ' 'v$(rv)
140 $(T_r).%.r: arg = $(T_r)
141 $(T_r).%.r: export PATH := $(test_prefix)/bin:$(PATH)
142 $(T_r).%.r: export RUBYLIB := $(test_prefix)/lib:$(RUBYLIB)
143 $(T_r).%.r: export UNICORN_RAILS_TEST_VERSION = $(rv)
144 $(T_r).%.r: export RAILS_GIT_REPO = $(CURDIR)/$(rails_git)
145 $(T_r).%.r: $(test_prefix)/.stamp $(rails_git)/info/cloned-stamp
146 $(run_test)
148 .PHONY: doc $(T) $(slow_tests) Manifest