Class: Rake::Delphi::Dcc32Task

Inherits:
Task
  • Object
show all
Defined in:
lib/rake/delphi/dcc32.rb

Instance Attribute Summary collapse

Attributes inherited from Task

#logger

Instance Method Summary collapse

Methods inherited from Task

#execute_base, #initialize_base, #needed=, #needed?, #out, #reenable_chain, #shortname, #trace?

Constructor Details

#initialize(name, application) ⇒ Dcc32Task

Returns a new instance of Dcc32Task.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rake/delphi/dcc32.rb', line 31

def initialize(name, application)
    super
    initvars
    @arg_names = [:verbose]
    @rc_template_task = application.define_task(RCTemplateTask, shortname + ':rc:template')
    @rc_task = application.define_task(RCTask, shortname + ':rc')
    enhance([@rc_template_task, @rc_task])
    @platform = nil
    @platform_stripped = nil
    @dccToolClass = nil
    recreate_dcc_tool
end

Instance Attribute Details

#_source=(value) ⇒ Object

Sets the attribute _source

Parameters:

  • value

    the value to set the attribute _source to.



17
18
19
# File 'lib/rake/delphi/dcc32.rb', line 17

def _source=(value)
  @_source = value
end

#binObject

Returns the value of attribute bin.



17
18
19
# File 'lib/rake/delphi/dcc32.rb', line 17

def bin
  @bin
end

#dccToolObject (readonly)

Returns the value of attribute dccTool.



18
19
20
# File 'lib/rake/delphi/dcc32.rb', line 18

def dccTool
  @dccTool
end

#exeoutputObject

Returns the value of attribute exeoutput.



17
18
19
# File 'lib/rake/delphi/dcc32.rb', line 17

def exeoutput
  @exeoutput
end

#mainiconObject

Returns the value of attribute mainicon.



17
18
19
# File 'lib/rake/delphi/dcc32.rb', line 17

def mainicon
  @mainicon
end

#systempathObject

Returns the value of attribute systempath.



17
18
19
# File 'lib/rake/delphi/dcc32.rb', line 17

def systempath
  @systempath
end

Instance Method Details

#createVersionInfoObject



62
63
64
# File 'lib/rake/delphi/dcc32.rb', line 62

def createVersionInfo
    versionInfoClass.new(self)
end

#dcu=(value) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rake/delphi/dcc32.rb', line 66

def dcu=(value)
  # delete previously defined
  @prerequisites.delete_if do |d|
    if d.kind_of?(Rake::FileCreationTask)
       d.name.casecmp(@dcu) == 0
    end
  end
  @dcu = value
  dcu_task = directory @dcu
  enhance([dcu_task])
end

#dprObject



220
221
222
# File 'lib/rake/delphi/dcc32.rb', line 220

def dpr
  @_source
end

#execute(opts = nil) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/rake/delphi/dcc32.rb', line 275

def execute(opts=nil)
    super
    recreate_dcc_tool
    @dccTool.class.checkToolFailure(@dccTool.toolpath)
    fail "Could not find #{_source} to compile" unless @_source && File.exists?(@_source)
    init_libs
    args = build_args
    # on cygwin $D is assumed as shell var
    # so escape $
    args.map! { |a| a.gsub('$', '\$') if a.kind_of?(String) } unless application.windows?
    args.compact!
    cmd = Rake.quotepath('', @dccTool.toolpath)
    cmd << ([''] | args).join(' ')
    ChDir.new(self, File.dirname(@_source)) do |dir|
        RakeFileUtils.verbose(Logger.debug?) do
            begin
                unless @usecfg
                    cfg = @systempath.pathmap('%X.cfg')
                    bak_cfg = @systempath.pathmap('%X.rake.cfg')
                    if File.exists?(cfg)
                        mv cfg, bak_cfg
                    else
                        warn "WARNING! Config #{cfg} is absent!"
                    end
                    if @altercfg
                        cp @altercfg, cfg
                    end
                    # on Windows there is some limit on command line parameters length
                    # so we just append path parameters to config file
                    File.open(cfg, 'a+') do |f|
                        paths.each do |p|
                            f.write(p + "\n")
                        end
                    end
                end
                sh cmd
            ensure
                unless @usecfg
                    begin
                        cp cfg, cfg + '.1' if trace?
                    ensure
                        mv bak_cfg, cfg if File.exists?(bak_cfg)
                    end
                end
            end
        end
    end
    puts '' # make one empty string to separate from further lines
