mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-06-19 18:24:16 +08:00
Added support for codesigning extensions.
Conflicts: lib/motion/project/template/ios/builder.rb
This commit is contained in:
@@ -146,6 +146,10 @@ module Motion; module Project;
|
||||
# Build vendor libraries.
|
||||
vendor_libs = build_vendor_libs(extension, platform)
|
||||
|
||||
# Prepare embedded and external frameworks BridgeSupport files (OSX-only).
|
||||
embedded_frameworks = prepare_embedded_frameworks(extension, platform)
|
||||
external_frameworks = prepare_external_frameworks(extension, platform)
|
||||
|
||||
# Build object files.
|
||||
objs_build_dir = File.join(build_dir, 'objs')
|
||||
FileUtils.mkdir_p(objs_build_dir)
|
||||
@@ -180,7 +184,7 @@ module Motion; module Project;
|
||||
or vendor_libs.any? { |lib| File.mtime(lib) > File.mtime(extension_exec) } \
|
||||
or File.mtime(librubymotion) > File.mtime(extension_exec)
|
||||
|
||||
extension_exec_created = link_executable(extension_exec, extension_objs, init_o, main_extension_o, embedded_frameworks, external_frameworks, should_link_executable, config, platform)
|
||||
extension_exec_created = link_executable(extension_exec, extension_objs, init_o, main_extension_o, embedded_frameworks, external_frameworks, should_link_executable, extension, platform)
|
||||
|
||||
# Create extension Info.plist.
|
||||
extension_info_plist = File.join(extension_path, 'Info.plist')
|
||||
@@ -204,7 +208,8 @@ module Motion; module Project;
|
||||
@reserved_app_bundle_files = [
|
||||
'_CodeSignature/CodeResources', 'CodeResources', 'embedded.mobileprovision',
|
||||
'Info.plist', 'PkgInfo', 'ResourceRules.plist',
|
||||
convert_filesystem_encoding([config.identifier, extension.name].join('.'))
|
||||
convert_filesystem_encoding([config.identifier, extension.name].join('.')),
|
||||
extension.entitlements_filename
|
||||
]
|
||||
|
||||
# Copy resources, handle subdirectories.
|
||||
|
||||
@@ -70,8 +70,9 @@ module Motion; module Project;
|
||||
config.supported_sdk_versions(versions)
|
||||
end
|
||||
|
||||
def common_plist_data(identifier)
|
||||
def common_plist_data(platform, identifier)
|
||||
{
|
||||
'BuildMachineOSBuild' => `sw_vers -buildVersion`.strip,
|
||||
'CFBundleDevelopmentRegion' => 'en',
|
||||
'CFBundleDisplayName' => @name,
|
||||
'CFBundleExecutable' => [identifier, @name].join('.'),
|
||||
@@ -81,7 +82,18 @@ module Motion; module Project;
|
||||
'CFBundlePackageType' => 'XPC!',
|
||||
'CFBundleShortVersionString' => (@short_version || @version),
|
||||
'CFBundleSignature' => @bundle_signature,
|
||||
'CFBundleVersion' => @version
|
||||
'CFBundleVersion' => config.version,
|
||||
'MinimumOSVersion' => config.deployment_target,
|
||||
'CFBundleResourceSpecification' => 'ResourceRules.plist',
|
||||
'CFBundleSupportedPlatforms' => [config.deploy_platform],
|
||||
'UIDeviceFamily' => config.device_family_ints.map { |x| ENV['__USE_DEVICE_INT__'] ? x.to_i : x.to_s },
|
||||
'DTXcodeBuild' => config.xcode_version[1],
|
||||
'DTSDKName' => "#{platform.downcase}#{sdk_version}",
|
||||
'DTSDKBuild' => config.sdk_build_version(platform),
|
||||
'DTPlatformName' => platform.downcase,
|
||||
'DTCompiler' => 'com.apple.compilers.llvm.clang.1_0',
|
||||
'DTPlatformVersion' => config.sdk_version,
|
||||
'DTPlatformBuild' => config.sdk_build_version(platform),
|
||||
}
|
||||
end
|
||||
|
||||
@@ -92,7 +104,7 @@ module Motion; module Project;
|
||||
'NSExtensionPrincipalClass' => 'TodayViewController',
|
||||
'NSExtensionPointIdentifier' => 'com.apple.widget-extension'
|
||||
}
|
||||
}.merge(common_plist_data(identifier)))
|
||||
}.merge(common_plist_data(platform, identifier)))
|
||||
end
|
||||
|
||||
def keyboard_service_plist_data(platform, identifier)
|
||||
@@ -102,7 +114,7 @@ module Motion; module Project;
|
||||
'NSExtensionPrincipalClass' => 'KeyboardViewController',
|
||||
'NSExtensionPointIdentifier' => 'com.apple.keyboard-service'
|
||||
}
|
||||
}.merge(common_plist_data(identifier)))
|
||||
}.merge(common_plist_data(platform, identifier)))
|
||||
end
|
||||
|
||||
def share_services_plist_data(platform, identifier)
|
||||
@@ -112,7 +124,7 @@ module Motion; module Project;
|
||||
'NSExtensionPrincipalClass' => 'ShareViewController',
|
||||
'NSExtensionPointIdentifier' => 'com.apple.share-services'
|
||||
}
|
||||
}.merge(common_plist_data(identifier)))
|
||||
}.merge(common_plist_data(platform, identifier)))
|
||||
end
|
||||
|
||||
def photo_editing_plist_data(platform, identifier)
|
||||
@@ -122,7 +134,7 @@ module Motion; module Project;
|
||||
'NSExtensionPrincipalClass' => 'PhotoEditingViewController',
|
||||
'NSExtensionPointIdentifier' => 'com.apple.photo-editing'
|
||||
}
|
||||
}.merge(common_plist_data(identifier)))
|
||||
}.merge(common_plist_data(platform, identifier)))
|
||||
end
|
||||
|
||||
def fileprovider_nonui_photo_editing_plist_data(platform, identifier)
|
||||
@@ -132,7 +144,7 @@ module Motion; module Project;
|
||||
'NSExtensionPrincipalClass' => 'FileProvider',
|
||||
'NSExtensionPointIdentifier' => 'com.apple.fileprovider-nonui'
|
||||
}
|
||||
}.merge(common_plist_data(identifier)))
|
||||
}.merge(common_plist_data(platform, identifier)))
|
||||
end
|
||||
|
||||
def ui_services_plist_data(platform, identifier)
|
||||
@@ -142,7 +154,37 @@ module Motion; module Project;
|
||||
'NSExtensionPrincipalClass' => 'ActionViewController',
|
||||
'NSExtensionPointIdentifier' => 'com.apple.ui-services'
|
||||
}
|
||||
}.merge(common_plist_data(identifier)))
|
||||
}.merge(common_plist_data(platform, identifier)))
|
||||
end
|
||||
|
||||
def fileprovider_ui_photo_editing_plist_data(platform, identifier)
|
||||
Motion::PropertyList.to_s({
|
||||
'NSExtension' => {
|
||||
'NSExtensionAttributes' => self.attributes,
|
||||
'NSExtensionPrincipalClass' => 'DocumentPickerViewController',
|
||||
'NSExtensionPointIdentifier' => 'com.apple.fileprovider-ui'
|
||||
}
|
||||
}.merge(common_plist_data(platform, identifier)))
|
||||
end
|
||||
|
||||
def entitlements_data
|
||||
dict = entitlements.dup
|
||||
if ['fileprovider-ui', 'fileprovider-nonui'].include? type
|
||||
dict['com.apple.security.application-groups'] = config.identifier
|
||||
end
|
||||
Motion::PropertyList.to_s(dict)
|
||||
end
|
||||
|
||||
def entitlements_filename
|
||||
"#{@name}.entitlements"
|
||||
end
|
||||
|
||||
def entitlements_path(platform)
|
||||
File.join(extension_path(platform), entitlements_filename)
|
||||
end
|
||||
|
||||
def codesign_certificate
|
||||
config.codesign_certificate
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -57,8 +57,25 @@ module Motion; module Project
|
||||
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 = File.join(bundle_path, '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|
|
||||
@@ -91,13 +108,16 @@ module Motion; module Project
|
||||
PLIST
|
||||
end
|
||||
end
|
||||
resource_rules_plist
|
||||
end
|
||||
|
||||
# Copy the provisioning profile.
|
||||
bundle_provision = File.join(bundle_path, "embedded.mobileprovision")
|
||||
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
|
||||
|
||||
# Codesign.
|
||||
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|
|
||||
@@ -109,13 +129,14 @@ PLIST
|
||||
end
|
||||
end
|
||||
|
||||
if File.mtime(config.project_file) > File.mtime(bundle_path) \
|
||||
or !system("#{codesign_cmd} --verify \"#{bundle_path}\" >& /dev/null")
|
||||
App.info 'Codesign', bundle_path
|
||||
entitlements = File.join(config.versionized_build_dir(platform), "Entitlements.plist")
|
||||
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} \"#{bundle_path}\""
|
||||
sh "#{codesign_cmd} -f -s \"#{config.codesign_certificate}\" --resource-rules=\"#{resource_rules_plist}\" --entitlements #{entitlements} \"#{path}\""
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end; end
|
||||
|
||||
@@ -156,6 +156,14 @@ module Motion; module Project;
|
||||
Motion::PropertyList.to_s(dict)
|
||||
end
|
||||
|
||||
def entitlements_filename
|
||||
"Entitlements.plist"
|
||||
end
|
||||
|
||||
def entitlements_path(platform)
|
||||
File.join(versionized_build_dir(platform), entitlements_filename)
|
||||
end
|
||||
|
||||
def common_flags(platform)
|
||||
simulator_version = begin
|
||||
flag = " -miphoneos-version-min=#{deployment_target}"
|
||||
@@ -335,10 +343,6 @@ module Motion; module Project;
|
||||
app_bundle(platform)
|
||||
end
|
||||
|
||||
def app_extensions_dir(platform)
|
||||
File.join(app_bundle(platform), 'PlugIns')
|
||||
end
|
||||
|
||||
def fonts
|
||||
@fonts ||= begin
|
||||
resources_dirs.flatten.inject([]) do |fonts, dir|
|
||||
|
||||
@@ -105,6 +105,14 @@ module Motion; module Project;
|
||||
Motion::PropertyList.to_s(dict)
|
||||
end
|
||||
|
||||
def entitlements_filename
|
||||
"Entitlements.plist"
|
||||
end
|
||||
|
||||
def entitlements_path(platform)
|
||||
File.join(versionized_build_dir(platform), entitlements_filename)
|
||||
end
|
||||
|
||||
def common_flags(platform)
|
||||
super + " -mmacosx-version-min=#{deployment_target}"
|
||||
end
|
||||
|
||||
@@ -464,6 +464,9 @@ EOS
|
||||
@vendor_projects.each { |vendor| vendor.clean }
|
||||
end
|
||||
|
||||
def app_extensions_dir(platform)
|
||||
File.join(app_bundle(platform), 'PlugIns')
|
||||
end
|
||||
|
||||
def extension_main_cpp_file_txt(spec_objs)
|
||||
main_txt = <<EOS
|
||||
|
||||
Reference in New Issue
Block a user