Files
RubyMotion/lib/motion/project/template/ios/builder.rb
Mark Villacampa f1367ced8d Added support for codesigning extensions.
Conflicts:
	lib/motion/project/template/ios/builder.rb
2014-08-20 18:12:38 +09:00

143 lines
5.9 KiB
Ruby

# encoding: utf-8
# Copyright (c) 2012, HipByte SPRL and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require 'motion/project/builder'
module Motion; module Project
class Builder
def archive(config)
# Create .ipa archive.
app_bundle = config.app_bundle('iPhoneOS')
archive = config.archive
if !File.exist?(archive) or File.mtime(app_bundle) > File.mtime(archive)
App.info 'Create', archive
tmp = "/tmp/ipa_root"
sh "/bin/rm -rf #{tmp}"
sh "/bin/mkdir -p #{tmp}/Payload"
sh "/bin/cp -r \"#{app_bundle}\" #{tmp}/Payload"
Dir.chdir(tmp) do
sh "/bin/chmod -R 755 Payload"
sh "/usr/bin/zip -q -r archive.zip Payload"
end
sh "/bin/cp #{tmp}/archive.zip \"#{archive}\""
end
# Create manifest file (if needed).
manifest_plist = File.join(config.versionized_build_dir('iPhoneOS'), 'manifest.plist')
manifest_plist_data = config.manifest_plist_data
if manifest_plist_data and (!File.exist?(manifest_plist) or File.mtime(config.project_file) > File.mtime(manifest_plist))
App.info 'Create', manifest_plist
File.open(manifest_plist, 'w') { |io| io.write(manifest_plist_data) }
end
end
def codesign(config, platform)
bundle_path = config.app_bundle(platform)
raise unless File.exist?(bundle_path)
# Prepare extensions
config.extensions.each do |extension|
resource_rules_plist = create_resourcerules_file(extension.extension_path(platform))
copy_provisioning_profile(extension.extension_path(platform), config)
codesign_executable(extension.extension_path(platform), resource_rules_plist, extension, platform)
end
# Create bundle/ResourceRules.plist.
resource_rules_plist = create_resourcerules_file(bundle_path)
# Copy the provisioning profile.
copy_provisioning_profile(bundle_path, config)
# Codesign.
codesign_executable(bundle_path, resource_rules_plist, config, platform)
end
def create_resourcerules_file(path)
resource_rules_plist = File.join(path, 'ResourceRules.plist')
unless File.exist?(resource_rules_plist)
App.info 'Create', resource_rules_plist
File.open(resource_rules_plist, 'w') do |io|
io.write(<<-PLIST)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>rules</key>
<dict>
<key>.*</key>
<true/>
<key>Info.plist</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>ResourceRules.plist</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>100</real>
</dict>
</dict>
</dict>
</plist>
PLIST
end
end
resource_rules_plist
end
def copy_provisioning_profile(path, config)
bundle_provision = File.join(path, "embedded.mobileprovision")
App.info 'Create', bundle_provision
FileUtils.cp config.provisioning_profile, bundle_provision
end
def codesign_executable(path, resource_rules_plist, config, platform)
codesign_cmd = "CODESIGN_ALLOCATE=\"#{File.join(config.platform_dir(platform), 'Developer/usr/bin/codesign_allocate')}\" /usr/bin/codesign"
app_frameworks = File.join(config.app_bundle(platform), 'Frameworks')
config.embedded_frameworks.each do |framework|
framework_path = File.join(app_frameworks, File.basename(framework))
if File.mtime(config.project_file) > File.mtime(framework_path) \
or !system("#{codesign_cmd} --verify \"#{framework_path}\" >& /dev/null")
App.info 'Codesign', framework_path
sh "#{codesign_cmd} -f -s \"#{config.codesign_certificate}\" --preserve-metadata=\"identifier,entitlements,resource-rules\" \"#{framework_path}\""
end
end
if File.mtime(config.project_file) > File.mtime(path) \
or !system("#{codesign_cmd} --verify \"#{path}\" >& /dev/null")
App.info 'Codesign', path
entitlements = config.entitlements_path(platform)
File.open(entitlements, 'w') { |io| io.write(config.entitlements_data) }
sh "#{codesign_cmd} -f -s \"#{config.codesign_certificate}\" --resource-rules=\"#{resource_rules_plist}\" --entitlements #{entitlements} \"#{path}\""
end
end
end
end; end