end

#init(properties) ⇒ Object



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
255
256
257
258
259
260
261
262
# File 'lib/rake/delphi/dcc32.rb', line 224

def init(properties)
    Logger.trace(Logger::TRACE, properties)
    properties.map do |key, value|
        begin
            send("#{key}=", value)
        rescue NoMethodError
            instance_variable_set("@#{key}", value)
        end
    end
    @_source = properties[:projectfile].pathmap('%X.dpr')
    src = @_source.gsub('\\', '/')
    # make sure to create dir for output dcu
    # for now default is <PROJECTDIR>/dcu
    self.dcu = src.pathmap('%d%sdcu') unless @dcu
    # mainicon is usually requested by RCTemplate
    @mainicon ||= Rake.quotepath('', src.pathmap('%X.ico'))
    @rc_template_task.output = src
    @rc_template_task[:version] = properties[:version]
    @rc_template_task[:releaseCandidate] = properties[:releaseCandidate]
    @rc_task.input = src
    @rc_task.is_rc = properties[:releaseCandidate]
    @rc_task.mainicon_path = @mainicon
    return unless properties[:resources_additional]
    res_add = properties[:resources_additional]
    if res_add.kind_of?(String)
        res_add = res_add.split(';')
    end
    c = 0
    res_add.each do |res|
        if res.kind_of?(Symbol)
            rc_task_add = res
        else
            c = c.next
            rc_task_add = application.define_task(RCTask, shortname + ':rc:add' + c.to_s)
            rc_task_add.input = src.pathmap('%d%s') + res
        end
        enhance([rc_task_add])
    end
end

#init_libs(libs = nil) ⇒ Object



264
265
266
267
268
269
270
271
272
273
# File 'lib/rake/delphi/dcc32.rb', line 264

def init_libs(libs = nil)
    unless libs
        # call parent to find libs
        application[name.gsub(/:dcc32$/, '')].init_libs
    else
        # called from parent
        # set libs
        @includepaths = libs
    end
end

#platform=(value) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rake/delphi/dcc32.rb', line 78

def platform=(value)
    @platform = value
    Logger.trace(Logger::DEBUG, 'PLATFORM set: ' + value)
    # strip digits from platform name Android
    @platform_stripped = @platform
    @platform_stripped = @platform.gsub(/\d/, '') if @platform.downcase.starts_with?('android')
    @dccToolClass = nil
    post_needed = false
    if @platform_stripped.downcase.to_sym == :android
        # set dccaarm compiler tool for Android platform
        @dccToolClass = DccARMTool
        post_needed = true
    end
    # enable appropriate PAClientTask
    application[name + ':post'].needed = post_needed
    # for XE and above set default aliases and namespaces
    if EnvVariables.delphi_version >= DELPHI_VERSION_XE
        @aliases = 'Generics.Collections=System.Generics.Collections;Generics.Defaults=System.Generics.Defaults;WinTypes=Winapi.Windows;WinProcs=Winapi.Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE'
        @namespaces = 'Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;System;Xml;Data;Datasnap;Web;Soap'
        Logger.trace(Logger::TRACE, 'Aliases and namespaces are set for Delphi XE')
    end
end

#recreate_dcc_tool(checkExistance = false) ⇒ Object



44
45
46
47
48
49
# File 'lib/rake/delphi/dcc32.rb', line 44

def recreate_dcc_tool(checkExistance = false)
    @dccToolClass ||= Dcc32Tool
    @dccToolClass.reinit
    @dccTool = @dccToolClass.new(checkExistance)
    Logger.trace(Logger::DEBUG, name + ': DCC tool set: ' + @dccToolClass.to_s)
end

#reenableObject

used in tests



52
53
54
55
56
# File 'lib/rake/delphi/dcc32.rb', line 52

def reenable
    # recreate Dcc32Tool to reinitialize paths to tool
    recreate_dcc_tool(true)
    super
end

#versionInfoClassObject



58
59
60
# File 'lib/rake/delphi/dcc32.rb', line 58

def versionInfoClass
    @dccTool.versionInfoClass
end