1 # use GNU Make to run tests in parallel, and without depending on RubyGems
14 GIT-VERSION-FILE
: .FORCE-GIT-VERSION-FILE
16 -include GIT-VERSION-FILE
18 ruby_bin
:= $(shell which
$(RUBY
))
19 ifeq ($(DLEXT
),) # "so" for Linux
20 DLEXT
:= $(shell $(RUBY
) -rrbconfig
-e
'puts RbConfig::CONFIG["DLEXT"]')
22 ifeq ($(RUBY_VERSION
),)
23 RUBY_VERSION
:= $(shell $(RUBY
) -e
'puts RUBY_VERSION')
26 RUBY_ENGINE
:= $(shell $(RUBY
) -e
'puts((RUBY_ENGINE rescue "ruby"))')
30 # dunno how to implement this as concisely in Ruby, and hell, I love awk
31 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
33 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
34 test/unit
/test_signals.rb
test/unit
/test_upload.rb
35 log_suffix
= .
$(RUBY_ENGINE
).
$(RUBY_VERSION
).log
36 T
:= $(filter-out $(slow_tests
), $(wildcard test/*/test*.rb
))
37 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
38 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
39 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
40 test_prefix
= $(CURDIR
)/test/$(RUBY_ENGINE
)-$(RUBY_VERSION
)
42 ext
:= ext
/unicorn_http
43 c_files
:= $(ext
)/unicorn_http.c
$(ext
)/httpdate.c
$(wildcard $(ext
)/*.h
)
44 rl_files
:= $(wildcard $(ext
)/*.rl
)
45 base_bins
:= unicorn unicorn_rails
46 bins
:= $(addprefix bin
/, $(base_bins
))
47 man1_rdoc
:= $(addsuffix _1
, $(base_bins
))
48 man1_bins
:= $(addsuffix .1, $(base_bins
))
49 man1_paths
:= $(addprefix man
/man1
/, $(man1_bins
))
50 rb_files
:= $(bins
) $(shell find lib ext
-type f
-name
'*.rb')
51 inst_deps
:= $(c_files
) $(rb_files
) GNUmakefile
test/test_helper.rb
53 ragel
: $(ext
)/unicorn_http.c
54 $(ext
)/unicorn_http.c
: $(rl_files
)
55 cd
$(@D
) && $(RAGEL
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
56 $(ext
)/Makefile
: $(ext
)/extconf.rb
$(c_files
)
57 cd
$(@D
) && $(RUBY
) extconf.rb
58 $(ext
)/unicorn_http.
$(DLEXT
): $(ext
)/Makefile
60 http
: $(ext
)/unicorn_http.
$(DLEXT
)
62 test-install
: $(test_prefix
)/.stamp
63 $(test_prefix
)/.stamp
: $(inst_deps
)
64 mkdir
-p
$(test_prefix
)/.ccache
65 tar cf
- $(inst_deps
) GIT-VERSION-GEN | \
66 (cd
$(test_prefix
) && tar xf
-)
67 $(MAKE
) -C
$(test_prefix
) clean
68 $(MAKE
) -C
$(test_prefix
) http shebang RUBY
="$(RUBY)"
71 # this is only intended to be run within $(test_prefix)
73 $(MRI
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
75 t_log
:= $(T_log
) $(T_n_log
)
77 @cat
$(t_log
) |
$(MRI
) test/aggregate.rb
80 test-exec
: $(wildcard test/exec
/test_
*.rb
)
81 test-unit
: $(wildcard test/unit
/test_
*.rb
)
82 $(slow_tests
): $(test_prefix
)/.stamp
83 @
$(MAKE
) $(shell $(awk_slow
) $@
)
85 # ensure we can require just the HTTP parser without the rest of unicorn
86 test-require
: $(ext
)/unicorn_http.
$(DLEXT
)
87 $(RUBY
) --disable-gems
-I
$(ext
) -runicorn_http
-e Unicorn
89 test-integration
: $(test_prefix
)/.stamp
92 check: test-require
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
) -r .install-tmp
137 cp
-p bin
/* .install-tmp
140 mv .install-tmp
/* bin
/
141 $(RM
) -r .install-tmp
144 setup_rb_files
:= .config InstalledFiles
145 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
148 -$(MAKE
) -C
$(ext
) clean
149 -$(MAKE
) -C Documentation
clean
150 $(RM
) $(ext
)/Makefile
151 $(RM
) $(setup_rb_files
) $(t_log
)
152 $(RM
) -r
$(test_prefix
) man
155 $(MAKE
) -C Documentation install-
$@
157 pkg_extra
:= GIT-VERSION-FILE lib
/unicorn
/version.rb LATEST NEWS \
158 $(ext
)/unicorn_http.c
$(man1_paths
)
163 .manifest
: $(ext
)/unicorn_http.c man NEWS
164 (git ls-files
&& for i in
$@
$(pkg_extra
); do echo
$$i; done
) | \
166 cmp
$@
+ $@ || mv
$@
+ $@
169 PLACEHOLDERS
= $(man1_rdoc
)
170 doc
: .document
$(ext
)/unicorn_http.c man html .olddoc.yml
$(PLACEHOLDERS
)
171 find bin lib
-type f
-name
'*.rbc' -exec
rm -f
'{}' ';'
176 install -m644 COPYING doc
/COPYING
177 install -m644
$(shell LC_ALL
=C grep
'^[A-Z]' .document
) doc
/
178 install -m644
$(man1_paths
) doc
/
179 tar cf
- $$(git ls-files examples
/) |
(cd doc
&& tar xf
-)
181 # publishes docs to http://unicorn.bogomips.org
186 chmod
644 $$(find doc
-type f
)
187 $(RSYNC
) -av doc
/ unicorn.bogomips.org
:/srv
/unicorn
/
188 git ls-files | xargs touch
190 # Create gzip variants of the same timestamp as the original so nginx
191 # "gzip_static on" can serve the gzipped versions directly.
192 doc_gz
: docs
= $(shell find doc
-type f
! -regex
'^.*\.gz$$')
194 for i in
$(docs
); do \
195 gzip
--rsyncable
-9 < $$i > $$i.gz
; touch
-r
$$i $$i.gz
; done
199 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
200 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
202 # ensures we're actually on the tagged $(VERSION), only used for release
204 test x
"$(shell umask)" = x0022
205 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
206 git diff-index
--quiet HEAD^
0
207 test `git rev-parse --verify HEAD^0` = \
208 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
211 git ls-tree
-r HEAD | awk
'/^100644 / {print $$NF}' | xargs chmod
644
212 git ls-tree
-r HEAD | awk
'/^100755 / {print $$NF}' | xargs chmod
755
216 install-gem
: $(pkggem
)
217 gem
install $(CURDIR
)/$<
219 $(pkggem
): .manifest fix-perms
220 gem build
$(rfpackage
).gemspec
224 $(pkgtgz
): distdir
= $(basename $@
)
225 $(pkgtgz
): HEAD
= v
$(VERSION
)
226 $(pkgtgz
): .manifest fix-perms
227 @
test -n
"$(distdir)"
230 tar cf
- $$(cat .manifest
) |
(cd
$(distdir
) && tar xf
-)
231 cd pkg
&& tar cf
- $(basename $(@F
)) | gzip
-9 > $(@F
)+
234 package
: $(pkgtgz
) $(pkggem
)
236 release
: verify package
237 # push gem to Gemcutter
240 gem install-gem
: GIT-VERSION-FILE
241 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
245 echo olddoc_placeholder
> $@
247 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) man