From be72a3ff473eae2a25736a06dce98b89313f7e2a Mon Sep 17 00:00:00 2001 From: Francisco Tolmasky Date: Tue, 19 May 2009 03:54:54 -0700 Subject: [PATCH] Allow fully building capp apps with Rake, and added to template Rakefiles. Reviewed by me. --- Tools/Rake/lib/objective-j/bundletask.rb | 53 ++++++++++++++++---- Tools/capp/Generate.j | 48 +++++++++--------- Tools/capp/Templates/Application/Rakefile | 3 +- Tools/capp/Templates/NibApplication/Rakefile | 3 +- 4 files changed, 71 insertions(+), 36 deletions(-) diff --git a/Tools/Rake/lib/objective-j/bundletask.rb b/Tools/Rake/lib/objective-j/bundletask.rb index baa7f14cc..8ed8be5f9 100644 --- a/Tools/Rake/lib/objective-j/bundletask.rb +++ b/Tools/Rake/lib/objective-j/bundletask.rb @@ -199,6 +199,8 @@ module ObjectiveJ attributes :email, :homepage, :github_project, :description, :license_file, :license attributes :build_path, :intermediates_path attribute :principal_class + attribute :index_file + attribute :info_plist # attributes :autorequire, :default_executable # attribute :platform, Gem::Platform::RUBY @@ -402,18 +404,49 @@ module ObjectiveJ end end - info_plist_path = build_path + '/Info.plist' - info_plist = { 'CPBundleName' => name, 'CPBundleIdentifier' => identifier, 'CPBundleInfoDictionaryVersion' => 6.0, 'CPBundleVersion' => version, 'CPBundlePackageType' => Bundle::Type.code_string(type) } + if type == Bundle::Type::Application and index_file + + index_file_path = File.join(build_path, File.basename(index_file)) + + file_d index_file_path => [index_file] do |t| + cp(index_file, t.name) + end + + enhance([index_file_path]) + + frameworks_path = File.join(build_path, 'Frameworks') + + file_d frameworks_path do + IO.popen("capp gen -f " + build_path) do |capp| + capp.sync = true + + while str = capp.gets + puts str + end + end + end + + enhance([frameworks_path]) + end + + info_plist_path = File.join(build_path, 'Info.plist') + new_info_plist = { 'CPBundleName' => name, 'CPBundleIdentifier' => identifier, 'CPBundleInfoDictionaryVersion' => 6.0, 'CPBundleVersion' => version, 'CPBundlePackageType' => Bundle::Type.code_string(type) } - info_plist['CPBundlePlatforms'] = platforms; + new_info_plist['CPBundlePlatforms'] = platforms; + + if info_plist + existing_info_plist = Plist::parse_xml(info_plist) + new_info_plist = new_info_plist.merge existing_info_plist + file_d info_plist_path => [info_plist] + end if principal_class - info_plist['CPPrincipalClass'] = principal_class + new_info_plist['CPPrincipalClass'] = principal_class end file_d info_plist_path do File.open(info_plist_path, 'w') do |file| - file.puts info_plist.to_plist + file.puts new_info_plist.to_plist end end @@ -488,13 +521,13 @@ module ObjectiveJ puts 'Compacting ' + path info_plist_path = File.join(path, 'Info.plist') - info_plist = Plist::parse_xml(info_plist_path) + existing_info_plist = Plist::parse_xml(info_plist_path) absolute_path = File.expand_path(path) + '/' patterns = patterns.map { |pattern| "#{path}/#{pattern}" } - bundle_name = info_plist['CPBundleName'] + bundle_name = existing_info_plist['CPBundleName'] replaced_files = [] FileList.new(File.join(path, '**', '*.platform')).each do |platform| @@ -529,11 +562,11 @@ module ObjectiveJ end end - info_plist['CPBundleReplacedFiles'] = replaced_files.uniq - info_plist['CPBundleExecutable'] = bundle_name + '.sj' + existing_info_plist['CPBundleReplacedFiles'] = replaced_files.uniq + existing_info_plist['CPBundleExecutable'] = bundle_name + '.sj' File.open(info_plist_path, 'w') do |file| - file.puts info_plist.to_plist + file.puts existing_info_plist.to_plist end end diff --git a/Tools/capp/Generate.j b/Tools/capp/Generate.j index f4c4fc8cf..7fd47e515 100644 --- a/Tools/capp/Generate.j +++ b/Tools/capp/Generate.j @@ -48,34 +48,34 @@ function gen(/*va_args*/) destinationProject = new java.io.File(destination), configuration = noConfig ? [Configuration defaultConfiguration] : [Configuration userConfiguration]; - if (!destinationProject.exists()) + if (justFrameworks) + createFrameworksInFile(destinationProject, shouldSymbolicallyLink); + + else if (!destinationProject.exists()) { - if (!justFrameworks) + exec(["cp", "-vR", sourceTemplate.getCanonicalPath(), destinationProject.getCanonicalPath()], true); + + var files = getFiles(destinationProject), + index = 0, + count = files.length, + name = String(destinationProject.getName()), + orgIdentifier = [configuration valueForKey:@"organization.identifier"] || ""; + + [configuration setTemporaryValue:name forKey:@"project.name"]; + [configuration setTemporaryValue:orgIdentifier + '.' + toIdentifier(name) forKey:@"project.identifier"]; + [configuration setTemporaryValue:toIdentifier(name) forKey:@"project.nameasidentifier"]; + + for (; index < count; ++index) { - exec(["cp", "-vR", sourceTemplate.getCanonicalPath(), destinationProject.getCanonicalPath()], true); + var path = files[index], + contents = File.read(path, { charset : "UTF-8" }), + key = nil, + keyEnumerator = [configuration keyEnumerator]; - var files = getFiles(destinationProject), - index = 0, - count = files.length, - name = String(destinationProject.getName()), - orgIdentifier = [configuration valueForKey:@"organization.identifier"] || ""; + while (key = [keyEnumerator nextObject]) + contents = contents.replace(new RegExp("__" + key + "__", 'g'), [configuration valueForKey:key]); - [configuration setTemporaryValue:name forKey:@"project.name"]; - [configuration setTemporaryValue:orgIdentifier + '.' + toIdentifier(name) forKey:@"project.identifier"]; - [configuration setTemporaryValue:toIdentifier(name) forKey:@"project.nameasidentifier"]; - - for (; index < count; ++index) - { - var path = files[index], - contents = File.read(path, { charset : "UTF-8" }), - key = nil, - keyEnumerator = [configuration keyEnumerator]; - - while (key = [keyEnumerator nextObject]) - contents = contents.replace(new RegExp("__" + key + "__", 'g'), [configuration valueForKey:key]); - - File.write(path, contents, { charset: "UTF-8"}); - } + File.write(path, contents, { charset: "UTF-8"}); } createFrameworksInFile(destinationProject, shouldSymbolicallyLink); diff --git a/Tools/capp/Templates/Application/Rakefile b/Tools/capp/Templates/Application/Rakefile index 44dce7c54..4b319769e 100644 --- a/Tools/capp/Templates/Application/Rakefile +++ b/Tools/capp/Templates/Application/Rakefile @@ -15,7 +15,8 @@ ObjectiveJ::BundleTask.new(:__project.nameasidentifier__) do |t| t.summary = '__project.name__' t.sources = FileList['*.j'] t.resources = FileList['Resources/*'] - t.license = ObjectiveJ::License::LGPL_v2_1 + t.index_file = 'index.html' + t.info_plist = 'Info.plist' t.build_path = File.join('Build', ENV['CONFIG'], '__project.nameasidentifier__') t.flag = '-DDEBUG' if ENV['CONFIG'] == 'Debug' t.flag = '-O' if ENV['CONFIG'] == 'Release' diff --git a/Tools/capp/Templates/NibApplication/Rakefile b/Tools/capp/Templates/NibApplication/Rakefile index 44dce7c54..4b319769e 100644 --- a/Tools/capp/Templates/NibApplication/Rakefile +++ b/Tools/capp/Templates/NibApplication/Rakefile @@ -15,7 +15,8 @@ ObjectiveJ::BundleTask.new(:__project.nameasidentifier__) do |t| t.summary = '__project.name__' t.sources = FileList['*.j'] t.resources = FileList['Resources/*'] - t.license = ObjectiveJ::License::LGPL_v2_1 + t.index_file = 'index.html' + t.info_plist = 'Info.plist' t.build_path = File.join('Build', ENV['CONFIG'], '__project.nameasidentifier__') t.flag = '-DDEBUG' if ENV['CONFIG'] == 'Debug' t.flag = '-O' if ENV['CONFIG'] == 'Release'