kwatch / motto-mysql

Motto-mysql is a complementary library to enhance and make faster 'mysql-ruby' library.

This URL has Read+Write access

motto-mysql / Rookbook.yaml
100644 226 lines (197 sloc) 7.109 kb
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
preparation*: |
 
  def edit_content(content)
    content.gsub!(/\$Release\$/, @release)
    content.gsub!(/\$Release:.*?\$/, "$Release: #{@release} $")
    content.gsub!(/\$Copyright.*?\$/, @copyright)
    content.gsub!(/\$License.*?\$/, @license)
    content
  end
 
 
properties:
 
  - project : motto-mysql
  - target : motto_mysql
  - release : 0.1.0
  - copyright : copyright(c) 2008 kuwata-lab.com all rights reserved.
  - license : "License: Ruby's license"
  #- mysql_ruby_version: '2.7.4'
  #- mysql_ruby_version: '2.7.5'
  #- mysql_ruby_version: '2.7.6'
  #- mysql_ruby_version: '2.8pre4'
  - mysql_ruby_version: '2.8'
  - mysql_srcdir: external/mysql-ruby-$(mysql_ruby_version)
  - mysql_c : $(mysql_srcdir)/mysql.c
 
parameters:
 
  #- rook_product: :all
 
recipes:
 
  - product: :all
    ingreds: [:build, :install, :test, :clean, :package]
 
  - product: :build
    desc: create Makefile and compile
    ingreds: [ ext/Makefile, ext/$(target).h ]
    method*: |
chdir "ext" do sys "make" end
 
  - product: :install
    ingreds: [ :build ]
    method*: |
chdir "ext" do sys "sudo make install" end
 
  - product: :uninstall
    method*: |
files = Dir.glob('/usr/local/lib/ruby/site_ruby/1.8/*/motto_mysql.*')
#sys "sudo rm #{files.join(' ')}"
rm_f files
 
  - product: :test
    method*: |
sys "testrb test"
 
  - product: :clean
    method*: |
rm_rf 'ext/Makefile', 'ext/$(target).o', 'ext/$(target).bundle', 'ext/mkmf.log'
 
  - product: ext/Makefile
    ingreds: [ ext/extconf.rb ]
    method*: |
chdir "ext" do
#sys "ruby extconf.rb --with-mysql-dir=/usr/local/mysql"
#sys "ruby extconf.rb --with-mysql-config"
sys "ruby extconf.rb"
end
 
  - product: :header
    desc: create 'ext/*.h' file
    ingreds: [ ext/$(target).h ]
 
  - product: ext/$(target).h
    ingreds: [ $(mysql_c), Rookbook.yaml ]
    method*: |
