-
Notifications
You must be signed in to change notification settings - Fork 24
/
doctor.rb
254 lines (211 loc) · 8.36 KB
/
doctor.rb
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
# coding: utf-8
# NOTE: This class is meant to have zero dependencies on external files (completely self contained),
# try not to take on external dependencies even if it means that code will be duplicated.
module Motion; module Project
class Doctor
def execute silent = true
if ENV['RM_BYPASS_DOCTOR'] == '1'
puts "* WARNING: Bypassing `motion doctor`, I hope you know what you're doing!"
return
else
@errors = []
verify_swift
verify_community_templates
verify_community_commands
print_environment_info unless silent
if @errors.empty?
unless silent
puts <<-S
======================================================================
* #{color :green, 'Success!'} `motion doctor` ran successfully and found no issues.
Still need help? Join us on Slack: http://slack.rubymotion.com
======================================================================
S
end
else
puts <<-S
======================================================================
* #{bold(color :red, 'ERROR:')} #{@errors.join("\n")}
* NOTE:
If you know what you are doing, Setting the environment variable
RM_BYPASS_DOCTOR=1 will skip RubyMotion's install verifications.
* HELP:
Find help in our Slack Channel: http://slack.rubymotion.com
======================================================================
S
exit 1
end
end
end
def print_environment_info
puts bold "= ENVIRONMENT INFO ="
puts "Swift Runtime: " + (swift_runtime? && swift_staged? ? '✅' : '❌')
puts "RubyMotion Templates: " + (rubymotion_templates? ? '✅' : '❌')
puts "RubyMotion Commands: " + (rubymotion_commands? ? '✅' : '❌')
puts bold "= RubyMotion ="
puts "version: " + rubymotion_version
puts "osx sdks: " + `ls /Library/RubyMotion/data/osx`.each_line.map {|l| l.strip}.join(", ")
puts "ios sdks: " + `ls /Library/RubyMotion/data/ios`.each_line.map {|l| l.strip}.join(", ")
if Dir.exist? '/Library/RubyMotion/data/tvos'
puts "tv sdks: " + `ls /Library/RubyMotion/data/tvos`.each_line.map {|l| l.strip}.join(", ")
else
puts "tv sdks: " + "(none)"
end
if Dir.exist? '/Library/RubyMotion/data/watchos'
puts "watch sdks: " + `ls /Library/RubyMotion/data/watchos`.each_line.map {|l| l.strip}.join(", ")
else
puts "watch sdks: " + "(none)"
end
puts "android sdks: " + `ls /Library/RubyMotion/data/android`.each_line.map {|l| l.strip}.join(", ")
puts bold "= xcodebuild ="
puts `xcodebuild -version`
puts bold "= clang ="
puts `clang --version`
puts bold "= xcode-select ="
puts "version: " + `xcode-select --version`
puts "path: " + xcode_path
puts bold "= Xcode ="
puts "osx platform: " + exec_and_join("ls #{xcode_path}/Platforms/MacOSX.platform/Developer/SDKs/", ", ")
puts "ios platform: " + exec_and_join("ls #{xcode_path}/Platforms/iPhoneOS.platform/Developer/SDKs/", ", ")
puts "tv platform: " + exec_and_join("ls #{xcode_path}/Platforms/AppleTVOS.platform/Developer/SDKs/", ", ")
puts "watch platform: " + exec_and_join("ls #{xcode_path}/Platforms/WatchOS.platform/Developer/SDKs/", ", ")
puts bold "= Android ="
if Dir.exist? File.expand_path('~/.rubymotion-android/sdk/platforms')
puts "android sdks: " + exec_and_join("ls ~/.rubymotion-android/sdk/platforms/", ", ")
else
puts "android sdks: (none)"
end
if Dir.exist? File.expand_path('~/.rubymotion-android/ndk')
puts "android ndk: " + exec_and_join("cat ~/.rubymotion-android/ndk/source.properties", " ")
else
puts "android ndk: (none)"
end
puts bold "= Java ="
puts `java -version 2>&1`.strip
puts bold "= MacOS ="
puts `system_profiler SPSoftwareDataType`.each_line.map {|l| l.strip}.find {|l| l =~ /System Version:/}
puts bold "= ENV ="
puts "RUBYMOTION_ANDROID_SDK=" + ENV.fetch("RUBYMOTION_ANDROID_SDK", '')
puts "RUBYMOTION_ANDROID_NDK=" + ENV.fetch("RUBYMOTION_ANDROID_NDK", '')
puts bold "= Ruby Manager ="
puts "rvm: #{`which rvm`}"
puts "rbenv: #{`which rbenv`}"
puts "chruby: #{`which chruby`}"
puts "asdf: #{`which asdf`}"
puts bold "= Ruby ="
puts `which ruby`
puts `ruby -v`
puts bold "= Homebrew ="
if `which brew`.empty?
puts 'Homebrew is not installed.'
else
puts `brew --version`
puts exec_and_join("brew list", ", ")
end
rescue => e
@errors << "Failure in running Doctor#print_environment_info: #{e}"
end
def exec_and_join command, delimiter
`#{command}`.split("\n").map {|l| l.strip }.reject {|l| l.length == 0}.join(delimiter)
end
def xcode_path
@xcode_path ||= `xcode-select --print-path`.strip
end
def xcode_frameworks_path
@xcode_frameworks_path ||= xcode_path.sub('/Developer', '/Frameworks')
end
def macos_version
`sw_vers`.each_line.to_a[1].split(':').last.strip
rescue
@errors << "Unable to determine the version of Mac OS X."
nil
end
def kill_simulators_command
"sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService"
end
def verify_swift
return if swift_staged?
return unless version_to_i(rubymotion_version) >= version_to_i('6.0')
return if version_to_i(rubymotion_version) >= version_to_i("7.15") # 7.15 and above no long require this check.
if swift_runtime?
@errors << <<-S
Mojave #{macos_version}'s Swift 5 runtime was not marked as staged.
To fix this error, run the following command:
#{'sudo ' unless File.writable?(xcode_frameworks_path)}touch #{xcode_frameworks_path}/.swift-5-staged
S
else
@errors << <<-S
Mojave #{macos_version}'s Swift 5 runtime was not found in Xcode.
To fix this error, run the following commands:
#{'sudo ' unless File.writable?(xcode_frameworks_path)}cp -r /usr/lib/swift/*.dylib #{xcode_frameworks_path}/
#{'sudo ' unless File.writable?(xcode_frameworks_path)}touch #{xcode_frameworks_path}/.swift-5-staged
S
end
end
def swift_staged?
File.exist?(File.expand_path("#{xcode_frameworks_path}/.swift-5-staged"))
end
def swift_runtime?
Dir["#{xcode_frameworks_path}/libswift*.dylib"].any?
end
def verify_community_templates
unless rubymotion_templates?
@errors << "It doesn't look like you have RubyMotion templates downloaded. Please run `motion repo`."
end
unless File.exist?(File.expand_path "~/.rubymotion/rubymotion-templates/required-marker-62")
@errors << "It doesn't look like you have the latest RubyMotion templates downloaded. Please run `motion repo`."
end
end
def rubymotion_templates?
Dir.exist?(File.expand_path("~/.rubymotion/rubymotion-templates"))
end
def verify_community_commands
unless rubymotion_commands?
@errors << "It doesn't look like you have RubyMotion commands downloaded. Please run `motion repo`."
end
unless File.exist?(File.expand_path "~/.rubymotion/rubymotion-command/required-marker-62")
@errors << "It doesn't look like you have the latest RubyMotion commands downloaded. Please run `motion repo`."
end
end
def rubymotion_commands?
Dir.exist?(File.expand_path("~/.rubymotion/rubymotion-command"))
end
def xcode_versions
{
'10.3' => '6.2',
'10.2' => '6.1',
}
end
def max_xcode_version
xcode_versions.keys.map do |k|
version_to_i k
end.max
end
def version_to_i s
s.to_s.gsub(".", "").to_i
end
def compare_xcode_versions version
version.to_s.gsub(".", "").to_i
end
def rubymotion_version
@rubymotion_version ||= `motion --version`.strip
end
def xcode_version
`xcodebuild -version`.lines
.first
.strip
.gsub('Xcode', '')
.split('.')
.map(&:strip)
.take(2)
.join('.')
end
def bold(text)
"\e[1m#{text}\e[0m"
end
def color(c, text)
code = { red: 31, green: 32 }[c]
"\e[#{code}m#{text}\e[0m"
end
end
end; end