Skip to content

Commit

Permalink
Load SkyX files on iOS where available
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde committed Jul 28, 2015
1 parent a342f44 commit 64e29f7
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 54 deletions.
28 changes: 16 additions & 12 deletions build/config/ios/ios_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,25 @@
'plutil'
]

def MakeDirectories(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
return 0
else:
return -1

return 0


def ProcessInfoPlist(args):
output_plist_file = os.path.abspath(os.path.join(args.output, 'Info.plist'))

print os.path.dirname(output_plist_file)
if MakeDirectories(os.path.dirname(output_plist_file)) == -1:
return -1

return subprocess.check_call( PLUTIL + [
'-convert',
'binary1',
Expand All @@ -42,18 +58,6 @@ def PerformCodeSigning(args):
])


def MakeDirectories(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
return 0
else:
return -1

return 0


def GenerateProjectStructure(args):
application_path = os.path.join( args.dir, args.name + ".app" )
return MakeDirectories( application_path )
Expand Down
10 changes: 7 additions & 3 deletions build/config/ios/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ template("resource_copy_ios") {
set_sources_assignment_filter([])
sources = _resources
outputs = [ "$root_build_dir/$_app_name.app/$_bundle_directory/{{source_file_part}}" ]

if (defined(invoker.deps)) {
deps = invoker.deps
}
}
}

Expand Down Expand Up @@ -115,14 +119,14 @@ template("ios_app") {
script = ios_app_script

sources = [ invoker.info_plist ]
outputs = [ "$root_build_dir/Info.plist" ]
outputs = [ "$root_build_dir/plist/$app_name/Info.plist" ]

args = [
"plist",
"-i",
rebase_path(invoker.info_plist, root_build_dir),
"-o",
rebase_path(root_build_dir),
rebase_path("$root_build_dir/plist/$app_name"),
]
}

Expand All @@ -131,7 +135,7 @@ template("ios_app") {
copy_gen_target_name = target_name + "_copy"
copy(copy_gen_target_name) {
sources = [
"$root_build_dir/Info.plist",
"$root_build_dir/plist/$app_name/Info.plist",
"$root_build_dir/$app_name",
]

Expand Down
42 changes: 41 additions & 1 deletion sky/build/sky_app.gni
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import("//sky/build/skyx.gni")
template("sky_app") {
skyx_target_name = target_name

if (is_android) {
if (is_android || is_ios) {
skyx_target_name = "app"
}

Expand Down Expand Up @@ -89,5 +89,45 @@ template("sky_app") {
deps += invoker.deps
}
}
} else if (is_ios && defined(invoker.info_plist)) {
import("//build/config/ios/rules.gni")
import("//build/config/ios/ios_sdk.gni")

ios_app(target_name) {
app_name = target_name + "_app"

code_signing_identity = ios_code_signing_identity

info_plist = invoker.info_plist

if (defined(invoker.entitlements_path)) {
entitlements_path = invoker.entitlements_path
} else {
entitlements_path = "//sky/shell/ios/Entitlements.xcent"
}

resources_gen_target_name = target_name + "_res"
resource_copy_ios(resources_gen_target_name) {
resources = [
"//third_party/icu/android/icudtl.dat",
"$target_gen_dir/app.skyx",
]
bundle_directory = "."
deps = [ ":app" ]
}

deps = [
"//sky/shell:ios_scaffolding",
":$resources_gen_target_name",
":$skyx_target_name",
]

if (defined(invoker.deps)) {
deps += invoker.deps
}
}
} else {
group(target_name) {
}
}
}
2 changes: 2 additions & 0 deletions sky/packages/sky/example/game/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ sky_app("game") {
deps = [
"//sky/packages/sky/example/game/apk:resources",
]
} else if (is_ios) {
info_plist = "ios/Info.plist"
}
}
52 changes: 52 additions & 0 deletions sky/sdk/example/game/ios/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>

<!--
This executable name must match the name of the app provided to the
ios_app GN template
-->
<key>CFBundleExecutable</key>
<string>game_app</string>

<key>CFBundleIdentifier</key>
<string>org.domokit.sky.game</string>

<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>game_app</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>DTPlatformName</key>
<string>iphonesimulator</string>
<key>DTSDKName</key>
<string>iphonesimulator8.3</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
<string>8.3</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneSimulator</string>
</array>
</dict>
</plist>
61 changes: 32 additions & 29 deletions sky/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,40 @@ if (is_android) {
import("//build/config/ios/rules.gni")
import("//build/config/ios/ios_sdk.gni")

group("ios_shell_scaffolding") {

}

source_set("ios_scaffolding") {
sources = [
"ios/main_ios.mm",
"ios/sky_app_delegate.h",
"ios/sky_app_delegate.mm",
"ios/sky_surface.h",
"ios/sky_surface.mm",
"ios/sky_view_controller.h",
"ios/sky_view_controller.mm",
]

set_sources_assignment_filter([])
sources += [
"mac/platform_mac.h",
"mac/platform_mac.mm",
"mac/platform_service_provider_mac.cc",
"mac/platform_view_mac.h",
"mac/platform_view_mac.mm",
]
set_sources_assignment_filter(sources_assignment_filter)

deps = common_deps + [
":common",
"//sky/services/ns_net",
]
}

ios_app("shell") {
app_name = "SkyShell"
info_plist = "ios/Info.plist"
scaffolding_target = "ios_scaffolding"
entitlements_path = "ios/Entitlements.xcent"
code_signing_identity = ios_code_signing_identity

Expand All @@ -181,35 +211,8 @@ if (is_android) {
bundle_directory = "."
}

source_set(scaffolding_target) {
sources = [
"ios/main_ios.mm",
"ios/sky_app_delegate.h",
"ios/sky_app_delegate.mm",
"ios/sky_surface.h",
"ios/sky_surface.mm",
"ios/sky_view_controller.h",
"ios/sky_view_controller.mm",
]

set_sources_assignment_filter([])
sources += [
"mac/platform_mac.h",
"mac/platform_mac.mm",
"mac/platform_service_provider_mac.cc",
"mac/platform_view_mac.h",
"mac/platform_view_mac.mm",
]
set_sources_assignment_filter(sources_assignment_filter)

deps = common_deps + [
":common",
"//sky/services/ns_net",
]
}

deps = [
":$scaffolding_target",
":ios_scaffolding",
":sky_resources",
]
}
Expand Down
28 changes: 19 additions & 9 deletions sky/shell/ios/sky_surface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,32 @@ - (void)notifySurfaceCreation {
}

- (NSString*)skyInitialLoadURL {
NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
NSString *target = [standardDefaults stringForKey:@"target"];
NSString *server = [standardDefaults stringForKey:@"server"];
if (server && target) {
return [NSString stringWithFormat:@"http://%@/%@", server, target];
}

return [NSBundle mainBundle].infoDictionary[@"org.domokit.sky.load_url"];
}

- (NSString*)skyInitialBundleURL {
return [[NSBundle mainBundle] pathForResource:@"app" ofType:@"skyx"];
}

- (void)connectToEngineAndLoad {
auto interface_request = mojo::GetProxy(&_sky_engine);
self.platformView->ConnectToEngine(interface_request.Pass());

mojo::String string(self.skyInitialLoadURL.UTF8String);
_sky_engine->RunFromNetwork(string);
NSString *endpoint = self.skyInitialBundleURL;
if (endpoint.length > 0) {
// Load from bundle
mojo::String string(endpoint.UTF8String);
_sky_engine->RunFromBundle(string);
return;
}

endpoint = self.skyInitialLoadURL;
if (endpoint.length > 0) {
// Load from URL
mojo::String string(endpoint.UTF8String);
_sky_engine->RunFromNetwork(string);
return;
}
}

- (void)notifySurfaceDestruction {
Expand Down

0 comments on commit 64e29f7

Please sign in to comment.