-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrakefile
169 lines (136 loc) · 5.59 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
require 'rake'
TMP_DIR = "/tmp/root/totalfinder-installer-tmp"
ROOT_DIR = File.expand_path('.')
PARENT_DIR = File.expand_path('..')
RELEASE_DIR = File.join(PARENT_DIR, 'release')
BUILD_DIR = File.join(PARENT_DIR, '.build')
BUILD_OSAX = File.join(BUILD_DIR, 'TotalFinder.osax')
BUILD_APP = File.join(BUILD_DIR, 'TotalFinder.app')
BUILD_APP_RESOURCES = File.join(BUILD_DIR, 'TotalFinder.app/Contents/Resources')
BUILD_APP_BUNDLE = File.join(BUILD_APP_RESOURCES, 'TotalFinder.bundle')
BUILD_APP_OSAXSIP = File.join(BUILD_APP_RESOURCES, 'TotalFinderSIP.osax')
BUILD_APP_BUNDLE_PLUGINS = File.join(BUILD_APP_BUNDLE, 'Contents/PlugIns')
BUILD_APP_BUNDLE_FRAMEWORKS = File.join(BUILD_APP_BUNDLE, 'Contents/Frameworks')
BUILD_APP_BUNDLE_RESOURCES = File.join(BUILD_APP_BUNDLE, 'Contents/Resources')
BUILD_APP_BUNDLE_RESOURCES_UNINSTALLER = File.join(BUILD_APP_BUNDLE_RESOURCES, 'TotalFinder Uninstaller.app')
I18N_DIR = File.join(PARENT_DIR, 'i18n')
I18N_DIR_INSTALLER = File.join(I18N_DIR, 'installer')
I18N_DIR_INSTALLER_README = File.join(I18N_DIR_INSTALLER, 'readme.pdf')
################################################################################################
# dependencies
begin
require 'colored'
rescue LoadError
raise 'You must "gem install colored" to use terminal colors'
end
################################################################################################
# helpers
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)
if not system(cmd) then
die "error #{$?}"
end
end
################################################################################################
# routines
def version()
$version = ENV["version"] or die("specify version")
end
def patch(path, replacers)
puts "#{'Patching'.red} #{path.blue}"
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 --timestamp=none --force --sign \"Developer ID Application: BinaryAge Limited\" \"#{path}\"")
die("build failed") unless $?==0
end
def productsign(path)
tmp_path = path+"-tmp"
sys("mv \"#{path}\" \"#{tmp_path}\"")
sys("productsign --sign \"Developer ID Installer: BinaryAge Limited\" \"#{tmp_path}\" \"#{path}\"")
die("build failed") unless $?==0
sys("rm \"#{tmp_path}\"")
end
def lipo(dir)
puts "Doing liposuction in #{dir.blue} ..."
Dir.chdir(dir) do
binaries = []
Dir.glob("**/*") do |file|
next unless File.executable? file
next unless `file \"#{file}\"` =~ /Mach-O/
binaries << file
end
binaries.each do |binary|
sys("lipo -thin x86_64 -output \"#{binary}\" \"#{binary}\"") unless `lipo -info \"#{binary}\"` =~ /^Non-fat/
end
end
end
################################################################################################
# tasks
desc "builds installer+unistaller, point it to products=<path>"
task :build do
puts "#{'Checking environment ...'.magenta}"
version()
$release = File.expand_path(ENV["release"])
sys("cp \"#{ROOT_DIR}/installer.pkgproj\" \"#{ROOT_DIR}/installer-patched.pkgproj\"")
patch("#{ROOT_DIR}/installer-patched.pkgproj", [
['##VERSION##', $version],
['##INSTALLER_TITLE##', "TotalFinder #{$version}"],
['##ROOT_PATH##', PARENT_DIR],
['##BUILD_PATH##', $release]
])
patch("#{BUILD_APP_BUNDLE_RESOURCES_UNINSTALLER}/Contents/Info.plist", [
['##VERSION##', $version]
])
patch("#{BUILD_DIR}/TotalFinder.app/Contents/Info.plist", [
['##VERSION##', $version]
])
lipo(BUILD_APP_BUNDLE_RESOURCES)
# codesign stuff
codesign(File.join(BUILD_APP_BUNDLE_FRAMEWORKS, "Sparkle.framework/Versions/A/Resources/Updater.app/Contents/MacOS/fileop"))
codesign(File.join(BUILD_APP_BUNDLE_FRAMEWORKS, "Sparkle.framework/Versions/A/Resources/Updater.app"))
codesign(File.join(BUILD_APP_BUNDLE_FRAMEWORKS, "Sparkle.framework/Versions/A"))
codesign(File.join(BUILD_APP_BUNDLE_FRAMEWORKS, "BAKit.framework/Versions/A"))
codesign(File.join(BUILD_APP_BUNDLE_FRAMEWORKS, "TotalKit.framework/Versions/A"))
Dir.glob(File.join(BUILD_APP_BUNDLE_PLUGINS, "*")) do |plugin|
codesign(plugin)
Dir.glob(File.join(File.join(plugin, "Contents", "Frameworks"), "*")) do |framework|
codesign(File.join(framework, "Versions", "A"))
end
end
codesign(File.join(BUILD_APP_BUNDLE_RESOURCES, "TotalFinderCrashWatcher.app"))
codesign(File.join(BUILD_APP_BUNDLE))
codesign(BUILD_APP_BUNDLE_RESOURCES_UNINSTALLER)
codesign(BUILD_APP_OSAXSIP)
codesign(BUILD_APP)
codesign(BUILD_OSAX)
release = File.join($release, "TotalFinder.pkg") # THIS MUST BE THE SAME NAME AS OF THE APP! REQUIRED BY SPARKLE
sys("rm -rf \"#{release}\"") if File.exist? release
sys("./bin/packagesbuild -v -F \"#{ROOT_DIR}\" \"#{ROOT_DIR}/installer-patched.pkgproj\"")
releasedmg = File.join($release, "TotalFinder-#{$version}.dmg")
sys("rm -rf \"#{releasedmg}\"") if File.exist? releasedmg
# codesign the pkg
productsign(release)
installer_icon = File.join(I18N_DIR_INSTALLER, "totalfinder-installer.icns")
sys("./bin/setfileicon \"#{installer_icon}\" \"#{release}\"")
sys("hdiutil create \"#{releasedmg}\" -volname \"TotalFinder\" -format UDBZ -fs HFS+ -srcfolder \"#{release}\" -srcfolder \"#{BUILD_APP_BUNDLE_RESOURCES_UNINSTALLER}\" -srcfolder \"#{I18N_DIR_INSTALLER_README}\"")
end
task :default => :build