Currently we use package: to mean "/gen", which is not at all how

Dart actually expects package: to work.  This CL makes package:foo
map to /packages/foo, similar to how Dartium or bin/dart would expect.

This also means overlaying the /gen directory over the actual package
outputs (as consumers of an SDK would expect) as well as adding
an additional /lib indirection for the actual package source as
the Dart pub tool will expect.

This is far from perfect, but it unlocks us actually producing a
sky SDK.

I expect there may be some fallout from this change as I'm sure I
missed some package: uses.  We also don't have a general solution
for all /foo/bar/baz includes which randomly included parts
of mojo's source directory.  Those will need to be updated to use
a package: and deploy_sdk.py taught how to build a package for them.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/990493002
This commit is contained in:
Eric Seidel
2015-03-13 16:58:53 -07:00
parent 06f46a22c1
commit 7cbfb05f21
8 changed files with 257 additions and 26 deletions

View File

@@ -6,34 +6,41 @@ iterating on Sky heavily, which means the framework and underlying engine are
both likely to change in incompatible ways several times, but if you're
interested in trying out the system, this document can help you get started.
Set up your computer
--------------------
1. Install the Dart SDK:
- https://www.dartlang.org/tools/download.html
2. Install the ``adb`` tool from the Android SDK:
- https://developer.android.com/sdk/installing/index.html
3. Install the Sky SDK:
- ``git clone https://github.com/domokit/sky_sdk.git``
4. Ensure sure $DART_SDK is set to the path of your Dart SDK and 'adb'
(inside 'platform-tools' in the android sdk) is in your $PATH.
Set up your device
------------------
Currently Sky requires an Android device running the Lollipop (or newer) version
of the Android operating system.
1. Install ``Sky`` on your device by via the Play Store. The Sky app on your
device is capable of displaying applications written using Sky.
2. Enable developer mode on your device by visiting ``Settings > About phone``
1. Enable developer mode on your device by visiting ``Settings > About phone``
and tapping the ``Build number`` field five times.
3. Enable ``USB debugging`` in ``Settings > Developer options``.
Set up your computer
--------------------
1. Install the ``adb`` tool from the Android SDK.
- Mac: ``brew install android-platform-tools``
- Linux: ``sudo apt-get install android-tools-adb``
2. Download the Sky framework:
- ``git clone https://github.com/domokit/sky-sdk.git``
2. Enable ``USB debugging`` in ``Settings > Developer options``.
3. Using a USB cable, plug your phone into your computer. If prompted on your
device, authorize your computer to access your device.
Running a Sky application
-------------------------
1. ``/path/to/sky-sdk/shelldb myapp.sky && adb logcat``
1. ``sky_sdk/bin/sky --install sky_sdk/examples/index.sky``
The --install flag is only necessary the first time to install SkyDemo.apk.
2. Use ``adb logcat`` to view any errors or Dart print() output from the app.

View File

