[xcassets] Move iOS/OS X specific behavior back to configs.

This commit is contained in:
Eloy Durán
2013-10-14 13:52:32 +02:00
parent f84096688a
commit d22f82ebb0
4 changed files with 55 additions and 39 deletions

View File

@@ -337,29 +337,12 @@ EOS
preserve_resources = []
# Compile Asset Catalog bundles.
xcassets_bundles = []
config.resources_dirs.each do |dir|
if File.exist?(dir)
xcassets_bundles.concat(Dir.glob(File.expand_path(File.join(dir, '*.xcassets'))))
end
end
unless xcassets_bundles.empty?
ios = config.deploy_platform == 'iPhoneOS'
app_icons_asset_bundles = xcassets_bundles.map { |b| Dir.glob(File.join(b, '*.appiconset')) }.flatten
if app_icons_asset_bundles.size > 1
App.warn "Found #{app_icons_asset_bundles.size} app icon sets across all " \
"xcasset bundles. Only the first one (alphabetically) " \
"will be used."
end
if app_icons_asset_bundle = app_icons_asset_bundles.sort.first
preserve_resources = ios ? config.icons : [config.icon]
app_icon_name = File.basename(app_icons_asset_bundle, '.appiconset')
# TODO We can potentially use the plist output to identify the icon
# names for the config, instead of parsing the JSON. This also
# guards against the Contents.json format changing.
app_icons_info_plist = ios ? File.expand_path(File.join(build_dir, 'AppIcon.plist')) : '/dev/null'
app_icons_options = "--output-partial-info-plist \"#{app_icons_info_plist}\" --app-icon \"#{app_icon_name}\""
assets_bundles = config.assets_bundles
unless assets_bundles.empty?
app_icons_asset_bundle = config.app_icons_asset_bundle
if app_icons_asset_bundle
app_icons_options = "--output-partial-info-plist \"#{config.app_icons_info_plist_path(platform)}\" " \
"--app-icon \"#{config.app_icon_name_from_asset_bundle}\""
end
app_resources_dir = File.expand_path(config.app_resources_dir(platform))
@@ -369,7 +352,7 @@ EOS
"--minimum-deployment-target #{config.deployment_target} " \
"#{Array(config.device_family).map { |d| "--target-device #{d}" }.join(' ')} " \
"#{app_icons_options} " \
"--compress-pngs --compile \"#{app_resources_dir}\" \"#{xcassets_bundles.join('" "')}\""
"--compress-pngs --compile \"#{app_resources_dir}\" \"#{assets_bundles.join('" "')}\""
# TODO should be quiet normally
puts cmd
actool_output = `#{cmd}`.strip
@@ -386,23 +369,11 @@ EOS
unless actool_compiled_files
App.fail 'TODO'
end
actool_compiled_files.pop
# Remove the partial Info.plist line.
actool_compiled_files.pop if app_icons_asset_bundle
preserve_resources.concat(actool_compiled_files)
# Extract the app icon file(s) name(s) and assign it to the config.
if app_icons_asset_bundle
if ios
app_icons_info_plist_content = `/usr/libexec/PlistBuddy -c 'Print :CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles' "#{app_icons_info_plist}"`.strip
lines = app_icons_info_plist_content.split("\n")
if lines.size < 2
App.fail 'TODO'
end
config.icons = lines[1..-2]
else
# On Mac there is only ever one icns file.
config.icon = app_icon_name
end
end
config.configure_app_icons_from_asset_bundle(platform) if app_icons_asset_bundle
end
# Compile CoreData Model resources and SpriteKit atlas files.

View File

@@ -57,6 +57,18 @@ module Motion; module Project;
end
end
def app_icons_info_plist_path(platform)
File.expand_path(File.join(versionized_build_dir(platform), 'AppIcon.plist'))
end
def configure_app_icons_from_asset_bundle(platform)
path = app_icons_info_plist_path(platform)
if File.exist?(path)
content = `/usr/libexec/PlistBuddy -c 'Print :CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles' "#{path}"`.strip
self.icons = content.split("\n")[1..-2]
end
end
def validate
# icons
if !(icons.is_a?(Array) and icons.all? { |x| x.is_a?(String) })

View File

@@ -68,6 +68,15 @@ module Motion; module Project;
archs
end
def app_icons_info_plist_path(platform)
'/dev/null'
end
# On OS X only one file is output. E.g. NAME.icns
def configure_app_icons_from_asset_bundle(platform)
self.icon = app_icon_name_from_asset_bundle
end
def locate_compiler(platform, *execs)
execs.each do |exec|
cc = File.join('/usr/bin', exec)

View File

@@ -322,5 +322,29 @@ EOS
path = File.join(xcode_dir, 'usr/bin/TextureAtlas')
File.exist?(path) ? path : nil
end
def assets_bundles
xcassets_bundles = []
resources_dirs.each do |dir|
if File.exist?(dir)
xcassets_bundles.concat(Dir.glob(File.expand_path(File.join(dir, '*.xcassets'))))
end
end
xcassets_bundles
end
def app_icons_asset_bundle
app_icons_asset_bundles = assets_bundles.map { |b| Dir.glob(File.join(b, '*.appiconset')) }.flatten
if app_icons_asset_bundles.size > 1
App.warn "Found #{app_icons_asset_bundles.size} app icon sets across all " \
"xcasset bundles. Only the first one (alphabetically) " \
"will be used."
end
app_icons_asset_bundles.sort.first
end
def app_icon_name_from_asset_bundle
File.basename(app_icons_asset_bundle, '.appiconset')
end
end
end; end