source = File.read('$(mysql_c)')
s = ''
s << "/* ------------------------ copied from mysql.c ------------------------ */\n"
s << "\n"
s << (source =~ /^\#define MYSQL_RUBY_VERSION.*?\n/ and $&)
s << "\n"
s << "/* struct mysql_res */\n"
s << (source =~ /^struct mysql_res \{.*?^\};\n/m and $&)
s << "\n"
s << "/* macro GetMysqlRes */\n"
s << (source =~ /^\#define GetMysqlRes\(obj\).*?\n/ and $&)
s << "\n"
s << "/* struct mysql_stmt */\n"
s << (source =~ /^struct mysql_stmt \{.*?\};\n/m and $&)
s << "\n"
s << "/* macro GetMysqlStmt */\n"
s << (source =~ /^\#define GetMysqlStmt\(obj\).*?\n/ and $&)
s << "\n"
s << "/* check_free() */\n"
s << (source =~ /^static void check_free\(VALUE \w+\)\n\{.*?^\}\n/m and $&)
s << "\n"
s << "/* check_stmt_closed() */\n"
s << (source =~ /^static void check_stmt_closed\(VALUE \w+\)\n\{.*?^\}\n/m and $&)
s << "\n"
s << "/* mysql_stmt_raise() */\n"
s << (source =~ /^static void mysql_stmt_raise\(MYSQL_STMT\* \w+\)\n\{.*?^\}\n/m and $&)
s << "\n"
s << "/* --------------------------------------------------------------------- */\n"
File.open(@product, 'w') {|f| f.write(s) }
 
 
  - product: README.html
    ingreds: [ README.txt ]
    method*: |
sys "rd2 #{@ingred} > #{@product}"
 
# - product: README.html
# ingreds: [ README.rdoc ]
# method*: |
# #sys "rdoc -1 #{@ingred} > #{@product}"
# #sys "rdoc #{@ingred}"
# sys "rdoc --template hefss #{@ingred}"
# #sys "rdoc --template kilmer #{@ingred}"
# mv "doc/files/README_rdoc.html", @product
# mv "doc/rdoc-style.css", "rdoc-style.css"
# rm_rf "doc"
# edit @product do |content|
# content.sub! '<body bgcolor="#BBBBBB">', '<body>'
# content.sub! 'href=".././rdoc-style.css"', 'href="rdoc-style.css"'
# content
# end
# edit "rdoc-style.css" do |content|
# content.sub! 'background: #BBBBBB;', '/*background: #BBBBBB;*/'
# content << "\n"
# content << "dt { font-weight: bold; color: #000000; margin-top: 5px; }\n"
# content << "dd { margin-top: 5px; margin-bottom: 10px; }\n"
# end
 
  - product: :package
    desc: create *.tar.gz and *.gem under 'build' directory
    ingreds: [ :clean ]
    method*: |
## remove and create build directory
base = "$(project)-$(release)"
dir = "build/#{base}"
rm_rf dir
mkdir_p dir
## copy files
store %w[README.txt $(project).gemspec setup.rb], dir
store 'ext/**/*', 'test/**/*', dir
## edit files
        edit "#{dir}/**/*" do |content|
edit_content(content)
end
## create packages
chdir "build" do
tar_czf "#{base}.tar.gz", base
end
chdir dir do
#sys "gem build $(project).gemspec"
          Gem.manage_gems
          require 'rubygems/gem_runner'
          Gem::GemRunner.new.run ['build', '$(project).gemspec']
mv "#{base}.gem", ".."
end
 
 
  - product: :index
    ingreds: [ website/index.html ]
 
  - product: website/index.html
    ingreds: [ README.txt ]
    method*: |
mkdir "website" unless test(?d, "website")
        download_url = "http://rubyforge.org/projects/$(project)/"
        sys "rd2 #{@ingred} | tidy -q -i -wrap 9999 -ashtml > #{@product}"
        edit @product do |content|
          body = (content =~ /<body>.*<\/body>/m) && $&
          #body.gsub! /<h1>.*<\/h1>/, "<h1>$(project): README.txt</h1>"
          #body.gsub! /README-$(project)/, 'README'
          body.gsub! /<!-- RDLabel: ".*" -->/, ''
          body.gsub! /(<h\d>)<a name=".*?" id=".*?">/, '\1'
          body.gsub! /<\/a>(<\/h\d>)/, '\1'
edit_content(body)
body.gsub! /copyright\(c\)/, 'copyright&copy;'
#body.sub! /http:\/\/$(project)\.rubyforge\.org\//, '<a href="\&">\&</a><br />'
#body.sub! /http:\/\/rubyforge\.org\/projects\/$(project)\//, '<a href="\&">\&</a>'
#body.sub! /http:\/\/github\.com\/\w+\/$(project)\//, '<a href="\&">\&</a>'
#body.sub! /http:\/\/kuwata-lab-products\.googlegroups.com\/?/, '<a href="\&">\&</a>'
          body.gsub! /(http:\/\/[-\w:\/.]+[^.<])/, '<a href="\1">\1</a>'
 
 
          #body.sub! /$(project)-$(release)\.tar\.gz/, "<a href=\"#{download_url}\">\\&</a>"
#body.sub! /CGI-Exception/, '<a href="http://cgi-exception.rubyforge.org/">\&</a>'
          html = <<END
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <html lang="en">
        <head>
          <title>$(project): README.txt</title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf8">
          <link rel="stylesheet" type="text/css" href="style.css">
</head>
        #{body}
        </html>
        END
          content[0..-1] = html
          content
        end
 
 
  - product: :debug
    method*: |
items = %w[string var_string int24 long longlong float double
timestamp datetime date time
tiny short year decimal blob tiny_blob medium_blob newdecimal bit]
s = ''
s << "#if DEBUG\n"
s << " int _type = buffer_type;\n"
s << " int _length = s->result.length[i];\n"
s << " switch (_type) {\n"
for item in items
t = item.upcase
s << " case MYSQL_TYPE_#{t}: fprintf(stderr, \"*** debug: MYSQL_TYPE_#{t}(%d), length=%d\\n\", _type, _length); break;\n"
end
s << " default: fprintf(stderr, \"*** debug: unknown type(%d)\\n\", _type);\n"
s << " }\n"
s << "#endif\n"
File.open('debug', 'w') {|f| f << s }