@@ -3,10 +3,10 @@
<script>
import "../resources/third_party/unittest/unittest.dart";
import "../resources/unit.dart";
import "/sky/framework/embedder.dart";
import "dart:sky";
import "package:mojo/services/input_events/public/interfaces/input_event_constants.mojom.dart" as constants;
import "package:mojo/services/input_events/public/interfaces/input_events.mojom.dart" as events;
import "package:sky/framework/embedder.dart";
import "package:sky/services/testing/test_harness.mojom.dart" as harness;
void main() {

View File

@@ -7,14 +7,17 @@ import 'dart:async';
import 'dart:sky';
import 'dart:sky.internals' as internals;
import 'dart:typed_data';
import '/mojo/public/dart/application.dart';
import 'dart:mojo.bindings';
import 'dart:mojo.core';
import 'package:mojo/public/dart/application.dart';
import 'package:mojo/public/interfaces/application/shell.mojom.dart' as shell_mojom;
import 'package:mojo/services/input_events/public/interfaces/input_events.mojom.dart' as input_events;
import 'package:mojo/services/view_manager/public/interfaces/view_manager.mojom.dart' as view_manager;
import 'package:services/js/test/echo_service.mojom.dart' as echo_service_mojom;
// This include is a hack which only works with sky_server. For this to work
// in the sky_sdk, this echo_service would need to make its own dart package.
import '/gen/services/js/test/echo_service.mojom.dart' as echo_service_mojom;
class IFrameEmbed extends Application {
IFrameEmbed.fromHandle(MojoHandle handle) : super.fromHandle(handle);

View File

@@ -0,0 +1,205 @@
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
from datetime import datetime
import logging
import os
import shutil
import subprocess
import sys
# Generates the sky_sdk from the template at sky/sdk.
# This script has a split personality of both making our deployment sdk
# as well as being a required part of developing locally, since all
# of our framework assumes it's working from the SDK.
SKY_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
SKY_DIR = os.path.dirname(SKY_TOOLS_DIR)
SRC_ROOT = os.path.dirname(SKY_DIR)
DEFAULT_REL_BUILD_DIR = os.path.join('out', 'android_Release')
def git_revision():
return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
def gen_filter(path):
if os.path.isdir(path):
return True
_, ext = os.path.splitext(path)
# Don't include all .dart, just .mojom.dart.
return path.endswith('.mojom.dart')
def dart_filter(path):
if os.path.isdir(path):
return True
_, ext = os.path.splitext(path)
# .dart includes '.mojom.dart'
return ext == '.dart'
def sky_or_dart_filter(path):
if os.path.isdir(path):
return True
_, ext = os.path.splitext(path)
# .dart includes '.mojom.dart'
return ext == '.sky' or ext == '.dart'
def ensure_dir_exists(path):
if not os.path.exists(path):
os.makedirs(path)
def copy(from_root, to_root, filter_func=None):
if os.path.isfile(from_root):
ensure_dir_exists(os.path.dirname(to_root))
shutil.copy(from_root, to_root)
return
ensure_dir_exists(to_root)
for root, dirs, files in os.walk(from_root):
# filter_func expects paths not names, so wrap it to make them absolute.
wrapped_filter = None
if filter_func:
wrapped_filter = lambda name: filter_func(os.path.join(root, name))
for name in filter(wrapped_filter, files):
from_path = os.path.join(root, name)
root_rel_path = os.path.relpath(from_path, from_root)
to_path = os.path.join(to_root, root_rel_path)
to_dir = os.path.dirname(to_path)
if not os.path.exists(to_dir):
os.makedirs(to_dir)
shutil.copy(from_path, to_path)
dirs[:] = filter(wrapped_filter, dirs)
def link(from_root, to_root, filter_func=None):
ensure_dir_exists(os.path.dirname(to_root))
os.symlink(from_root, to_root)
def confirm(prompt):
response = raw_input('%s [N]|y: ' % prompt)
return response and response.lower() == 'y'
def delete_all_non_hidden_files_in_directory(root, non_interactive=False):
to_delete = [os.path.join(root, p)
for p in os.listdir(root) if not p.startswith('.')]
if not to_delete:
return
if not non_interactive:
prompt = 'This will delete everything in %s:\n%s\nAre you sure?' % (
root, '\n'.join(to_delete))
if not confirm(prompt):
print 'User aborted.'
sys.exit(2)
for path in to_delete:
if os.path.isdir(path) and not os.path.islink(path):
shutil.rmtree(path)
else:
os.remove(path)
def main():
logging.basicConfig(level=logging.WARN)
parser = argparse.ArgumentParser(description='Deploy a new sky_sdk.')
parser.add_argument('sdk_root', type=str)
parser.add_argument('--build-dir', action='store', type=str,
default=os.path.join(SRC_ROOT, DEFAULT_REL_BUILD_DIR))
parser.add_argument('--non-interactive', action='store_true')
parser.add_argument('--dev-environment', action='store_true')
parser.add_argument('--fake-pub-get-into', action='store', type=str)
args = parser.parse_args()
build_dir = os.path.abspath(args.build_dir)
sdk_root = os.path.abspath(args.sdk_root)
print 'Building SDK from %s into %s' % (build_dir, sdk_root)
start_time = datetime.now()
# These are separate ideas but don't need a separate flag yet.
use_links = args.dev_environment
skip_apks = args.dev_environment
should_commit = not args.dev_environment
generate_licenses = not args.dev_environment
# We save a bunch of time in --dev-environment mode by symlinking whole
# directories when possible. Any names which conflict with generated
# directories can't be symlinked and must be copied.
copy_or_link = link if use_links else copy
def sdk_path(rel_path):
return os.path.join(sdk_root, rel_path)
def src_path(rel_path):
return os.path.join(SRC_ROOT, rel_path)
ensure_dir_exists(sdk_root)
delete_all_non_hidden_files_in_directory(sdk_root, args.non_interactive)
# Manually clear sdk_root above to avoid deleting dot-files.
copy(src_path('sky/sdk'), sdk_root)
copy_or_link(src_path('sky/examples'), sdk_path('examples'),
sky_or_dart_filter)
# Sky package
copy_or_link(src_path('sky/framework'),
sdk_path('packages/sky/lib/framework'), sky_or_dart_filter)
copy_or_link(src_path('sky/assets'), sdk_path('packages/sky/lib/assets'))
# Copy gen files every time for now:
copy(os.path.join(build_dir, 'gen/sky'),
sdk_path('packages/sky/lib'), gen_filter)
# Not used in the dev environment.
copy_or_link(src_path('sky/sdk/tools/sky'),
sdk_path('packages/sky/bin/sky'))
# Mojo package, lots of overlap with gen, must be copied:
copy(src_path('mojo/public'), sdk_path('packages/mojo/lib/public'),
dart_filter)
copy(os.path.join(build_dir, 'gen/mojo'), sdk_path('packages/mojo/lib'),
gen_filter)
if not skip_apks:
ensure_dir_exists(sdk_path('apks'))
shutil.copy(os.path.join(build_dir, 'apks', 'SkyShell.apk'),
sdk_path('apks'))
if generate_licenses:
with open(sdk_path('LICENSES.sky'), 'w') as license_file:
subprocess.check_call([src_path('tools/licenses.py'), 'credits'],
stdout=license_file)
if args.fake_pub_get_into:
packages_dir = os.path.abspath(args.fake_pub_get_into)
ensure_dir_exists(packages_dir)
os.symlink(sdk_path('packages/mojo/lib'),
os.path.join(packages_dir, 'mojo'))
os.symlink(sdk_path('packages/sky/lib'),
os.path.join(packages_dir, 'sky'))
if should_commit:
# Kinda a hack to make a prettier build dir for the commit:
rel_build_dir = os.path.join(os.path.split(build_dir)[-2:])
subprocess.check_call(['git', 'add', '.'], cwd=sdk_root)
subprocess.check_call([
'git', 'commit',
'-m', '%s from %s' % (rel_build_dir, git_revision())
], cwd=sdk_root)
time_delta = datetime.now() - start_time
print 'SDK built at %s in %ss' % (sdk_root, time_delta.total_seconds())
if __name__ == '__main__':
main()

View File

@@ -139,13 +139,12 @@ class SkyDebugger(object):
return shell_command
def sky_server_for_args(self, args):
def sky_server_for_args(self, args, packages_root):
# FIXME: This is a hack. sky_server should just take a build_dir
# not a magical "configuration" name.
configuration = os.path.basename(os.path.normpath(self.paths.build_dir))
server_root = self._server_root_for_url(args.url_or_path)
sky_server = SkyServer(SKY_SERVER_PORT, configuration, server_root)
return sky_server
return SkyServer(SKY_SERVER_PORT, configuration, server_root, packages_root)
def _create_paths_for_build_dir(self, build_dir):
# skypy.paths.Paths takes a root-relative build_dir argument. :(
@@ -188,7 +187,18 @@ class SkyDebugger(object):
print "Cannot debug Release builds on Android"
sys.exit(2)
sky_server = self.sky_server_for_args(args)
sdk_root = os.path.join(self.paths.build_dir, 'gen', 'sky_sdk')
packages_root = os.path.join(sdk_root, 'packages_root')
subprocess.check_call([
os.path.join(self.paths.sky_tools_directory, 'deploy_sdk.py'),
'--build-dir', self.paths.build_dir,
'--non-interactive',
'--dev-environment',
'--fake-pub-get-into', packages_root,
sdk_root,
])
sky_server = self.sky_server_for_args(args, packages_root)
self.pids['sky_server_pid'] = sky_server.start()
self.pids['sky_server_port'] = sky_server.port
self.pids['sky_server_root'] = sky_server.root

View File

@@ -55,13 +55,16 @@ func main() {
// and they *must* be before any unnamed arguments. There are better ones:
// https://godoc.org/github.com/jessevdk/go-flags
// but for now we're using raw-go.
if flag.NArg() != 2 {
if flag.NArg() != 3 {
usage()
}
root, _ := filepath.Abs(flag.Arg(0))
port := flag.Arg(1)
packageRoot := flag.Arg(2)
// genRoot should not be needed once we figure out how mojom generation
// for sdk users should work.
genRoot := path.Join(root, "out", *configuration, "gen")
fmt.Fprintf(os.Stderr, "Mappings for localhost:%s:\n", port)
@@ -77,6 +80,7 @@ func main() {
})
addMapping("/gen/", genRoot)
addMapping("/packages/", packageRoot)
http.ListenAndServe(":" + port, nil)
}

View File

@@ -1 +1 @@
00d7f2d6508392278439de82914b9299a85632c1
85445bf6bfa001659deac3ab98a86475952f5291

View File

@@ -13,10 +13,11 @@ SKY_ROOT = os.path.dirname(SKY_TOOLS_PATH)
SRC_ROOT = os.path.dirname(SKY_ROOT)
class SkyServer(object):
def __init__(self, port, configuration, root):
def __init__(self, port, configuration, root, package_root):
self.port = port
self.configuration = configuration
self.root = root
self.package_root = package_root
self.server = None
@staticmethod
@@ -42,6 +43,7 @@ class SkyServer(object):
'-t', self.configuration,
self.root,
str(self.port),
self.package_root,
]
self.server = subprocess.Popen(server_command)
return self.server.pid