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, #out, #shortname, #trace?

Constructor Details

#initialize(name, application) ⇒ Dcc32Task

Returns a new instance of Dcc32Task.



61
62
63
64
65
66
67
68
69
70
# File 'lib/rake/delphi/dcc32.rb', line 61

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
    @dcc32Tool = Dcc32Tool.new
end

Instance Attribute Details

#_source=(value) ⇒ Object

Sets the attribute _source

Parameters:

  • value

    the value to set the attribute _source to.



48
49
50
# File 'lib/rake/delphi/dcc32.rb', line 48

def _source=(value)
  @_source = value
end

#binObject

Returns the value of attribute bin.



48
49
50
# File 'lib/rake/delphi/dcc32.rb', line 48

def bin
  @bin
end

#exeoutput=(value) ⇒ Object

Sets the attribute exeoutput

Parameters:

  • value

    the value to set the attribute exeoutput to.



48
49
50
# File 'lib/rake/delphi/dcc32.rb', line 48

def exeoutput=(value)
  @exeoutput = value
end

#mainiconObject

Returns the value of attribute mainicon.



48
49
50
# File 'lib/rake/delphi/dcc32.rb', line 48

def mainicon
  @mainicon
end

#systempathObject

Returns the value of attribute systempath.



48
49
50
# File 'lib/rake/delphi/dcc32.rb', line 48

def systempath
  @systempath
end

Instance Method Details

#execute(opts = nil) ⇒ Object



266
267
268
269
270
271
272
273
274
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
# File 'lib/rake/delphi/dcc32.rb', line 266

def execute(opts=nil)
    @dcc32Tool.class.checkToolFailure(@dcc32Tool.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('', @dcc32Tool.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



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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
# File 'lib/rake/delphi/dcc32.rb', line 209

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('\\', '/')
    dcu = src.pathmap('%d%sdcu')
    # make sure to create dir for output dcu
    # for now default is <PROJECTDIR>/dcu
    directory dcu
    enhance([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]
    mainicon_path = File.expand_path2(Rake.unquotepath(@mainicon))
    @rc_task.is_main_icon = File.exists?(mainicon_path)
    unless @rc_task.is_main_icon
        warn "WARNING! Icon file '#{mainicon_path}' does not exists. Application icon is disabled."
    end
    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



255
256
257
258
259
260
261
262
263
264
# File 'lib/rake/delphi/dcc32.rb', line 255

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

#reenableObject

used in tests



73
74
75
76
77
# File 'lib/rake/delphi/dcc32.rb', line 73

def reenable
    # recreate Dcc32Tool to reinitialize paths to tool
    @dcc32Tool = Dcc32Tool.new(true)
    super
end

#versionInfoClassObject



79
80
81
# File 'lib/rake/delphi/dcc32.rb', line 79

def versionInfoClass
    @dcc32Tool.versionInfoClass
end