forked from boundsj/ObjectiveDDP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
170 lines (139 loc) · 4.47 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
PROJECT_NAME = "ObjectiveDDP"
APP_NAME = "ObjectiveDDP"
@configuration = "Debug"
@app_suffix = "-Dev"
SPECS_TARGET_NAME = "Specs"
SDK_VERSION = "6.1"
SDK_DIR = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator#{SDK_VERSION}.sdk"
BUILD_DIR = File.join(File.dirname(__FILE__), "build")
def build_dir(effective_platform_name)
File.join(BUILD_DIR, @configuration + effective_platform_name)
end
def product_name
"#{APP_NAME}#{@app_suffix}"
end
def grep_cmd_for_failure(cmd)
retries = 0
while retries < 10 do
retries += 1
puts "Executing #{cmd} and checking for FAILURE"
result = %x[#{cmd} 2>&1]
puts "Results:"
puts result
if result.include?("Simulator session timed out")
puts "Simulator timed out, retrying..."
kill_simulator
else
if !result.include?("Finished")
exit(1)
end
if result.include?("FAILURE")
exit(1)
elsif result.include?("EXCEPTION")
exit(1)
else
exit(0)
end
end
end
exit(1)
end
def system_or_exit(cmd, stdout = nil)
puts "Executing #{cmd}"
cmd += " >#{stdout}" if stdout
system(cmd) or raise "******** Build failed ********"
end
def with_env_vars(env_vars)
old_values = {}
env_vars.each do |key,new_value|
old_values[key] = ENV[key]
ENV[key] = new_value
end
yield
env_vars.each_key do |key|
ENV[key] = old_values[key]
end
end
def output_file(target)
output_dir = if ENV['IS_CI_BOX']
ENV['CC_BUILD_ARTIFACTS']
else
Dir.mkdir(BUILD_DIR) unless File.exists?(BUILD_DIR)
BUILD_DIR
end
output_file = File.join(output_dir, "#{target}.output")
puts "Output: #{output_file}"
output_file
end
def kill_simulator
system %Q[killall -m -KILL "gdb"]
system %Q[killall -m -KILL "otest"]
system %Q[killall -m -KILL "iPhone Simulator"]
end
#task :default => [:trim_whitespace, :specs]
task :default => [:trim_whitespace, :clean, :build_app, :build_specs]
desc "CI build"
task :cruise => [:clean, :clean_simulator, :build_app, :specs]
desc "Trim whitespace"
task :trim_whitespace do
filenames = `git status --short | grep --invert-match ^D | cut -c 4-`.split("\n")
filenames.map! do |filename|
if filename.include?('->')
filename = filename.slice(filename.index("->")..-1)
filename.gsub!('-> ', '')
end
filename
end
puts filenames.inspect
system_or_exit %Q[echo '#{filenames.join("\n")}'| grep -E '.*\.m?[cmhn]\"?$' | xargs sed -i '' -e 's/ / /g;s/ *$//g;']
end
desc "Clean simulator directories"
task :clean_simulator do
system('rm -Rf ~/Library/Application\ Support/iPhone\ Simulator/5.1/Applications/*')
end
desc "Clean all targets"
task :clean do
#system_or_exit "xcodebuild -workspace ObjectiveDDP.xcworkspace -scheme ObjectiveDDP -configuration #{@configuration} clean SYMROOT=#{BUILD_DIR}", output_file("clean")
system_or_exit "xcodebuild -workspace ObjectiveDDP.xcworkspace -scheme ObjectiveDDP -configuration #{@configuration} clean", output_file("clean")
FileUtils.rm_rf BUILD_DIR
end
desc "Build application"
task :build_app do
system_or_exit(%Q[xcodebuild -configuration Debug -workspace ObjectiveDDP.xcworkspace -scheme ObjectiveDDP -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO ARCHS=i386 build], output_file("app"))
end
desc "Build specs"
task :build_specs do
puts "SYMROOT: #{ENV['SYMROOT']}"
system_or_exit(%Q[xcodebuild -configuration Debug -workspace ObjectiveDDP.xcworkspace -scheme Specs -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO ARCHS=i386 build], output_file("specs"))
end
desc "Build all targets"
task :build_all do
kill_simulator
system_or_exit "xcodebuild -alltargets build TEST_AFTER_BUILD=NO SYMROOT=#{BUILD_DIR}", output_file("build_all")
end
desc "Run specs"
task :specs => :build_specs do
build_dir = build_dir("")
with_env_vars("DYLD_FRAMEWORK_PATH" => build_dir) do
system_or_exit("cd #{build_dir}; ./#{SPECS_TARGET_NAME}")
end
end
desc "adds a release tag to git"
task :tag_git do
release_tag = "#{@configuration.downcase}-#{agv_version}"
system_or_exit("git tag #{release_tag}")
end
desc "ensures that there's nothing in the git index before creating a release"
task :require_clean_index do
diff = `git diff-index --cached HEAD`
if diff.length > 0
raise "\nYou have uncommitted changes in your git index. You can't deploy with uncommitted changes."
end
end
task :current_version do
puts agv_version
end
def agv_version
output = `agvtool what-version`.split("\n")[1]
output.match(/(\d+)/)[1]
end