1 # use GNU Make to run tests in parallel, and without depending on RubyGems
12 GIT-VERSION-FILE
: .FORCE-GIT-VERSION-FILE
14 -include GIT-VERSION-FILE
16 ruby_bin
:= $(shell which
$(RUBY
))
17 ifeq ($(DLEXT
),) # "so" for Linux
18 DLEXT
:= $(shell $(RUBY
) -rrbconfig
-e
'puts RbConfig::CONFIG["DLEXT"]')
20 ifeq ($(RUBY_VERSION
),)
21 RUBY_VERSION
:= $(shell $(RUBY
) -e
'puts RUBY_VERSION')
24 RUBY_ENGINE
:= $(shell $(RUBY
) -e
'puts((RUBY_ENGINE rescue "ruby"))')
28 # dunno how to implement this as concisely in Ruby, and hell, I love awk
29 awk_slow
:= awk
'/def test_/{print FILENAME"--"$$2".n"}' 2>/dev
/null
31 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb \
32 test/unit
/test_signals.rb
test/unit
/test_upload.rb
33 log_suffix
= .
$(RUBY_ENGINE
).
$(RUBY_VERSION
).log
34 T
:= $(filter-out $(slow_tests
), $(wildcard test/*/test*.rb
))
35 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
36 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
37 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
38 test_prefix
= $(CURDIR
)/test/$(RUBY_ENGINE
)-$(RUBY_VERSION
)
40 ext
:= ext
/unicorn_http
41 c_files
:= $(ext
)/unicorn_http.c
$(ext
)/httpdate.c
$(wildcard $(ext
)/*.h
)
42 rl_files
:= $(wildcard $(ext
)/*.rl
)
43 base_bins
:= unicorn unicorn_rails
44 bins
:= $(addprefix bin
/, $(base_bins
))
45 man1_rdoc
:= $(addsuffix _1
, $(base_bins
))
46 man1_bins
:= $(addsuffix .1, $(base_bins
))
47 man1_paths
:= $(addprefix man
/man1
/, $(man1_bins
))
48 rb_files
:= $(bins
) $(shell find lib ext
-type f
-name
'*.rb')
49 inst_deps
:= $(c_files
) $(rb_files
) GNUmakefile
test/test_helper.rb
51 ragel
: $(ext
)/unicorn_http.c
52 $(ext
)/unicorn_http.c
: $(rl_files
)
53 cd
$(@D
) && $(RAGEL
) unicorn_http.rl
-C
$(RLFLAGS
) -o
$(@F
)
54 $(ext
)/Makefile
: $(ext
)/extconf.rb
$(c_files
)
55 cd
$(@D
) && $(RUBY
) extconf.rb
56 $(ext
)/unicorn_http.
$(DLEXT
): $(ext
)/Makefile
58 lib
/unicorn_http.
$(DLEXT
): $(ext
)/unicorn_http.
$(DLEXT
)
61 http
: lib
/unicorn_http.
$(DLEXT
)
63 test-install
: $(test_prefix
)/.stamp
64 $(test_prefix
)/.stamp
: $(inst_deps
)
65 mkdir
-p
$(test_prefix
)/.ccache
66 tar cf
- $(inst_deps
) GIT-VERSION-GEN | \
67 (cd
$(test_prefix
) && tar xf
-)
68 $(MAKE
) -C
$(test_prefix
) clean
69 $(MAKE
) -C
$(test_prefix
) http shebang RUBY
="$(RUBY)"
72 # this is only intended to be run within $(test_prefix)
74 $(MRI
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
76 t_log
:= $(T_log
) $(T_n_log
)
78 @cat
$(t_log
) |
$(MRI
) test/aggregate.rb
81 test-exec
: $(wildcard test/exec
/test_
*.rb
)
82 test-unit
: $(wildcard test/unit
/test_
*.rb
)
83 $(slow_tests
): $(test_prefix
)/.stamp
84 @
$(MAKE
) $(shell $(awk_slow
) $@
)
86 test-integration
: $(test_prefix
)/.stamp
89 check: test test-integration
93 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
95 quiet_pre
= @echo
'* $(arg)$(extra)';
96 quiet_post
= >$(t
) 2>&1 && $(check_test
)
98 # we can't rely on -o pipefail outside of bash 3+,
99 # so we use a stamp file to indicate success and
100 # have rm fail if the stamp didn't get created
101 stamp
= $@
$(log_suffix
).ok
102 quiet_pre
= @echo
$(RUBY
) $(arg
) $(TEST_OPTS
); ! test -f
$(stamp
) && (
103 quiet_post
= && > $(stamp
) )2>&1 | tee
$(t
); \
104 rm $(stamp
) 2>/dev
/null
&& $(check_test
)
107 # not all systems have setsid(8), we need it because we spam signals
108 # stupidly in some tests...
109 rb_setsid
:= $(RUBY
) -e
'Process.setsid' -e
'exec *ARGV'
111 # TRACER='strace -f -o $(t).strace -s 100000'
112 run_test
= $(quiet_pre
) \
113 $(rb_setsid
) $(TRACER
) $(RUBY
) -w
$(arg
) $(TEST_OPTS
) $(quiet_post
) || \
114 (sed
"s,^,$(extra): ," >&2 < $(t
); exit
1)
116 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
117 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
118 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
119 %.n
: export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
120 %.n
: $(test_prefix
)/.stamp
124 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
125 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
126 $(T
): export RUBYLIB
:= $(test_prefix
):$(test_prefix
)/lib
:$(MYLIBS
)
127 $(T
): $(test_prefix
)/.stamp
130 install: $(bins
) $(ext
)/unicorn_http.c
132 $(RM
) lib
/unicorn_http.
$(DLEXT
)
133 $(RM
) -r .install-tmp
135 cp
-p bin
/* .install-tmp
138 mv .install-tmp
/* bin
/
139 $(RM
) -r .install-tmp
142 setup_rb_files
:= .config InstalledFiles
143 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) clean
146 -$(MAKE
) -C
$(ext
) clean
147 -$(MAKE
) -C Documentation
clean
148 $(RM
) $(ext
)/Makefile lib
/unicorn_http.
$(DLEXT
)
149 $(RM
) $(setup_rb_files
) $(t_log
)
150 $(RM
) -r
$(test_prefix
) man
153 $(MAKE
) -C Documentation install-
$@
155 pkg_extra
:= GIT-VERSION-FILE lib
/unicorn
/version.rb ChangeLog LATEST NEWS \
156 $(ext
)/unicorn_http.c
$(man1_paths
)
158 ChangeLog
: GIT-VERSION-FILE .wrongdoc.yml
161 .manifest
: ChangeLog
$(ext
)/unicorn_http.c man
162 (git ls-files
&& for i in
$@
$(pkg_extra
); do echo
$$i; done
) | \
164 cmp
$@
+ $@ || mv
$@
+ $@
167 doc
: .document
$(ext
)/unicorn_http.c man html .wrongdoc.yml
168 for i in
$(man1_rdoc
); do echo
> $$i; done
169 find bin lib
-type f
-name
'*.rbc' -exec
rm -f
'{}' ';'
172 install -m644 COPYING doc
/COPYING
173 install -m644
$(shell LC_ALL
=C grep
'^[A-Z]' .document
) doc
/
174 install -m644
$(man1_paths
) doc
/
175 tar cf
- $$(git ls-files examples
/) |
(cd doc
&& tar xf
-)
178 # publishes docs to http://unicorn.bogomips.org
182 find doc
/images
-type f | \
183 TZ
=UTC xargs touch
-d
'1970-01-01 00:00:02' doc
/rdoc.css
185 chmod
644 $$(find doc
-type f
)
186 $(RSYNC
) -av doc
/ unicorn.bogomips.org
:/srv
/unicorn
/
187 git ls-files | xargs touch
189 # Create gzip variants of the same timestamp as the original so nginx
190 # "gzip_static on" can serve the gzipped versions directly.
191 doc_gz
: docs
= $(shell find doc
-type f
! -regex
'^.*\.\(gif\|jpg\|png\|gz\)$$')
193 for i in
$(docs
); do \
194 gzip
--rsyncable
-9 < $$i > $$i.gz
; touch
-r
$$i $$i.gz
; done
199 pkggem
:= pkg
/$(rfpackage
)-$(VERSION
).gem
200 pkgtgz
:= pkg
/$(rfpackage
)-$(VERSION
).tgz
201 release_notes
:= release_notes-
$(VERSION
)
202 release_changes
:= release_changes-
$(VERSION
)
204 release-notes
: $(release_notes
)
205 release-changes
: $(release_changes
)
207 wrongdoc release_changes
> $@
+
208 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
210 wrongdoc release_notes
> $@
+
211 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
213 # ensures we're actually on the tagged $(VERSION), only used for release
215 test x
"$(shell umask)" = x0022
216 git rev-parse
--verify refs
/tags/v
$(VERSION
)^
{}
217 git diff-index
--quiet HEAD^
0
218 test `git rev-parse --verify HEAD^0` = \
219 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
222 git ls-tree
-r HEAD | awk
'/^100644 / {print $$NF}' | xargs chmod
644
223 git ls-tree
-r HEAD | awk
'/^100755 / {print $$NF}' | xargs chmod
755
227 install-gem
: $(pkggem
)
228 gem
install $(CURDIR
)/$<
230 $(pkggem
): .manifest fix-perms
231 gem build
$(rfpackage
).gemspec
235 $(pkgtgz
): distdir
= $(basename $@
)
236 $(pkgtgz
): HEAD
= v
$(VERSION
)
237 $(pkgtgz
): .manifest fix-perms
238 @
test -n
"$(distdir)"
241 tar cf
- $$(cat .manifest
) |
(cd
$(distdir
) && tar xf
-)
242 cd pkg
&& tar cf
- $(basename $(@F
)) | gzip
-9 > $(@F
)+
245 package
: $(pkgtgz
) $(pkggem
)
247 release
: verify package
$(release_notes
) $(release_changes
)
248 # push gem to Gemcutter
251 gem install-gem
: GIT-VERSION-FILE
252 $(MAKE
) $@ VERSION
=$(GIT_VERSION
)
255 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) man