forked from phusion/passenger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc.rb
153 lines (140 loc) · 4.4 KB
/
misc.rb
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
# Phusion Passenger - http://www.modrails.com/
# Copyright (c) 2010 Phusion
#
# "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
desc "Run 'sloccount' to see how much code Passenger has"
task :sloccount do
ENV['LC_ALL'] = 'C'
begin
# sloccount doesn't recognize the scripts in
# bin/ as Ruby, so we make symlinks with proper
# extensions.
tmpdir = ".sloccount"
system "rm -rf #{tmpdir}"
mkdir tmpdir
Dir['bin/*'].each do |file|
safe_ln file, "#{tmpdir}/#{File.basename(file)}.rb"
end
sh "sloccount", *Dir[
"#{tmpdir}/*",
"lib/phusion_passenger",
"ext/apache2",
"ext/nginx",
"ext/common",
"ext/oxt",
"ext/phusion_passenger/*.c",
"test/**/*.{cpp,rb,h}"
]
ensure
system "rm -rf #{tmpdir}"
end
end
desc "Convert the NEWS items for the latest release to HTML"
task :news_as_html do
# The text is in the following format:
#
# Release x.x.x
# -------------
#
# * Text.
# * More text.
# * A header.
# With yet more text.
#
# Release y.y.y
# -------------
# .....
require 'cgi'
contents = File.read("NEWS")
# We're only interested in the latest release, so extract the text for that.
contents =~ /\A(Release.*?)^(Release|Older releases)/m
# Now split the text into individual items.
items = $1.split(/^ \*/)
items.shift # Delete the 'Release x.x.x' header.
puts "<dl>"
items.each do |item|
item.strip!
# Does this item have a header? It does if it consists of multiple lines, and
# the next line is capitalized.
lines = item.split("\n")
if lines.size > 1 && lines[1].strip[0..0] == lines[1].strip[0..0].upcase
puts "<dt>#{lines[0]}</dt>"
lines.shift
item = lines.join("\n")
item.strip!
end
# Split into paragraphs. Empty lines are paragraph dividers.
paragraphs = item.split(/^ *$/m)
def format_paragraph(text)
# Get rid of newlines: convert them into spaces.
text.gsub!("\n", ' ')
while text.index(' ')
text.gsub!(' ', ' ')
end
# Auto-link to issue tracker.
text.gsub!(/(bug|issue) #(\d+)/i) do
url = "http://code.google.com/p/phusion-passenger/issues/detail?id=#{$2}"
%Q(<{a href="#{url}"}>#{$1} ##{$2}<{/a}>)
end
text.strip!
text = CGI.escapeHTML(text)
text.gsub!(%r(<\{(.*?)\}>(.*?)<\{/(.*?)\}>)) do
"<#{CGI.unescapeHTML $1}>#{$2}</#{CGI.unescapeHTML $3}>"
end
text
end
if paragraphs.size > 1
STDOUT.write("<dd>")
paragraphs.each do |paragraph|
paragraph.gsub!(/\A\n+/, '')
paragraph.gsub!(/\n+\Z/, '')
if (paragraph =~ /\A /)
# Looks like a code block.
paragraph.gsub!(/^ /m, '')
puts "<pre lang=\"ruby\">#{CGI.escapeHTML(paragraph)}</pre>"
else
puts "<p>#{format_paragraph(paragraph)}</p>"
end
end
STDOUT.write("</dd>\n")
else
puts "<dd>#{format_paragraph(item)}</dd>"
end
end
puts "</dl>"
end
task :compile_app => [LIBCOMMON, LIBBOOST_OXT, :libev] do
source = ENV['SOURCE'] || ENV['FILE'] || ENV['F']
if !source
STDERR.puts "Please specify the source filename with SOURCE=(...)"
exit 1
end
exe = source.sub(/\.cpp$/, '')
create_executable(exe, source,
"-Iext -Iext/common #{LIBEV_CFLAGS} " <<
"#{PlatformInfo.portability_cflags} " <<
"#{EXTRA_CXXFLAGS} " <<
"#{LIBCOMMON} " <<
"#{LIBBOOST_OXT} " <<
"#{LIBEV_LIBS} " <<
"#{PlatformInfo.portability_ldflags} " <<
"#{EXTRA_LDFLAGS}")
end