[WatchKit] Refactor to have a dedicated watch app config in the watch extension config.

INCEPTION! http://i.imgur.com/q5TAM.gif
This commit is contained in:
Eloy Durán
2014-11-27 14:55:54 +01:00
parent 7a3078ee06
commit cfd78f4a2c
3 changed files with 90 additions and 42 deletions

View File

@@ -28,19 +28,19 @@ require 'motion/project/template/ios-extension-builder'
module Motion; module Project
class Builder
def build_watch_app(config, platform, opts)
watch_app_bundle_path = config.watch_app_bundle(platform)
# Copy watch app binary
FileUtils.mkdir_p watch_app_bundle_path
sh "/usr/bin/ditto -rsrc \"#{File.join(config.sdk(platform), "/Library/Application\ Support/SP/SP.app/SP")}\" \"#{watch_app_bundle_path}/#{config.watch_app_name}\""
FileUtils.mkdir_p config.app_bundle(platform)
source = config.prebuilt_app_executable(platform)
destination = config.app_bundle_executable(platform)
sh "/usr/bin/ditto -rsrc '#{source}' '#{destination}'"
# Compile storyboard
sh "/usr/bin/ibtool --errors --warnings --notices --module #{config.bundle_name.gsub(" ", "_")} --minimum-deployment-target #{config.sdk_version} --output-partial-info-plist /tmp/Interface-SBPartialInfo.plist --auto-activate-custom-fonts --output-format human-readable-text --compilation-directory \"#{watch_app_bundle_path}\" watch_app/Interface.storyboard"
sh "/usr/bin/ibtool --errors --warnings --notices --module #{config.escaped_storyboard_module_name} --minimum-deployment-target #{config.sdk_version} --output-partial-info-plist /tmp/Interface-SBPartialInfo.plist --auto-activate-custom-fonts --output-format human-readable-text --compilation-directory '#{config.app_bundle(platform)}' watch_app/Interface.storyboard"
end
def build_watch_extension(config, platform, opts)
build_extension(config, platform, opts)
build_watch_app(config, platform, opts)
build_watch_app(config.watch_app_config, platform, opts)
end
alias_method "build_extension", "build"
alias_method "build", "build_watch_extension"

View File

@@ -24,6 +24,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require 'motion/project/template/ios-extension-config'
require 'motion/project/template/ios/config'
module Motion; module Project;
class IOSWatchExtensionConfig < IOSExtensionConfig
@@ -34,41 +35,10 @@ module Motion; module Project;
super
end
# @return [String] The name of the application.
# @return [WatchAppConfig] A config instance for the watch application.
#
def watch_app_name
bundle_name.sub(" WatchKit Extension", '') + " Watch App"
end
# @return [String] The application bundle filename.
#
def watch_app_bundle_name
"#{watch_app_name}.app"
end
# @param [String] platform
# The platform identifier that's being build for, such as
# `iPhoneSimulator` or `iPhoneOS`.
#
# @return [String] The path to the application bundle in this extension's
# build directory.
#
def watch_app_bundle(platform)
File.join(app_bundle(platform), watch_app_bundle_name)
end
# @return [String] The path to the application bundle inside the host
# application in its build directory.
#
def embedded_watch_app_bundle
File.join(ENV['RM_TARGET_DESTINATION_BUNDLE_PATH'], watch_app_bundle_name)
end
# @return [String] The path to the application executable inside the host
# application in its build directory.
#
def embedded_watch_app_executable
File.join(embedded_watch_app_bundle, watch_app_name)
def watch_app_config
@watch_app_config ||= WatchAppConfig.new(@project_dir, @build_mode, self)
end
def main_cpp_file_txt(spec_objs)
@@ -110,5 +80,82 @@ EOS
}
EOS
end
# This config class is mostly used to re-use existing filename/path APIs as
# they are in any other iOS application and to build an Info.plist.
#
# We do not actually compile this application, it's only assembled from an
# existing `SP.app` application template inside the SDK.
#
class WatchAppConfig < IOSConfig
def initialize(project_dir, build_mode, extension_config)
super(project_dir, build_mode)
@name = nil
@files = []
@resources_dirs = []
@specs_dir = nil
@detect_dependencies = false
@delegate_class = "SPApplicationDelegate"
@extension_config = extension_config
end
def sdk_version
@extension_config.sdk_version
end
def deployment_target
@extension_config.deployment_target
end
# @return [String] The name of the watch application based on the name of
# the watch extension.
#
def name
@name ||= @extension_config.name.sub(" WatchKit Extension", '') + " Watch App"
end
# @param [String] platform
# The platform identifier that's being build for, such as
# `iPhoneSimulator` or `iPhoneOS`.
#
# @return [String] The path to the application bundle in this extension's
# build directory.
#
def app_bundle(platform)
File.join(@extension_config.app_bundle(platform), bundle_filename)
end
# @return [String] The path to the application bundle inside the host
# application in its build directory.
#
def embedded_app_bundle
File.join(ENV['RM_TARGET_DESTINATION_BUNDLE_PATH'], bundle_filename)
end
# @return [String] The path to the application executable inside the host
# application in its build directory.
#
def embedded_app_bundle_executable
File.join(embedded_app_bundle, name)
end
# @return [String] The path to the SockPuppet application executable that
# we copy and use as-is.
#
def prebuilt_app_executable(platform)
File.join(sdk(platform), "/Library/Application Support/SP/SP.app/SP")
end
# @todo Do we really need this? `man ibtool` seems to indicate it's needed
# when the document references a Swift class.
#
# @return [String] The module name to include in applicable custom class
# names at runtime.
#
def escaped_storyboard_module_name
@extension_config.bundle_name.gsub(" ", "_")
end
end
end
end; end

View File

@@ -83,8 +83,9 @@ end
# and the normal iOS task to launch on the sim.
desc "Run the simulator"
task :simulator do
app = App.config.embedded_watch_app_bundle
app_executable = File.expand_path(App.config.embedded_watch_app_executable)
config = App.config.watch_app_config
app = config.embedded_app_bundle
app_executable = File.expand_path(config.embedded_app_bundle_executable)
if ENV['TMUX']
tmux_default_command = `tmux show-options -g default-command`.strip