forked from macournoyer/thin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
174 lines (144 loc) · 4.86 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require File.dirname(__FILE__) + '/lib/thin'
REVISION = `svn info`.match('Revision: (\d+)')[1]
EXT_DIR = 'ext/thin_parser'
EXT_BUNDLE = "#{EXT_DIR}/thin_parser.bundle"
EXT_FILES = FileList[
"#{EXT_DIR}/*.c",
"#{EXT_DIR}/*.h",
"#{EXT_DIR}/*.rl",
"#{EXT_DIR}/extconf.rb",
"#{EXT_DIR}/Makefile",
"lib"
]
CLEAN.include %w(doc/rdoc pkg tmp log *.gem **/*.{o,bundle,jar,so,obj,pdb,lib,def,exp,log} ext/*/Makefile)
Rake::TestTask.new do |t|
t.pattern = 'test/*_test.rb'
end
task :default => [:compile, :test]
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc/rdoc'
rdoc.options += ['--quiet', '--title', Thin::NAME,
"--opname", "index.html",
"--line-numbers",
"--main", "README",
"--inline-source"]
rdoc.template = "site/rdoc.rb"
rdoc.main = "README"
rdoc.title = Thin::NAME
rdoc.rdoc_files.add %w(README lib/thin/*.rb')
end
namespace :rdoc do
desc 'Upload rdoc to code.macournoyer.com'
task :upload => :rdoc do
upload "doc/rdoc", 'thin/doc', :replace => true
end
end
spec = Gem::Specification.new do |s|
s.name = Thin::NAME
s.version = Thin::VERSION::STRING
s.platform = Gem::Platform::RUBY
s.summary =
s.description = "A thin and fast web server"
s.author = "Marc-Andre Cournoyer"
s.email = '[email protected]'
s.homepage = 'http://code.macournoyer.com/thin/'
s.required_ruby_version = '>= 1.8.6'
s.add_dependency 'eventmachine', '>= 0.9.0'
s.add_dependency 'rack', '>= 0.2.0'
s.files = %w(README COPYING Rakefile) + Dir.glob("{doc,lib,test,example}/**/*")
s.extensions = FileList["ext/**/extconf.rb"].to_a
s.require_path = "lib"
end
Rake::GemPackageTask.new(spec) do |p|
p.gem_spec = spec
end
namespace :gem do
desc 'Upload gem to code.macournoyer.com'
task :upload => :gem do
upload "pkg/#{spec.full_name}.gem", 'gems'
sh 'ssh [email protected] "cd code.macournoyer.com && index_gem_repository.rb"'
end
desc 'Upload gem to rubyforge.org'
task :upload_rubyforge => :gem do
sh 'rubyforge login'
sh "rubyforge add_release thin thin #{Thin::VERSION::STRING} pkg/thin-#{Thin::VERSION::STRING}.gem"
sh "rubyforge add_file thin thin #{Thin::VERSION::STRING} pkg/thin-#{Thin::VERSION::STRING}.gem"
end
end
task :ragel do
Dir.chdir EXT_DIR do
target = "parser.c"
File.unlink target if File.exist? target
sh "ragel parser.rl | rlgen-cd -G2 -o #{target}"
raise "Failed to compile Ragel state machine" unless File.exist? target
end
end
desc "Compile the extensions"
task :compile => ["#{EXT_DIR}/Makefile", EXT_BUNDLE]
task :package => :compile
file "#{EXT_DIR}/Makefile" => ["#{EXT_DIR}/extconf.rb"] do
cd(EXT_DIR) { ruby "extconf.rb" }
end
file EXT_BUNDLE => EXT_FILES do
cd EXT_DIR do
sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
end
cp EXT_BUNDLE, 'lib/'
end
desc 'Show some stats about the code'
task :stats do
line_count = proc do |path|
Dir[path].collect { |f| File.open(f).readlines.reject { |l| l =~ /(^\s*(\#|\/\*))|^\s*$/ }.size }.inject(0){ |sum,n| sum += n }
end
lib = line_count['lib/**/*.rb']
ext = line_count['ext/**/*.{c,h}']
test = line_count['test/**/*.rb']
ratio = '%1.2f' % (test.to_f / lib.to_f)
puts "#{lib.to_s.rjust(6)} LOC of lib"
puts "#{ext.to_s.rjust(6)} LOC of ext"
puts "#{test.to_s.rjust(6)} LOC of test"
puts "#{ratio.to_s.rjust(6)} ratio lib/test"
end
namespace :site do
task :build do
mkdir_p 'tmp/site/images'
cd 'tmp/site' do
ruby '../../site/thin.rb', '--dump'
end
cp 'site/style.css', 'tmp/site'
cp_r Dir['site/images/*'], 'tmp/site/images'
end
desc 'Upload website to code.macournoyer.com'
task :upload => 'site:build' do
upload 'tmp/site/*', 'thin'
end
end
namespace :deploy do
task :site => %w(site:upload rdoc:upload)
desc 'Deploy on code.macournoyer.com'
task :alpha => %w(gem:upload deploy:site)
desc 'Deploy on rubyforge'
task :public => %w(gem:upload_rubyforge deploy:site)
end
desc 'Deploy on all servers'
task :deploy => %w(deploy:alpha deploy:public)
task :install do
sh %{rake package}
sh %{sudo gem install pkg/#{Thin::NAME}-#{Thin::VERSION::STRING}}
end
task :uninstall => [:clean] do
sh %{sudo gem uninstall #{Thin::NAME}}
end
task :tag do
sh %Q{svn cp . http://code.macournoyer.com/svn/thin/tags/#{Thin::VERSION::STRING} -m "Tagging version #{Thin::VERSION::STRING}"}
end
# == Utilities
def upload(file, to, options={})
sh %{ssh [email protected] "rm -rf code.macournoyer.com/#{to}"} if options[:replace]
sh %{scp -rq #{file} [email protected]:code.macournoyer.com/#{to}}
end