-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathrakefile
283 lines (231 loc) · 9 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
BUILD_TOOL = ENV["tool"] || 'xcodebuild' # 'xctool'
BUILD_TOOL_POSTFIX = ENV["toolpostfix"] || unless `which xcpretty`.empty? then '| xcpretty -c; exit ${PIPESTATUS[0]}' end
ROOT_DIR = File.expand_path('.')
BIN_DIR = File.join(ROOT_DIR, 'bin')
RELEASE_DIR = File.join(ROOT_DIR, 'releases')
PAYLOADS_DIR = File.join(ROOT_DIR, 'payloads')
INSTALLER_DIR = File.join(ROOT_DIR, 'installer')
TMP_ROOT = File.join(ROOT_DIR, 'tmp')
TMP_DIR = File.join(TMP_ROOT, "asepsis-installer")
INSTALL_DIR = "/Library/Application Support/Asepsis"
PRIVATE_KEY = File.join(ROOT_DIR, '..', 'keys', 'asepsis', 'dsa_priv.pem')
PUBLISH_PREFIX_URL = "http://downloads.binaryage.com"
CHANGELOG_PREFIX_URL = "http://asepsis.binaryage.com"
################################################################################################
# dependencies
require 'rubygems'
begin
require 'colored'
rescue LoadError
raise 'You must "gem install colored" to use terminal colors'
end
############################################################################################
def die(msg, status=1)
puts "Error[#{status||$?}]: #{msg}".red
exit status||$?
end
def announce(cmd)
puts "> " + cmd.yellow
end
def sys(cmd)
announce(cmd)
system(cmd)
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 "#{'Patching'.magenta} #{path.yellow}"
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 codesign(path)
sys("codesign --force --sign \"Developer ID Application: BinaryAge Limited\" \"#{path}\"")
end
def productsign(path)
tmp_path = path+"-tmp"
sys("mv \"#{path}\" \"#{tmp_path}\"")
sys("productsign --sign \"Developer ID Installer: BinaryAge Limited\" \"#{tmp_path}\" \"#{path}\"")
sys("rm \"#{tmp_path}\"")
end
def lipo(dir)
puts "Doing liposuction in #{dir.blue} ..."
Dir.chdir(dir) do
binaries = []
Dir.glob("**/Frameworks/*.framework") do |framework|
base = File.basename framework, ".framework"
full = File.join(framework, base)
binaries << full
end
Dir.glob("**/MacOS/*") do |exe|
binaries << exe
end
binaries.reject! {|file| File.symlink? file }
binaries.each do |binary|
sys("lipo -thin x86_64 -output \"#{binary}\" \"#{binary}\"") unless `lipo -info \"#{binary}\"` =~ /^Non-fat/
end
end
end
def strip_symbols(dir)
puts "Stripping symbols in #{dir.blue} ..."
symbols = []
Dir.chdir(dir) do
binaries = []
Dir.glob("**/*") do |file|
next unless File.executable? file
next unless `file \"#{file}\"` =~ /Mach-O/
binaries << file
end
binaries.reject! {|file| File.symlink? file }
binaries.each do |binary|
obfuscated_symbols = `nm -a "#{binary}" | grep " [+-]\\[\\\\$"`
obfuscated_symbols.split("\n").each do |sym|
sym =~ /^(.*) ([+-]\[\$.*)$/
symbols << $2
end
sys("strip -Sx \"#{binary}\"")
end
end
symbols = symbols.sort.uniq
end
############################################################################################
def release_version_from_filename(n) # /Users/darwin/code/totalfinder/payloads/TotalFinder-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 "build"
task :build do
sys("#{BUILD_TOOL} -project Asepsis.xcodeproj -scheme build -configuration Release #{BUILD_TOOL_POSTFIX}")
die("build failed") unless $?==0
end
desc "build debug version (more verbose in Console.app)"
task :build_debug do
sys("#{BUILD_TOOL} -project Asepsis.xcodeproj -scheme build -configuration Debug #{BUILD_TOOL_POSTFIX}")
die("build failed") unless $?==0
end
desc "install"
task :install do
sys("sudo rm -rf \"#{INSTALL_DIR}\"")
sys("sudo cp -r \"#{BIN_DIR}/Asepsis/\" \"#{INSTALL_DIR}\"")
sys("\"#{INSTALL_DIR}/ctl/asepsisctl\" install")
end
desc "clean"
task :clean do
sys("rm -rf \"#{BIN_DIR}\"")
sys("rm -rf \"#{TMP_DIR}\"")
sys(BUILD_TOOL+' clean -project Asepsis.xcodeproj -scheme build')
die("clean failed") unless $?==0
end
desc "test asepsis"
task :test do
sys("\"#{INSTALL_DIR}/Asepsis/asepsisTest\"")
end
desc "builds installer+unistaller, point it to products=<path>"
task :release do
puts "#{'Checking environment...'.magenta}"
version()
sys("mkdir -p #{RELEASE_DIR}") unless File.exists? RELEASE_DIR
# work on copy, because we do some dirty patching of sources
sys("rm -rf \"#{TMP_DIR}\"")
sys("mkdir -p \"#{TMP_DIR}\"")
sys("rsync -a --exclude=\"#{TMP_DIR}\" \"#{ROOT_DIR}/\" \"#{TMP_DIR}\"")
Dir.chdir(TMP_DIR) do
# do some patching prior compilation
patch("daemon/main.c", [
["asepsisd v##VERSION##", "asepsisd v#{$version}"]
])
patch("updater/AsepsisUpdater-Info.plist", [
['##VERSION##', $version]
])
patch("uninstaller-resources/Uninstaller-Info.plist", [
['##VERSION##', $version]
])
sys("rake build")
patch('bin/Asepsis/ctl/asepsisctl', [
['##VERSION##', "#{$version}"],
['##INSTALLER_TITLE##', "Asepsis #{$version}"]
])
installer_profile = File.join("bin", "installer-patched.pkgproj")
sys("cp \"installer/installer.pkgproj\" \"#{installer_profile}\"")
patch(installer_profile, [
['##VERSION##', $version],
['##INSTALLER_TITLE##', "Asepsis #{$version}"],
["/Users/darwin/code/asepsis", "#{TMP_DIR}"],
["#{TMP_DIR}/release", RELEASE_DIR]
])
lipo("bin/Asepsis")
strip_symbols("bin/Asepsis")
uninstaller = File.join("bin", "Asepsis", "Asepsis Uninstaller.app")
codesign(uninstaller)
codesign(File.join("bin", "Asepsis", "AsepsisUpdater.app", "Contents", "Frameworks", "Sparkle.framework/Versions/A/Resources/finish_installation.app"))
codesign(File.join("bin", "Asepsis", "AsepsisUpdater.app", "Contents", "Frameworks", "Sparkle.framework/Versions/A"))
codesign(File.join("bin", "Asepsis", "AsepsisUpdater.app"))
codesign(File.join("bin", "Asepsis", "DesktopServicesPrivWrapper"))
codesign(File.join("bin", "Asepsis", "install_name_tool"))
codesign(File.join("bin", "Asepsis", "asepsisTest"))
codesign(File.join("bin", "Asepsis", "asepsisd"))
codesign(File.join("bin", "Asepsis", "Asepsis Uninstaller.app"))
release = File.join(RELEASE_DIR, "Asepsis.pkg") # THIS MUST BE THE SAME NAME AS OF THE APP! REQUIRED BY SPARKLE
sys("rm -rf \"#{release}\"") if File.exist? release
die("build failed") unless $?==0
sys("packagesbuild -v -F \"#{TMP_DIR}\" \"#{installer_profile}\"")
die("build failed") unless $?==0
# codesign the pkg
productsign(release)
installer_icon = File.join("installer", "installer.icns")
sys("./installer/bin/setfileicon \"#{installer_icon}\" \"#{release}\"")
die("build failed") unless $?==0
releasedmg = File.join(RELEASE_DIR, "Asepsis-#{$version}.dmg")
sys("rm -rf \"#{releasedmg}\"") if File.exist? releasedmg
die("build failed") unless $?==0
readme_source = File.join("installer", "readme.pdf")
sys("hdiutil create \"#{releasedmg}\" -volname \"Asepsis\" -format UDBZ -fs HFS+ -srcfolder \"#{release}\" -srcfolder \"#{uninstaller}\" -srcfolder \"#{readme_source}\"")
die("build failed") unless $?==0
size = File.size(releasedmg)
sig = `ruby "sparkle/sign_update.rb" "#{releasedmg}" "#{PRIVATE_KEY}"`.strip
die("build failed") unless $?==0
snippet = "\
<item>
<title>Version #{$version}</title>
<sparkle:releaseNotesLink>#{CHANGELOG_PREFIX_URL}/changelog.html</sparkle:releaseNotesLink>
<pubDate>#{Time.new}</pubDate>
<enclosure url=\"#{PUBLISH_PREFIX_URL}/Asepsis-#{$version}.dmg\" sparkle:version=\"#{$version}\" length=\"#{size}\" type=\"application/octet-stream\" sparkle:dsaSignature=\"#{sig}\"/>
<sparkle:minimumSystemVersion>10.8.0</sparkle:minimumSystemVersion>
</item>"
puts snippet
puts
puts "Don't forget: ".red+"git tag -a as-v#{$version} -m \"Release #{$version}\"".green
puts "#{PUBLISH_PREFIX_URL}/Asepsis-#{$version}.dmg".blue
end
end
desc "monitor fs usage for DS_Store operations"
task :fs_usage do
sys("sudo fs_usage | grep DS_Store")
end
task :default => :build