-
Notifications
You must be signed in to change notification settings - Fork 5
/
toolchains.rb
52 lines (43 loc) · 1.26 KB
/
toolchains.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
require 'json'
require './process.rb'
# Toolchains are managed by sdk-manage --toolchain
# The class provides a cached list of objects via class.each() and class.get(name)
class Toolchain
include Enumerable
attr_accessor :name, :installed
@@toolchains={}
UPDATE_VALID_PERIOD=7200
@@last_update_check=Time.at(0)
def initialize(name, installed)
@name = name
@installed = installed
end
# Installs a toolchain to the filesystem
def install()
if ! @installed
puts "sdk-manage --toolchain --install '#{@name}'"
CCProcess.start("sdk-manage --toolchain --install '#{@name}'", (_ :adding_toolchain) + " #{@name}", 60*60)
end
end
# Cached information from sdk-manage
def self._toolchains()
if (Time.now - @@last_update_check) > UPDATE_VALID_PERIOD then
@@toolchains = {}
CCProcess.complete("sdk-manage --toolchain --list").split.map {|line| line.split(',') }.map { |tc, i| @@toolchains[tc] = Toolchain.new(tc, (i == 'i')) }
end
@@toolchains
rescue CCProcess::Failed
@@toolchains = {} #FIXME: nil if can't read the list!
end
def self.get(name)
_toolchains[name]
end
def self.exists(name)
get(name) != nil
end
def self.each
for name, obj in _toolchains do
yield obj
end
end
end