Class: Rake::Delphi::CustomDelphiTool

Inherits:
CustomExec show all
Defined in:
lib/rake/delphi/tool.rb

Direct Known Subclasses

Dcc32Tool, PAClientTool, RCResourceCompiler

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.



27
28
29
# File 'lib/rake/delphi/tool.rb', line 27

def initialize(checkExistance = false)
    @@version, @@delphidir, @@toolpath = self.class.find(checkExistance) unless @@version
end

Class Method Details

.checkToolFailure(toolpath) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/rake/delphi/tool.rb', line 169

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



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
# File 'lib/rake/delphi/tool.rb', line 131

def self.find(failIfNotFound = false)
    v = EnvVariables.delphi_version.to_s
    if ENV['DELPHI_DIR']
        Logger.trace(Logger::DEBUG, 'DELPHI_DIR is set: ' + ENV['DELPHI_DIR'])
        # append trailing path delimiter
        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..21).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) # found it !
            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



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rake/delphi/tool.rb', line 108

def self.readDelphiDir(ver)
    begin
        require 'win32/registry'
        [::Win32::Registry::HKEY_LOCAL_MACHINE, \
                # for local/manual installations
                ::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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rake/delphi/tool.rb', line 57

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

.reinitObject



21
22
23
# File 'lib/rake/delphi/tool.rb', line 21

def self.reinit
    @@version, @@delphidir, @@toolpath = nil, nil, nil
end

.rootForVersion(version) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rake/delphi/tool.rb', line 90

def self.rootForVersion(version)
    if version.to_f < DELPHI_VERSION_7
        regRoot = DelphiRegRoot
    else
        if version.to_f <= DELPHI_VERSION_2006
            regRoot = BDSRegRoot
        elsif version.to_f < DELPHI_VERSION_XE
            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

.toolNameObject



31
32
33
# File 'lib/rake/delphi/tool.rb', line 31

def self.toolName
    raise 'Abstract method "toolName". Override it'
end

.version4version(version) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/rake/delphi/tool.rb', line 80

def self.version4version(version)
    if version.to_f >= DELPHI_VERSION_7
        version = format('%.1f', version.to_f - 6)
    end
    if !version["."]
        version << ".0"
    end
    return version
end

Instance Method Details

#delphidirObject



43
44
45
# File 'lib/rake/delphi/tool.rb', line 43

def delphidir
  @@delphidir
end

#optionsObject



47
48
49
# File 'lib/rake/delphi/tool.rb', line 47

def options
    ''
end

#toolpathObject



39
40
41
# File 'lib/rake/delphi/tool.rb', line 39

def toolpath
    @@toolpath
end

#versionObject



35
36
37
# File 'lib/rake/delphi/tool.rb', line 35

def version
    @@version
end

#versionInfoClassObject



51
52
53
54
55
# File 'lib/rake/delphi/tool.rb', line 51

def versionInfoClass
    return @@version.to_f < DELPHI_VERSION_2006 ? BDSVersionInfo : \
        @@version.to_f < DELPHI_VERSION_2010 ? RAD2007VersionInfo : \
        @@version.to_f < DELPHI_VERSION_XE ? RAD2010VersionInfo : XEVersionInfo
end