Class: Rake::Delphi::CustomDelphiTool
Constant Summary
collapse
- DelphiRegRoot =
'SOFTWARE\\Borland\\Delphi'
- BDSRegRoot =
'SOFTWARE\\Borland\\BDS'
- EDSRegRoot =
'SOFTWARE\\CodeGear\\BDS'
- EmbarcaderoRegRoot =
'SOFTWARE\\Embarcadero\\BDS'
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from CustomExec
#execute, #to_system_path
Methods inherited from BasicTask
#trace?
Constructor Details
#initialize(checkExistance = false) ⇒ CustomDelphiTool
Returns a new instance of CustomDelphiTool.
22
23
24
|
# File 'lib/rake/delphi/tool.rb', line 22
def initialize(checkExistance = false)
@@version, @@delphidir, @@toolpath = self.class.find(checkExistance) unless @@version
end
|
Class Method Details
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/rake/delphi/tool.rb', line 164
def self.checkToolFailure(toolpath)
if toolpath.kind_of?(TrueClass) || toolpath.kind_of?(FalseClass)
unless toolpath
fail 'Could not detect path for %s! Check your registry and DELPHI_VERSION environment variable.' % [toolName]
end
cond = ! toolpath
toolpath = ''
else
cond = File.exists?(toolpath)
end
fail 'Could not find %s: (%s)' % [toolName, toolpath] unless cond
end
|
.find(failIfNotFound = false) ⇒ Object
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
|
# File 'lib/rake/delphi/tool.rb', line 126
def self.find(failIfNotFound = false)
v = EnvVariables.delphi_version
if ENV['DELPHI_DIR']
Logger.trace(Logger::DEBUG, 'DELPHI_DIR is set: ' + ENV['DELPHI_DIR'])
ENV['DELPHI_DIR'] = ENV['DELPHI_DIR'].gsub(/[^\/]$/, '\&/')
tool = ENV['DELPHI_DIR'] + toolName
checkToolFailure(tool) if failIfNotFound
return v, ENV['DELPHI_DIR'], tool
end
if v.to_s.empty?
v = []
(4..20).each { |n| v << n.to_s }
v.reverse!
else
Logger.trace(Logger::DEBUG, 'DELPHI_VERSION is set: ' + v)
v = [v]
end
tool_was_found = false
v.each do |ver|
path = readDelphiDir(ver)
next unless path
tool = path + toolName
tool_was_found = true
Logger.trace(Logger::DEBUG, "Got tool: '#{tool}'")
if File.exists?(tool)
ENV['DELPHI_VERSION'] = ver
ENV['DELPHI_DIR'] = path
Logger.trace(Logger::DEBUG, "Set: DELPHI_VERSION=#{ver}; DELPHI_DIR='#{path}'")
return ver, path, tool
else
Logger.trace(Logger::DEBUG, 'But file does not exist!')
end
end
checkToolFailure(tool_was_found) if failIfNotFound
return nil
end
|
.readDelphiDir(ver) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/rake/delphi/tool.rb', line 103
def self.readDelphiDir(ver)
begin
require 'win32/registry'
[::Win32::Registry::HKEY_LOCAL_MACHINE, \
::Win32::Registry::HKEY_CURRENT_USER].each do |regRoot|
begin
Logger.trace(Logger::DEBUG, "Finding Delphi dir for #{ver}")
regRoot.open(rootForVersion(ver)) do |reg|
reg_typ, reg_val = reg.read('RootDir')
return reg_val.gsub('\\', '/')
end
rescue ::Win32::Registry::Error
Logger.trace(Logger::DEBUG, "No reg key '#{regRoot}'?!")
end
end
return nil
rescue LoadError
Logger.trace(Logger::DEBUG, 'No `win32/registry` gem?!')
return nil
end
end
|
.readUserOption(key, name, ver) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/rake/delphi/tool.rb', line 52
def self.readUserOption(key, name, ver)
begin
require 'win32/registry'
root = rootForVersion(ver) + '\\' + key
key_exists = false
begin
Logger.trace(Logger::DEBUG, "Reading user option '#{name}' in '#{root}'")
::Win32::Registry::HKEY_CURRENT_USER.open(root) do |reg|
key_exists = true
reg_typ, reg_val = reg.read(name)
return reg_val.gsub('\\', '/')
end
rescue ::Win32::Registry::Error
Logger.trace(Logger::DEBUG, "No reg key '%s'?!" % \
(key_exists ? "#{root}\\#{name}" : root))
return ''
end
rescue LoadError
Logger.trace(Logger::DEBUG, 'No `win32/registry` gem?!')
return ''
end
end
|
.reinit ⇒ Object
16
17
18
|
# File 'lib/rake/delphi/tool.rb', line 16
def self.reinit
@@version, @@delphidir, @@toolpath = nil, nil, nil
end
|
.rootForVersion(version) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/rake/delphi/tool.rb', line 85
def self.rootForVersion(version)
if version.to_f < 9
regRoot = DelphiRegRoot
else
if version.to_f < 12
regRoot = BDSRegRoot
elsif version.to_f < 14
regRoot = EDSRegRoot
else
regRoot = EmbarcaderoRegRoot
end
end
version = version4version(version)
regRoot = regRoot + '\\' + version
Logger.trace(Logger::DEBUG, "Root for version #{version}: '#{regRoot}'")
return regRoot
end
|
26
27
28
|
# File 'lib/rake/delphi/tool.rb', line 26
def self.toolName
raise 'Abstract method "toolName". Override it'
end
|
.version4version(version) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/rake/delphi/tool.rb', line 75
def self.version4version(version)
if version.to_f >= 9
version = format('%.1f', version.to_f - 6)
end
if !version["."]
version << ".0"
end
return version
end
|
Instance Method Details
#delphidir ⇒ Object
38
39
40
|
# File 'lib/rake/delphi/tool.rb', line 38
def delphidir
@@delphidir
end
|
#options ⇒ Object
42
43
44
|
# File 'lib/rake/delphi/tool.rb', line 42
def options
''
end
|
34
35
36
|
# File 'lib/rake/delphi/tool.rb', line 34
def toolpath
@@toolpath
end
|
#version ⇒ Object
30
31
32
|
# File 'lib/rake/delphi/tool.rb', line 30
def version
@@version
end
|
#versionInfoClass ⇒ Object
46
47
48
49
50
|
# File 'lib/rake/delphi/tool.rb', line 46
def versionInfoClass
return @@version.to_f < 11 ? BDSVersionInfo : \
@@version.to_f < 13 ? RAD2007VersionInfo : \
@@version.to_f < 14 ? RAD2010VersionInfo : XEVersionInfo
end
|