Class: Rake::CocoaBundle

Inherits:
CocoaTask show all
Defined in:
lib/rake/cocoa.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from CocoaTask

#generate_compilation_tasks

Constructor Details

#initialize {|_self| ... } ⇒ CocoaBundle

Returns a new instance of CocoaBundle.

Yields:

  • (_self)

Yield Parameters:



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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/rake/cocoa.rb', line 295

def initialize
  @name = :bundle
  @bundle = "RubyObjC"
  @identifier = 'com.rubyobjc.bundle'
  @info = nil
  @resources = []

  @arch = "-arch i386 -arch ppc"  # build universal by default
  @cflags = "-g -Wall"

  @frameworks = %w{Cocoa}
  @libs = %w{objc}
  @lib_dirs = []
  @ldflags = ""

  yield self if block_given?

  task :default => :bundle

  desc "Build the bundle."
  task :bundle => [:executable, :resources, :info_plist, :pkginfo]

  @bundle_dir      = "#{@bundle}.bundle"
  @contents_dir    = "#{@bundle_dir}/Contents"
  @executable_dir  = "#{@contents_dir}/MacOS"
  @resource_dir    = "#{@contents_dir}/Resources"
  @localized_dir   = "#{@contents_dir}/Resources/English.lproj"

  FileList[@bundle_dir, @contents_dir, @executable_dir, @resource_dir, @localized_dir].each {|d| directory d}

  generate_compilation_tasks
  
  @ruby_files = File.exist?("ruby") ? FileList['ruby/*.rb'] : FileList['*.rb'] 
  @nu_files = File.exist?("nu") ? FileList['nu/*.nu'] : FileList['*.nu'] 

  desc "Create the executable (subtask of bundle)."
  task :executable  => [:generated, @executable_dir, "#{@executable_dir}/#{@bundle}"]
  file "#{@executable_dir}/#{@bundle}" => @gcc_objects do |t|
    sh "#{@cc} #{@gcc_objects} #{@c_objects} #{@cflags} #{@arch} #{@ldflags} -o '#{t.name}' -bundle"
  end

  desc "Copy files to the bundle's Resources directory (subtask of bundle)."
  task :resources   => [@resource_dir]
  [@ruby_files, @nu_files, @icon_files, @resources].each{|list| list.each {|f|
    task :resources => "#{@resource_dir}/#{f.split("/")[-1]}"
    file "#{@resource_dir}/#{f.split("/")[-1]}" => f do |t|
      cp_r f, t.name
    end
  }}

  @nib_files.each {|f|
    g = f.split('/')[-1]
    task :resources => "#{@localized_dir}/#{g}"
    file "#{@localized_dir}/#{g}" => f do |t|
      cp_r "English.lproj/#{g}", t.name
    end
  }

  if File.exist?("lib")
    task :resources => "#{@resource_dir}/lib"
    file "#{@resource_dir}/lib" => "lib" do |t|
      sh "rm -rf #{t.name}"
      cp_r "lib", t.name
    end
  end

  desc "Create the Info.plist file (subtask of bundle)."
  task :info_plist  => [@contents_dir, "#{@contents_dir}/Info.plist"]
  file "#{@contents_dir}/Info.plist" do |t|
    info = {
      :CFBundleDevelopmentRegion => "English",
      :CFBundleExecutable => @bundle,
      :CFBundleIdentifier => @identifier,
      :CFBundleInfoDictionaryVersion => "6.0",
      :CFBundleName => @bundle,
      :CFBundlePackageType => "BNDL",
      :CFBundleSignature => @creator_code,
      :CFBundleVersion => "1.0",
      :NSPrincipalClass => @bundle
    }
    info = info.merge(@info) if @info
    plist = PList.generate(info)
    File.open(t.name, "w") {|f| f.write plist}
  end

  desc "Create the PkgInfo file (subtask of bundle)."
  task :pkginfo     => [@contents_dir, "#{@contents_dir}/PkgInfo"]
  file "#{@contents_dir}/PkgInfo" do |t|
    sh "echo -n 'APPL#{@creator_code}' > '#{t.name}'"
  end

  desc "Test the bundle."
  task :test => :bundle do
    system "ruby -rtest/unit -e0 -- -v --pattern '/test_.*\.rb^/'"
  end

  CLEAN.include("**/*.o")                             # all object files
  CLOBBER.include("*.lproj/*~.nib")			              # backup nib files
  CLOBBER.include("#{@bundle_dir}")                      # the application
  CLOBBER.include(".gdb_history")                     # support files
end

Instance Attribute Details

#archObject

Returns the value of attribute arch.



293
294
295
# File 'lib/rake/cocoa.rb', line 293

def arch
  @arch
end

#bundleObject

Returns the value of attribute bundle.



293
294
295
# File 'lib/rake/cocoa.rb', line 293

def bundle
  @bundle
end

#cflagsObject

Returns the value of attribute cflags.



293
294
295
# File 'lib/rake/cocoa.rb', line 293

def cflags
  @cflags
end

#frameworksObject

Returns the value of attribute frameworks.



293
294
295
# File 'lib/rake/cocoa.rb', line 293

def frameworks
  @frameworks
end

#icon_fileObject

Returns the value of attribute icon_file.



293
294
295
# File 'lib/rake/cocoa.rb', line 293

def icon_file
  @icon_file
end

#identifierObject

Returns the value of attribute identifier.



293
294
295
# File 'lib/rake/cocoa.rb', line 293

def identifier
  @identifier
end

#infoObject

Returns the value of attribute info.



293
294
295
# File 'lib/rake/cocoa.rb', line 293

def info
  @info
end

#ldflagsObject

Returns the value of attribute ldflags.



293
294
295
# File 'lib/rake/cocoa.rb', line 293

def ldflags
  @ldflags
end

#resourcesObject

Returns the value of attribute resources.



293
294
295
# File 'lib/rake/cocoa.rb', line 293

def resources
  @resources
end