mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-09 04:07:12 +00:00
147 lines
4.7 KiB
Ruby
147 lines
4.7 KiB
Ruby
require 'rake'
|
|
require 'objective-j/plist'
|
|
|
|
module ObjectiveJ
|
|
|
|
# Create a package based upon a Gem spec. Gem packages, as well as
|
|
# zip files and tar/gzipped packages can be produced by this task.
|
|
#
|
|
# In addition to the Rake targets generated by PackageTask, a
|
|
# GemPackageTask will also generate the following tasks:
|
|
#
|
|
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.gem"</b>]
|
|
# Create a Ruby GEM package with the given name and version.
|
|
#
|
|
# Example using a Ruby GEM spec:
|
|
#
|
|
# require 'rubygems'
|
|
#
|
|
# spec = Gem::Specification.new do |s|
|
|
# s.platform = Gem::Platform::RUBY
|
|
# s.summary = "Ruby based make-like utility."
|
|
# s.name = 'rake'
|
|
# s.version = PKG_VERSION
|
|
# s.requirements << 'none'
|
|
# s.require_path = 'lib'
|
|
# s.autorequire = 'rake'
|
|
# s.files = PKG_FILES
|
|
# s.description = <<EOF
|
|
# Rake is a Make-like program implemented in Ruby. Tasks
|
|
# and dependencies are specified in standard Ruby syntax.
|
|
# EOF
|
|
# end
|
|
#
|
|
# Rake::GemPackageTask.new(spec) do |pkg|
|
|
# pkg.need_zip = true
|
|
# pkg.need_tar = true
|
|
# end
|
|
#
|
|
class BundleTask < Rake::Task
|
|
|
|
# Objective-J Bundle spec containing the metadata for this bundle.
|
|
attr_accessor :bundle_spec
|
|
|
|
def self.overwrite_accessor(name, &block)
|
|
remove_method name
|
|
define_method(name, &block)
|
|
end
|
|
|
|
overwrite_accessor :bundle_spec= do |spec|
|
|
|
|
@bundle_spec = spec
|
|
|
|
@bundle_spec.validate
|
|
|
|
resources_path = File.join(@bundle_spec.build_path, 'Resources')
|
|
copied_resources = []
|
|
|
|
# create file tasks for copied resources
|
|
@bundle_spec.resources.each do |resource|
|
|
|
|
copied_resource = File.join(resources_path, File.basename(resource))
|
|
|
|
file_d copied_resource => [resource] do
|
|
cp_r(resource, resources_path)
|
|
end
|
|
|
|
copied_resources << copied_resource
|
|
end
|
|
|
|
objects_path = @bundle_spec.intermediates_path
|
|
objects = []
|
|
replaced_files = []
|
|
|
|
# create file tasks for object files
|
|
@bundle_spec.sources.each do |source|
|
|
|
|
object_path = File.join(objects_path, File.basename(source, File.extname(source))) + '.o'
|
|
flags = []
|
|
|
|
@bundle_spec.flags.each do |flag|
|
|
flags << '-D' + flag
|
|
end
|
|
|
|
file_d object_path => source do
|
|
IO.popen("objjc #{flags.join(' ')} #{source} -o #{object_path}") do |objjc|
|
|
puts objjc.read
|
|
end
|
|
end
|
|
|
|
objects << object_path
|
|
replaced_files << File.basename(source)
|
|
end
|
|
|
|
#the actual executable path
|
|
executable_path = File.join(@bundle_spec.build_path, @bundle_spec.name + '.sj')
|
|
|
|
# copy license file
|
|
license_path = nil
|
|
|
|
# check if a license type has been specified
|
|
if @bundle_spec.license != nil
|
|
|
|
copied_license = @bundle_spec.build_path + '/LICENSE'
|
|
|
|
case @bundle_spec.license
|
|
when License::LGPL_v2_1
|
|
license_path = File.expand_path(File.join(File.dirname(__FILE__), '../LGPL-v2.1'))
|
|
else
|
|
license_path = license
|
|
end
|
|
|
|
file_d executable_path => copied_license
|
|
|
|
file_d copied_license => license_path do
|
|
cp(license_path, copied_license)
|
|
end
|
|
end
|
|
|
|
file executable_path => objects do
|
|
|
|
File.open(executable_path, "w") do |file|
|
|
|
|
file.write('@STATIC;1.0;')
|
|
|
|
objects.each do |object|
|
|
file.write(IO.read(object))
|
|
end
|
|
end
|
|
end
|
|
|
|
info_plist_path = @bundle_spec.build_path + '/Info.plist'
|
|
info_plist = @bundle_spec.info_plist
|
|
|
|
info_plist['CPBundleExecutable'] = File.basename(executable_path)
|
|
info_plist['CPBundleReplacedFiles'] = replaced_files
|
|
|
|
file_d info_plist_path do
|
|
File.open(info_plist_path, 'w') do |file|
|
|
file.puts info_plist.to_plist
|
|
end
|
|
end
|
|
|
|
enhance(copied_resources + [executable_path, info_plist_path])
|
|
end
|
|
end
|
|
end
|