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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
require 'rake'
require 'fileutils'
require 'rake/clean'
require 'google_code'
require 'net/ftp'
RakeFileUtils.verbose(false)
PROJECT="iax"
GC_NAME = "IAX"
SRC_DIR=File.expand_path("..")
DOCS_DIR=File.expand_path("../Docs")
RES_DIR=File.expand_path("../res")
VERSION_FILE="#{DOCS_DIR}/#{PROJECT}_version.txt"
TYPES=[ 'ansi', 'unicode' ]
version=nil
def cp_relative(file, base, target)
file = File.expand_path(file)
base = File.expand_path(base)
raise "Wrong file/base : #{file} / #base" unless file.slice(0, base.length) == base
relative = file.slice(base.length, file.length - base.length)
target = File.expand_path(File.join(target, relative))
target_dir = File.dirname(target)
makedirs target_dir unless File.exists?(target_dir)
cp file, target
end
task :get_version do
File.open(VERSION_FILE, "r") do |file|
while (line = file.gets)
version = (line.match(/\d+\.\d+\.\d+\.\d+/) || [])[0]
break if version
end
end
raise "Could not read version file" unless VERSION
puts
puts "Current #{PROJECT} version: #{version}"
end
# Build ##############################################################################
SOLUTION="#{PROJECT}.dsw"
CONFIG=[ "Release", "Unicode Release" ]
BUILD_RESULT_DIR=[ "../Release", "../Unicode_Release" ]
DLL=[ "../../../bin/Release/Plugins/#{PROJECT}.dll", "../../../bin/Release Unicode/Plugins/#{PROJECT}W.dll" ]
PDB=[ "#{BUILD_RESULT_DIR[0]}/#{PROJECT}.pdb", "#{BUILD_RESULT_DIR[1]}/#{PROJECT}W.pdb" ]
(0..1).each do |i|
type = TYPES[i]
build = "build_#{type}".to_s
desc "Build #{type} project"
task build do
puts
puts "Building #{type} #{PROJECT}"
chdir(SRC_DIR) do
sh "msdev #{SOLUTION} /MAKE \"#{PROJECT} - Win32 #{CONFIG[i]}\" /REBUILD" do |ok, status|
ok or fail "Failed to compile #{type} dll (#{status.exitstatus})"
end
end
end
task :build => build
CLEAN.include(File.join(BUILD_RESULT_DIR[i], '/**/*'))
CLOBBER.include(DLL[i])
end
# Source zip #########################################################################
SRC_FILES = FileList[ \
"#{SRC_DIR}/*.cpp", \
"#{SRC_DIR}/*.h", \
"#{SRC_DIR}/*.rc", \
"#{SRC_DIR}/*.dsp", \
"#{SRC_DIR}/*.dsw", \
"#{SRC_DIR}/lib/**/*.h", \
"#{SRC_DIR}/sdk/**/*.h" \
]
SRC_ZIP="#{PROJECT}_src"
SRC_ZIP_FOLDER='zip_src'
task :clean_package_src do
rmtree SRC_ZIP_FOLDER
end
task :clean => :clean_package_src
desc "Create source package"
task :package_src => :get_version do
zip = "#{SRC_ZIP}.#{version}.zip"
puts
puts "Packaging #{zip}"
rmtree SRC_ZIP_FOLDER
mkdir SRC_ZIP_FOLDER
SRC_FILES.each do |file|
cp_relative(file, SRC_DIR, SRC_ZIP_FOLDER)
end
rm zip, :force => true
chdir(SRC_ZIP_FOLDER) do
sh "../zip -r -q ../#{zip} *"
end
rmtree SRC_ZIP_FOLDER
end
task :package => :package_src
CLOBBER.include("#{SRC_ZIP}.*.zip")
# Dll zips ###########################################################################
ZIP_FOLDERS=['zip_ansi', 'zip_unicode']
ZIPS=[ "#{PROJECT}", "#{PROJECT}W" ]
VOICE_SERVICE=[ "../../../bin/Release/Plugins/voiceservice.dll", "../../../bin/Release/Plugins/voiceserviceW.dll" ]
HISTORY_EVENTS=[ "../../../bin/Release/Plugins/aa_historyevents.dll", "../../../bin/Release Unicode/Plugins/aa_historyeventsW.dll" ]
(0..1).each do |i|
type = TYPES[i]
clean = "clean_package_#{type}".to_s
package = "package_#{type}".to_s
task clean do
rmtree ZIP_FOLDERS[i]
rmtree ZIP_FOLDERS[i] + '_pdb'
end
task :clean => clean
desc "Create #{type} package"
task package => [ :get_version, "build_#{type}".to_s ] do
zip = "#{ZIPS[i]}.#{version}.zip"
puts
puts "Packaging #{zip}"
rmtree ZIP_FOLDERS[i]
mkdir ZIP_FOLDERS[i]
target_dir = File.join(ZIP_FOLDERS[i], 'Docs')
docs = FileList["#{DOCS_DIR}/*"]
docs.exclude(VERSION_FILE)
docs.each do |file|
cp_relative(file, DOCS_DIR, target_dir)
end
target_dir = File.join(ZIP_FOLDERS[i], 'Icons')
docs = FileList["#{RES_DIR}/proto_#{PROJECT}.dll"]
docs.each do |file|
cp_relative(file, RES_DIR, target_dir)
end
target_dir = File.join(ZIP_FOLDERS[i], 'Plugins')
makedirs target_dir
cp DLL[i], target_dir
cp VOICE_SERVICE[i], target_dir
cp HISTORY_EVENTS[i], target_dir
rm zip, :force => true
chdir(ZIP_FOLDERS[i]) do
sh "../zip -r -q ../#{zip} *"
end
rmtree ZIP_FOLDERS[i]
zip = "#{ZIPS[i]}.pdb.#{version}.zip"
puts
puts "Packaging #{zip}"
rmtree ZIP_FOLDERS[i] + '_pdb'
target_dir = ZIP_FOLDERS[i] + '_pdb/Plugins'
makedirs target_dir
cp PDB[i], target_dir
chdir(ZIP_FOLDERS[i] + '_pdb') do
sh "../zip -r -q ../#{zip} *"
end
rmtree ZIP_FOLDERS[i] + '_pdb'
end
task :package => package
CLOBBER.include("#{ZIPS[i]}.pdb.*.zip")
CLOBBER.include("#{ZIPS[i]}.*.zip")
end
# Rebuild ############################################################################
desc "Rebuild all #{PROJECT} versions"
task :rebuild => [ :clobber, :build ]
desc "Build all #{PROJECT} versions"
task :build
# Upload #############################################################################
desc "Build and upload files"
task :upload
def empty?(str)
return true unless str
return str.strip.length <= 0
end
def ask(name, val=nil)
if empty?(val)
puts
print "#{name}: "
return STDIN.gets.chomp
else
return val
end
end
desc "Upload to googlecode"
task :upload_googlecode => [ :package, :get_version ] do
files = [ "#{ZIPS[0]}.#{version}.zip", \
"#{ZIPS[0]}.pdb.#{version}.zip", \
"#{ZIPS[1]}.#{version}.zip", \
"#{ZIPS[1]}.pdb.#{version}.zip" \
]
descriptions = [ "#{GC_NAME} #{version} - Ansi", \
"#{GC_NAME} PDB #{version} - Ansi", \
"#{GC_NAME} #{version} - Unicode", \
"#{GC_NAME} PDB #{version} - Unicode" \
]
type = [ "Ansi", "Ansi", "Unicode", "Unicode" ]
files.each do |file|
raise "Google Code: File not found: #{file}" unless File.exists?(file)
end
project = nil
username = nil
password = nil
if File.exists?("googlecode.passwd")
File.open("googlecode.passwd", "r") do |file|
line = file.gets
project,username,password = line.split(':')
end
end
project = ask("Google Code Project", project)
username = ask("Google Code Username", username)
password = ask("Google Code Password", password)
raise "Google Code: Invalid data" if empty?(project) || empty?(username) || empty?(password)
gc = GoogleCode.new(project, username, password)
gc.current_files.each do |file|
if file.description.slice(0, GC_NAME.length + 1) == GC_NAME + ' '
file.labels.reject! { |label| label == GoogleCode::FEATURED }
file.labels << GoogleCode::DEPRECATED
gc.update(file)
end
end
puts
(0...files.length).each do |i|
puts "Google Code: uploading #{files[i]}"
file = GoogleCode::Download.new File.basename(files[i])
file.description = descriptions[i]
file.labels << GoogleCode::FEATURED unless descriptions[i].match('PDB')
file.labels << 'Type-' + type[i] << 'Plugin-' + GC_NAME
file.local_file = files[i]
gc.upload(file)
end
end
task :upload => :upload_googlecode
desc "Upload to ftp"
task :upload_ftp => [ :package, :get_version ] do
files = [ "#{ZIPS[0]}.#{version}.zip", \
"#{ZIPS[0]}.pdb.#{version}.zip", \
"#{ZIPS[1]}.#{version}.zip", \
"#{ZIPS[1]}.pdb.#{version}.zip", \
"#{SRC_ZIP}.#{version}.zip", \
"#{DOCS_DIR}/#{PROJECT}_changelog.txt", \
"#{DOCS_DIR}/#{PROJECT}_readme.txt", \
"#{DOCS_DIR}/#{PROJECT}_version.txt" \
]
files.each do |file|
raise "FTP: File not found: #{file}" unless File.exists?(file)
end
server = nil
path = nil
username = nil
password = nil
if File.exists?("ftp.passwd")
File.open("ftp.passwd", "r") do |file|
line = file.gets
server,path,username,password = line.split(':')
end
end
server = ask("FTP Server", server)
path = ask("FTP path", path)
username = ask("FTP Username", username)
password = ask("FTP Password", password)
raise "FTP: Invalid data" if empty?(server) || empty?(path) || empty?(username) || empty?(password)
puts
Net::FTP.open(server, username, password) do |ftp|
files.each do |file|
puts "FTP: Uploading #{File.basename(file)}"
remote = File.join(path, File.basename(file).gsub(/\.\d+\.\d+\.\d+\.\d+/, ''))
begin
ftp.delete remote
rescue
end
ftp.putbinaryfile(file, remote)
end
end
end
task :upload => :upload_ftp
|