forked from binaryage/totalterminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrakefile
434 lines (364 loc) · 13.1 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
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
ROOT_DIR = File.expand_path('.')
TMP_ROOT = '/tmp'
TMP_DIR = File.join(TMP_ROOT, 'totalterminal')
BUILD_DIR = File.join(ROOT_DIR, 'build')
RELEASE_DIR = File.join(ROOT_DIR, 'release')
INSTALLER_DIR = File.join(ROOT_DIR, 'installer')
PAYLOADS_DIR = File.join(ROOT_DIR, 'payloads')
PARENT_DIR = File.expand_path('..')
PLUGIN_BUNDLE = "TotalTerminal.bundle"
XCODE_WORKSPACE = File.join(ROOT_DIR, 'TotalTerminal.xcworkspace')
SPARKLE_DIR = File.join(ROOT_DIR, 'sparkle')
OSAX_DIR = File.join(PARENT_DIR, 'totalterminal-osax')
I18N_DIR = File.join(PARENT_DIR, 'totalterminal-i18n')
TMP_GIT_MODULES = File.join(TMP_DIR, '.gitmodules')
TMP_TOTALTERMINAL_RESOURCES = File.join(TMP_DIR, 'totalterminal-i18n', 'plugin')
TMP_TOTALTERMINAL_DIR = File.join(TMP_DIR, 'totalterminal-plugin')
TMP_BIN_DIR = File.join(TMP_DIR, 'bin')
TMP_BIN_TOTALTERMINAL_FRAMEWORKS = File.join(TMP_BIN_DIR, 'TotalTerminal.osax/Contents/Resources/TotalTerminal.bundle/Contents/Frameworks')
PLUGIN_INFO_PLIST = File.join(TMP_DIR, 'totalterminal-plugin', 'Info.plist')
PLUGIN_VISOR_M = File.join(TMP_DIR, 'totalterminal-plugin', 'TotalTerminal.mm')
PLUGIN_PREFERENCES_MM = File.join(TMP_DIR, 'totalterminal-plugin', 'TotalTerminal+Preferences.mm')
PLUGIN_VISOR_XIB = File.join(TMP_DIR, 'totalterminal-i18n', 'plugin', 'TotalTerminal.xib')
OSAX_INFO_PLIST = File.join(TMP_DIR, 'totalterminal-osax', 'Info.plist')
CRASHWATCHER_INFO_PLIST = File.join(TMP_DIR, 'crashwatcher', 'CrashWatcher-Info.plist')
PUBLISH_PREFIX_URL = "http://downloads.binaryage.com"
CHANGELOG_PREFIX_URL = "http://totalterminal.binaryage.com"
################################################################################################
# dependencies
begin
require 'colored'
rescue LoadError
raise 'You must "gem install colored" to use terminal colors'
end
def file_color(text); text.yellow; end
def dir_color(text); text.blue; end
def cmd_color(text); text.magenta; end
############################################################################################
def die(msg, status=1)
puts "Error[#{status||$?}]: #{msg}".red
exit status||$?
end
def version()
$version = ENV["version"] or die("specify version")
end
def revision()
$revision = `git rev-parse HEAD`.strip
$short_revision = $revision[0...7]
end
def dirty_repo_warning()
is_clean = `git status`.match(/working directory clean/)
puts "Repository is not clean! You should commit all changes before releasing.".red unless is_clean
end
def patch(path, replacers)
puts "#{cmd_color('Patching')} #{file_color(path)}"
lines = []
File.open(path, "r") do |f|
f.each do |line|
replacers.each do |r|
line.gsub!(r[0], r[1])
end
lines << line
end
end
File.open(path, "w") do |f|
f << lines.join
end
end
def announce(cmd)
puts "> " + cmd.yellow
end
def sys(cmd)
announce(cmd)
system(cmd)
end
############################################################################################
def generate_payload_for_pkg(tmp, pkg)
tree = ""
exes = ""
tmp2 = File.join(tmp, File.basename(pkg))
sys("rm -rf \"#{tmp2}\"") if File.exist? tmp2
sys("mkdir -p \"#{tmp2}\"")
sys("cp \"#{pkg}\" \"#{tmp2}\"")
name = File.basename pkg
Dir.chdir(tmp2) do
sys("xar -xf \"#{name}\"")
if (File.exist? "Payload") then
sys("mv Payload Payload.gz")
sys("gunzip Payload.gz")
sys("cpio -id < Payload")
end
`rm \"#{name}\"`
tree = `tree --dirsfirst -apsugif`
exes = ""
Dir.glob("**/Contents/MacOS/*") do |exe|
exes += `file "#{exe}"` + "\n"
end
end
res = ""
res << "\n"
res << "#{name}\n"
res << "=======================================================================\n"
res << tree
res << "\n"
res << exes
res
end
def generate_payload(dmg, out)
puts "Generating payload for: ".green + dmg.blue
volume = "/Volumes/TotalTerminal"
tmp = File.join(TMP_DIR, "payloads", File.basename(dmg, ".dmg"))
sys("rm -rf \"#{tmp}\"") if File.exist? tmp
sys("mkdir -p \"#{tmp}\"")
puts dmg
cmd = "hdiutil attach \"#{dmg}\" | grep Apple_partition_scheme"
announce(cmd)
res = `#{cmd}`
puts res
disk = res.split("\n")[0].split("\t")[0]
die("bad disk") unless disk =~ /\/dev/
sys("cp -r #{volume}/* \"#{tmp}\"")
tree1 = ""
Dir.chdir(tmp) do
tree1 = `tree --dirsfirst -apsugif`
end
pkgs = []
Dir.glob(File.join(tmp, "**/*.pkg")) do |pkg|
pkgs << generate_payload_for_pkg(tmp, pkg)
end
outdir = File.dirname out
`mkdir -p #{outdir}` unless File.exist? outdir
File.open(out, "w") do |f|
f << "BASIC DMG LAYOUT\n"
f << "================\n"
f << tree1
pkgs.each do |pkg|
f << pkg
end
end
puts " -> ".green + out.blue
sys("hdiutil detach #{disk}")
end
def retag_submodule(tags, submodule)
tags.each do |tag|
x = `git ls-tree #{tag} #{submodule}`
sha = x.split(" ")[2]
Dir.chdir(submodule) do
sha = `git log --reverse`.split("\n")[0].split(" ")[1] unless sha # take first commit in case submodule wasn't defined at this point
sys("git tag -d #{tag}")
puts "#{tag} #{sha}"
sys("git tag #{tag} #{sha}")
end
end
Dir.chdir(submodule) do
sys("git push --tags")
end
end
def release_version_from_filename(n) # /Users/darwin/code/totalterminal/payloads/TotalTerminal-0.7.1.txt
p = File.basename(n, ".txt").split("-")[1]
n = p.split(".")
while n.size < 3 do
n << "0"
end
x = (n[0]||"0").to_i
y = (n[1]||"0").to_i
z = (n[2]||"0").to_i
x*1000000 + y*1000 + z
end
###################################################################################################################
desc "opens XCode project"
task :open do
`open "#{XCODE_WORKSPACE}"`
end
desc "prepare stage"
task :stage do
puts "#{cmd_color('Cloning sources to stage ...')}"
`sudo rm -rf "#{TMP_DIR}"`
`mkdir -p "#{TMP_ROOT}"`
Dir.chdir(TMP_ROOT) do
`git clone #{ROOT_DIR}`
end
puts "#{cmd_color('Initializing submodules ...')}"
Dir.chdir(TMP_DIR) do
`git reset --hard HEAD`
patch(TMP_GIT_MODULES, [['git://github.com/binaryage', ROOT_DIR], ['.git', '']])
`git submodule update --init`
end
end
desc "prepares release build"
task :release do
unless File.exists?(TMP_DIR) then die('Doing it for first time? => rake stage') end
puts "#{cmd_color('Checking environment ...')}"
dirty_repo_warning()
version()
revision()
mkdir_p(RELEASE_DIR) unless File.exists? RELEASE_DIR
unless ENV["fast"] then
puts "#{cmd_color('Updating stage ...')}"
Dir.chdir(TMP_DIR) do
sys('git clean -fd')
sys('git fetch')
sys('git reset --hard origin/master')
patch(TMP_GIT_MODULES, [['git://github.com/binaryage', ROOT_DIR], ['.git', '']])
#
sys('git submodule sync')
sys('git submodule foreach "git reset --hard origin/master"')
sys('git submodule update')
end
puts "#{cmd_color('Patching version info ...')}"
patch(PLUGIN_VISOR_XIB, [['##VERSION##', $version], ['##REVISION##', $short_revision]])
patch(PLUGIN_INFO_PLIST, [['##VERSION##', $version], ['##REVISION##', $short_revision]])
patch(PLUGIN_VISOR_M, [['##VERSION##', $version], ['##REVISION##', $short_revision], ['##SHA##', $revision]])
patch(PLUGIN_PREFERENCES_MM, [['##VERSION##', $version], ['##REVISION##', $short_revision], ['##SHA##', $revision]])
patch(OSAX_INFO_PLIST, [['##VERSION##', $version], ['##REVISION##', $short_revision]])
patch(OSAX_INFO_PLIST, [['##VERSION##', $version], ['##REVISION##', $short_revision]])
patch(CRASHWATCHER_INFO_PLIST, [['##VERSION##', $version], ['##REVISION##', $short_revision]])
sys("rm -rf \"#{TMP_BIN_DIR}\"") unless ENV["noclean"]
sys("rm -rf ~/Library/Developer/Xcode/DerivedData/TotalTerminal-*") unless ENV["noclean"]
puts "#{cmd_color('Building')} #{file_color(TMP_TOTALTERMINAL_DIR)}"
Dir.chdir(TMP_DIR) do
sys('xcodebuild -workspace TotalTerminal.xcworkspace -scheme "TotalTerminal Package" -configuration Release')
die("build failed") unless $?==0
end
Dir.glob(File.join(TMP_BIN_TOTALTERMINAL_FRAMEWORKS, "*")) do |framework|
patch(File.join(framework, 'Resources', 'Info.plist'), [['##VERSION##', $version], ['##REVISION##', $short_revision]])
end
end
releasedmg = File.join(RELEASE_DIR, "TotalTerminal-#{$version}.dmg")
sys("rm -rf \"#{releasedmg}\"") if File.exist? releasedmg
die("build failed") unless $?==0
Dir.chdir(File.join(TMP_DIR, "totalterminal-installer")) do
sys("rake build version=#{$version} products=\"../bin\" release=\"#{RELEASE_DIR}\"")
die("installer build failed") unless $?==0
end
size = File.size(releasedmg)
sig = `ruby "sparkle/sign_update.rb" "#{releasedmg}" keys/dsa_priv.pem`.strip
die("build failed") unless $?==0
snippet = "\
<item>
<title>Version #{$version}</title>
<sparkle:releaseNotesLink>#{CHANGELOG_PREFIX_URL}/changelog-beta.html</sparkle:releaseNotesLink>
<pubDate>#{Time.new}</pubDate>
<enclosure url=\"#{PUBLISH_PREFIX_URL}/TotalTerminal-#{$version}.dmg\" sparkle:version=\"#{$version}\" length=\"#{size}\" type=\"application/octet-stream\" sparkle:dsaSignature=\"#{sig}\"/>
<sparkle:minimumSystemVersion>10.6.0</sparkle:minimumSystemVersion>
</item>"
puts snippet
puts
puts "Don't forget: ".red+"git tag -a v#{$version} -m \"Release #{$version}\"".green
puts "#{PUBLISH_PREFIX_URL}/TotalTerminal-#{$version}.dmg".blue
# Dir.chdir(ROOT_DIR) do
# sys("mkdir -p ttdata")
# sys("mount -t smbfs //guest:@whale/Store/ttdata ttdata")
# sys("rsync -av --delete release ttdata")
# sys("umount ttdata")
# sys("rm -rf ttdata")
# end
end
desc "removes intermediate build files"
task :clean do
puts "#{cmd_color('Removing')} #{dir_color(TMP_DIR)}"
`rm -rf "#{TMP_DIR}"`
end
desc "removes all release builds"
task :purge do
puts "#{cmd_color('Removing')} #{dir_color(RELEASE_DIR)}"
`rm -rf "#{RELEASE_DIR}"`
end
desc "beautify sources using uncrustify => see uncrustify.cfg"
task :beautify do
config = File.join(ROOT_DIR, 'uncrustify.cfg')
what = ENV["filter"] || "*"
base = File.join(ROOT_DIR, "totalterminal-plugin")
Dir.glob(File.join(base, "**/#{what}")) do |file|
next unless file=~/\.(mm|m|c|h|cc|cpp|hpp)$/
puts file[base.size+1..-1]
`uncrustify -c "#{config}" --replace --no-backup --mtime "#{file}"`
end
end
desc "build missing payloads"
task :payload do
Dir.chdir(RELEASE_DIR) do
Dir.glob("*.dmg").each do |file|
name = File.basename(file, ".dmg")
dest = File.join(PAYLOADS_DIR, name+".txt")
unless File.exist? dest then
generate_payload(file, dest)
end
end
end
end
desc "diff two most recent payloads"
task :paydiff do
res = `ls -1 "#{PAYLOADS_DIR}"/*.txt`
res = res.split("\n")
res = res.sort do |a, b|
va = release_version_from_filename a
vb = release_version_from_filename b
vb<=>va
end
a = res[1]
b = res[0]
`ksdiff "#{a}" "#{b}"`
end
desc "update tags in submodules v1.0+"
task :retag do
tags = `git tag`.split("\n").reject {|x| x =~ /^v0/ } # skip v0.x.x
puts "found #{tags.size} tags..."
retag_submodule(tags, "totalterminal-i18n")
retag_submodule(tags, "totalterminal-installer")
retag_submodule(tags, "totalterminal-osax")
# NO! retag_submodule(tags, "crashwatcher") # crashwatcher is shared between TotalTerminal and TotalFinder
# NO! retag_submodule(tags, "sparkle") # sparkle is shared between TotalTerminal and TotalFinder
`git push --tags`
end
desc "pull all"
task :pull do
Dir.chdir("totalterminal-i18n") do
puts "in " + Dir.pwd
sys("git pull")
end
Dir.chdir("totalterminal-installer") do
puts "in " + Dir.pwd
sys("git pull")
end
Dir.chdir("totalterminal-osax") do
puts "in " + Dir.pwd
sys("git pull")
end
Dir.chdir("sparkle") do
puts "in " + Dir.pwd
sys("git pull")
end
Dir.chdir("crashwatcher") do
puts "in " + Dir.pwd
sys("git pull")
end
puts "in " + Dir.pwd
sys("git pull")
end
desc "push all"
task :push do
Dir.chdir("totalterminal-i18n") do
puts "in " + Dir.pwd
sys("git push")
end
Dir.chdir("totalterminal-installer") do
puts "in " + Dir.pwd
sys("git push")
end
Dir.chdir("totalterminal-osax") do
puts "in " + Dir.pwd
sys("git push")
end
Dir.chdir("sparkle") do
puts "in " + Dir.pwd
sys("git push")
end
Dir.chdir("crashwatcher") do
puts "in " + Dir.pwd
sys("git push")
end
puts "in " + Dir.pwd
sys("git push")
end
task :default => :open