forked from caged/httpriot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
337 lines (282 loc) · 10.2 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
require 'rubygems'
require 'rake/packagetask'
require 'plist'
require 'versionomy'
IPHONE_BUILD_TARGETS = %w(3.0 3.1 3.1.2 3.1.3 3.2).collect {|v| Versionomy.parse(v)}
OSX_BUILD_TARGETS = %w(10.5 10.6).collect {|v| Versionomy.parse(v)}
CONFIGURATION = "Release"
namespace :iphone do
# TODO Find out how to run a program on the Simulator programtically
desc 'Run iPhone Unit Tests'
task :test do
system("GHUNIT_CLI=1 xcodebuild -target iPhoneUnitTestsRunner -configuration #{Project.active_config}")
# system("open #{File.join("#{Project.product_dir}-iphonesimulator", 'iPhoneUnitTestsRunner')}.app")
end
end
namespace :sdk do
desc 'Build and package all SDKs'
task :dist => ['sdk:build', 'sdk:package']
desc "Build Release Versions (iphone: #{IPHONE_BUILD_TARGETS.join(', ')}) (osx:#{OSX_BUILD_TARGETS.join(', ')}) of the static library for the simulator and device"
task :build => :clean do
rm_r(Project.build_dir) if File.exists?(Project.build_dir)
IPHONE_BUILD_TARGETS.each do |version|
system("xcodebuild -target libhttpriot -configuration #{CONFIGURATION} -sdk iphonesimulator#{version}")
system("xcodebuild -target libhttpriot -configuration #{CONFIGURATION} -sdk iphoneos#{version}")
end
OSX_BUILD_TARGETS.each do |version|
#system("ARCHS='i386' xcodebuild -target libhttpriot -configuration #{CONFIGURATION} -sdk macosx#{version}")
system("ARCHS='i386' xcodebuild -target HTTPRiot -configuration #{CONFIGURATION} -sdk macosx#{version}")
end
end
desc 'Clean all targets'
task :clean do
system("xcodebuild clean -alltargets")
end
desc 'Generate the documentation'
task :doc do
system("xcodebuild -target Documentation -configuration #{CONFIGURATION} -sdk macosx10.5")
end
desc 'Install the SDK in ~/Library/SDks'
task :install do
cd Project.project_dir
sdk = Dir.entries('pkg').detect {|e| e =~ /[^\.|\.\.|zip|tgz|tar|gz]$/i}
if sdk
sdk_base_dir = File.join(File.expand_path("~"), 'Library', 'SDKs')
sdk_install_location = File.join(sdk_base_dir, sdk)
mkdir(sdk_base_dir) unless File.exists?(sdk_base_dir)
rm_r(sdk_install_location) if File.exists?(sdk_install_location)
cd 'pkg'
mv sdk, sdk_install_location
else
puts "Nothing to install"
end
end
end
task :default => "osx:test"
# Used to build SDKSettings.plist files for iPhoneOS or iPhoneSimulator
class SDKSettings
def initialize(name, version, sdk, target)
@name = name
@version = version
@sdk = sdk
@target = target.to_s
end
def iphone?
@sdk == 'iphoneos'
end
def simulator?
@sdk == 'iphonesimulator'
end
def osx?
!iphone? && !simulator?
end
def osx_minimum_build_target
OSX_BUILD_TARGETS.min
end
def iphone_minimum_build_target
IPHONE_BUILD_TARGETS.min
end
def minimal_display_name
iphone? ? 'Device' : 'Simulator'
end
def display_name
iphone? ? "Device - iPhone OS #{@target}" : "Simulator - iPhone OS #{@target}"
end
def alternate_sdk
"#{@name}#{@sdk}#{@version}"
end
def default_properties
if iphone?
{
"CODE_SIGN_ENTITLEMENTS" => "",
"DEAD_CODE_STRIPPING" => "YES",
"ENTITLEMENTS_REQUIRED" => "YES",
"CODE_SIGN_RESOURCE_RULES_PATH" => "$(SDKROOT)/ResourceRules.plist",
"AD_HOC_CODE_SIGNING_ALLOWED" => "NO",
"PLATFORM_NAME" => "iphoneos",
"GCC_THUMB_SUPPORT" => "YES",
"IPHONEOS_DEPLOYMENT_TARGET" => @target
}
elsif simulator?
{
"GCC_PRODUCT_TYPE_PREPROCESSOR_DEFINITIONS" => " __IPHONE_OS_VERSION_MIN_REQUIRED=30000",
"PLATFORM_NAME" => "iphonesimulator",
"IPHONEOS_DEPLOYMENT_TARGET" => @target
}
else
{
"PLATFORM_NAME" => "macosx",
"MACOSX_DEPLOYMENT_TARGET" => @target
}
end
end
def to_plist
pl = {
"MinimalDisplayName" => minimal_display_name,
"Version" => @target,
"FamilyIdentifier" => (osx? ? "macosx" : "iphoneos"),
"DisplayName" => (osx? ? "Mac OS X #{@target}" : display_name),
"MaximumOSDeploymentTarget" => OSX_BUILD_TARGETS.max.to_s,
"MinimumSupportedToolsVersion" => iphone_minimum_build_target.to_s,
"CustomProperties" => {},
"FamilyName" => (osx? ? "Mac OS X" : "iPhone OS"),
"IsBaseSDK" => "NO",
"DefaultProperties" => default_properties,
"CanonicalName" => (osx? ? "macosx#{@target}" : alternate_sdk)
}
pl.merge("AlternateSDK" => alternate_sdk) if !osx?
pl.to_plist
end
end
class Project
def self.out
@out ||= %x[xcodebuild -list]
end
def self.active_config
config = 'Debug'
out.each_line do |line|
config = 'Release' if line.include?('Release (Active)')
end
config
end
def self.active_product
proj = ''
out.scan(/(.+?)\s\(Active\)/) do |m|
proj = m[0].strip unless %w(Debug Release).include?(m[0].strip)
end
File.join(product_dir, proj)
end
def self.project_dir
File.dirname(__FILE__)
end
def self.build_dir
File.join(project_dir, 'build')
end
def self.product_dir
File.join(build_dir, active_config)
end
def self.plist
File.join(project_dir, 'Info.plist')
end
def self.targets
IPHONE_BUILD_TARGETS.collect { |t| t.to_s }
end
end
# Creates iPhone friendly SDKs for static libraries and archives them for distribution.
# By default the package task will create an SDK for every target (2.0, 2.1, 2.2, 2.2.1, 3.0)
# for both the simulator and the device. An SDK is simply a collection of files laid out in a
# specific fasion with an included SDKSettings.plist file.
#
# /iphoneos3.0.sdk
# SDKSettings.plist
# /usr/local/lib/lib{LIBRARY_NAME}.a
# /usr/local/include/{PROJECT_NAME}/{HEADERS}
#
# Any project can link to these sdks using the "Additional SDks" settings in the build settings
# of a project and setting additional linker flags to the project name -l{PROJECT_NAME}
#
# IMPORTANT NOTE: This package tool uses `agvtool` to determine the version of your library.
# If you plan on using it in your own projects you'll need to make sure it's setup to use
# `agvtool`. You can get a run down on it here: http://chanson.livejournal.com/125568.html
#
class SDKPackage < Rake::PackageTask
# Project root directory unless provided
attr_accessor :product_name
# Build products dir. Uses `build` by default
attr_accessor :build_dir
# Debug, Release, etc. Release by default
attr_accessor :configuration
# Deployment target (2.0, 2.1, 2.2, 2.2.1, 3.0). Contains all by default.
attr_accessor :targets
# SDKs to package. iphonesimulator, iphoneos by default
attr_accessor :sdks
def initialize(name = nil, version = nil)
init(name, version)
yield self if block_given?
generate_tasks
end
def init(name, version)
super
@product_name = File.basename(Project.project_dir)
@name = name || @product_name.downcase.gsub(/\s*/, '')
@version = version || `agvtool vers -terse`.strip
@project_dir = Project.project_dir
@package_dir = File.join(@project_dir, 'pkg')
@build_dir = Project.build_dir
@sdks = %w(iphoneos iphonesimulator)
@configuration = 'Release'
@targets = Project.targets
end
def generate_tasks
namespace :sdk do
desc 'Build the iPhoneOS and iPhoneSimulator SDK package'
task :package do
package_root = File.join(package_dir, package_name)
rm_r(package_root) if File.exists?(package_root)
mkdir_p package_root
cd package_root
@targets.each do |target|
@sdks.each do |sdk|
# Create the SDK dir
cd package_root
target = '' if sdk == 'macosx'
sdk_dir = "#{sdk}#{target}.sdk"
next if File.exists?(sdk_dir)
mkdir sdk_dir
# Create the SDKSettings.plist file
cd sdk_dir
sdk_properties = SDKSettings.new(name, version, sdk, target).to_plist
File.open(File.join(pwd, 'SDKSettings.plist'), 'w+') do |f|
f << sdk_properties
end
# Copy the header files over
if sdk == 'macosx' && File.exists?(File.join(@build_dir, @configuration))
built_sdk_dir = File.join(@build_dir, @configuration)
else
built_sdk_dir = File.join(@build_dir, "#{@configuration}-#{sdk}#{target}")
end
cp_r File.join(built_sdk_dir, "usr"), "./"
# Create the lib directory and copy over the static library
lib_dir = File.join(pwd, 'usr', 'local', 'lib')
mkdir lib_dir
cd lib_dir
# assume product name is lib${NAME}.a
cp File.join(built_sdk_dir, "lib#{name}.a"), './'
end
end
# Move the framework over
package_root = File.join(package_dir, package_name)
cd package_root
framework = Dir["#{File.join(@build_dir, @configuration)}/*.framework"].first
cp_r(framework, './') if framework
[
[need_tar, tgz_file, "z"],
[need_tar_gz, tar_gz_file, "z"],
[need_tar_bz2, tar_bz2_file, "j"]
].each do |need_tar, file, flag|
if need_tar
cd package_dir do
sh %{#{@tar_command} #{flag}cvf #{file} #{package_name}}
end
end
end
if need_zip
cd package_dir do
sh %{#{@zip_command} -r #{zip_file} #{package_name}}
end
end
end
desc 'Clean the package directory'
task :clean do
rm_r package_dir
end
desc 'Clean and package again'
task :repackage => [:clean, :package_all]
end
end
end
SDKPackage.new do |sdk|
sdk.need_tar_gz = true
sdk.need_zip = true
sdk.configuration = CONFIGURATION
end