Class: Rake::Delphi::CustomDelphiTool

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

Direct Known Subclasses

Dcc32Tool, RCResourceCompiler

Constant Summary collapse

DelphiRegRoot =
'SOFTWARE\\Borland\\Delphi'
BDSRegRoot =
'SOFTWARE\\Borland\\BDS'
EDSRegRoot =
'SOFTWARE\\CodeGear\\BDS'

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CustomExec

#execute, #to_system_path

Methods inherited from BasicTask

#trace?

Constructor Details

#initializeCustomDelphiTool

Returns a new instance of CustomDelphiTool.



19
20
21
# File 'lib/rake/delphi/tool.rb', line 19

def initialize
    @@version, @@delphidir, @@toolpath = self.class.find unless @@version
end

Class Method Details

.checkToolFailure(toolpath) ⇒ Object



134
135
136
# File 'lib/rake/delphi/tool.rb', line 134

def self.checkToolFailure(toolpath)
    fail 'Could not find %s: (%s)' % [toolName, toolpath.to_s] unless File.exists?(toolpath.to_s)
end

.find(failIfNotFound = false) ⇒ Object



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

def self.find(failIfNotFound = false)
    v = ENV['DELPHI_VERSION']
    if 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..14).each { |n| v << n.to_s }
        v.reverse!
    else
        v = [v]
    end
    v.each do |ver|
        path = readDelphiDir(ver)
        next unless path
        tool = path + toolName
        if File.exists?(tool) # found it !
            ENV['DELPHI_VERSION'] = ver
            ENV['DELPHI_DIR'] = path
            return ver, path, tool
        end
    end
    checkToolFailure(nil) if failIfNotFound
    return nil
end

.readDelphiDir(ver) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rake/delphi/tool.rb', line 84

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
                regRoot.open(rootForVersion(ver)) do |reg|
                    reg_typ, reg_val = reg.read('RootDir')
                    return reg_val.gsub('\\', '/')
                end
            rescue ::Win32::Registry::Error
            end
        end
        return nil
    rescue LoadError
        return nil
    end
end

.readUserOption(key, name, ver) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rake/delphi/tool.rb', line 43

def self.readUserOption(key, name, ver)
    begin
        require 'win32/registry'
        root = rootForVersion(ver) + '\\' + key
        begin
            ::Win32::Registry::HKEY_CURRENT_USER.open(root) do |reg|
                reg_typ, reg_val = reg.read(name)
                return reg_val.gsub('\\', '/')
            end
        rescue ::Win32::Registry::Error
            return ''
        end
    rescue LoadError
        return ''
    end
end

.reinitObject

used mainly in tests



14
15
16
# File 'lib/rake/delphi/tool.rb', line 14

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

.rootForVersion(version) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rake/delphi/tool.rb', line 70

def self.rootForVersion(version)
    if version.to_f < 9
        regRoot = DelphiRegRoot
    else
        if version.to_f < 12
            regRoot = BDSRegRoot
        else
            regRoot = EDSRegRoot
        end
    end
    version = version4version(version)
    return regRoot + '\\' + version
end

.toolNameObject



23
24
25
# File 'lib/rake/delphi/tool.rb', line 23

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

.version4version(version) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/rake/delphi/tool.rb', line 60

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

#delphidirObject



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

def delphidir
    @@delphidir
end

#toolpathObject



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

def toolpath
    @@toolpath
end

#versionObject



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

def version
    @@version
end

#versionInfoClassObject



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

def versionInfoClass
    return @@version.to_f < 11 ? BDSVersionInfo : RAD2007VersionInfo
end