diff --git a/sky/build/PackagerInvoke b/sky/build/PackagerInvoke new file mode 100755 index 00000000000..b2bf658e6da --- /dev/null +++ b/sky/build/PackagerInvoke @@ -0,0 +1,82 @@ +#!/bin/sh +# 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. + +RunCommand() { + $@ >/dev/null + return $? +} + +EchoError() { + echo "$@" 1>&2 +} + +AssertExists() { + RunCommand ls $1 + if [ $? -ne 0 ]; then + EchoError "The path $1 does not exist" + exit -1 + fi + return 0 +} + +PackageProject() { + # Check that the project path was specified + if [[ -z "$1" ]]; then + EchoError "Project path not specified" + exit -1 + fi + + # Check if pub exists + RunCommand which pub + if [[ $? -ne 0 ]]; then + EchoError "Could not find 'pub'." + EchoError "Did you install the Dart SDK?" + exit -1 + fi + + local pub_path="$(which pub)" + + AssertExists $1 + local project_path=$1 + + local derived_dir=${SOURCE_ROOT}/FlutterApplication/Generated + RunCommand mkdir -p $derived_dir + AssertExists $derived_dir + + local dart_main=${project_path}/lib/main.dart + AssertExists $dart_main + + local package_root=${project_path}/packages + AssertExists $package_root + + local icons_path=${project_path}/packages/material_design_icons/icons + AssertExists $icons_path + + # Remove old build artifacts + RunCommand rm -f ${derived_dir}/app.flx + + # Generate the new FLX file. The pub command must be run from the directory + # containing the pubspec + RunCommand pushd ${project_path} + + RunCommand ${pub_path} run sky_tools build \ + --asset-base ${icons_path} \ + --main ${dart_main} \ + --output-file ${derived_dir}/app.flx \ + --package-root ${package_root} \ + --precompiled + + if [[ $? -ne 0 ]]; then + EchoError "Failed to package $1 ..." + exit -1 + fi + + RunCommand popd + + echo "Project $1 successfully packaged..." + return 0 +} + +PackageProject $1 diff --git a/sky/build/SnapshotterInvoke b/sky/build/SnapshotterInvoke new file mode 100755 index 00000000000..96903c2be30 --- /dev/null +++ b/sky/build/SnapshotterInvoke @@ -0,0 +1,154 @@ +#!/bin/sh +# 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. + +RunCommand() { + $@ >/dev/null + return $? +} + +EchoError() { + echo "$@" 1>&2 +} + +AssertExists() { + RunCommand ls $1 + if [ $? -ne 0 ]; then + EchoError "The path $1 does not exist" + exit -1 + fi + return 0 +} + +GenerateBinaryInclude() { + local input=$1 + local output=$2 + + AssertExists ${input} + + # Check that an input file was specified + if [[ -z "${output}" ]]; then + EchoError "Isolate buffer output file unspecified" + exit -1 + fi + + # Check that xxd is available on the system + RunCommand which xxd + if [[ $? -ne 0 ]]; then + EchoError "Could not find |xxd| to generate buffers for ${input}" + exit -1 + fi + + # Remove old build artifacts + RunCommand rm -f #{output} + + # Since there is no flag to specify the symbol name to xxd, we change to the + # directory of the input file and invoke xxd from there + RunCommand pushd $(dirname ${input}) + + local input_basename=${input##*/} + RunCommand xxd --include ${input_basename} ${output} + if [[ $? -ne 0 ]]; then + EchoError "|xxd| invocation failed to generate ${output}" + fi + + RunCommand popd + + AssertExists $2 +} + +SnapshotProject() { + # Check that the caller has provided a project path + if [[ -z "$1" ]]; then + EchoError "The path to the dart project must be specified" + exit -1 + fi + + local project_path="$1" + + # Check if 'pub get' has been run + RunCommand ls ${project_path}/packages + if [ $? -ne 0 ]; then + EchoError "The project does not have a packages directory" + EchoError "Did you forget to run 'pub get'?" + exit -1 + fi + + local packages=${project_path}/packages + + # Resolve symlinks to point to the url mapping values + + # For dart:mojo.internal + local mojo_internal_path="$(readlink ${packages}/mojo)/../sdk_ext/internal.dart" + AssertExists $mojo_internal_path + + # For dart:ui_internals + local ui_internals_path="$(readlink ${packages}/sky_engine)/../sdk_ext/internals.dart" + AssertExists $ui_internals_path + + # For dart:ui + local ui_path="$(readlink ${packages}/sky_engine)/../sdk_ext/dart_ui.dart" + AssertExists $ui_path + + # FIXME: Publish vmservice_sky + # local vm_service_path="needs/to/be/published" + # AssertExists $vm_service_path + + local main_path="${project_path}/lib/main.dart" + AssertExists $main_path + + local src_dir=${SOURCE_ROOT}/Tools + local derived_dir=${SOURCE_ROOT}/FlutterApplication/Generated + + RunCommand mkdir -p $derived_dir + + AssertExists $src_dir + AssertExists $derived_dir + + # Remove old build artifacts + RunCommand rm -f ${derived_dir}/kDartVmIsolateSnapshotBuffer.c + RunCommand rm -f ${derived_dir}/kDartIsolateSnapshotBuffer.c + RunCommand rm -f ${derived_dir}/InstructionsSnapshot.S + + # Finally! Generate the snapshot. The instructions buffer is already in an + # assembly file which can be directly used by the linker. For the VM isolate + # snapshot buffer and isolate snapshot buffer, we name the file to match + # the name of the symbol the VM expects at runtime. On these binary files, + # we invoke xxd. + RunCommand ${src_dir}/Snapshotter \ + --vm_isolate_snapshot=${derived_dir}/kDartVmIsolateSnapshotBuffer \ + --isolate_snapshot=${derived_dir}/kDartIsolateSnapshotBuffer \ + --instructions_snapshot=${derived_dir}/InstructionsSnapshot.S \ + --embedder_entry_points_manifest=${src_dir}/EmbedderEntryPoints \ + --package_root=${packages} \ + --url_mapping=dart:mojo.internal,${mojo_internal_path} \ + --url_mapping=dart:ui,${ui_path} \ + --url_mapping=dart:ui_internals,${ui_internals_path} \ + --url_mapping=dart:vmservice_sky,$vm_service_path \ + $main_path + + if [[ $? -ne 0 ]]; then + EchoError "Snapshotter failed for $1 ..." + exit -1 + fi + + # The instruction buffer is already generated, the isolates need to be packed + # into C files + GenerateBinaryInclude \ + ${derived_dir}/kDartVmIsolateSnapshotBuffer \ + ${derived_dir}/kDartVmIsolateSnapshotBuffer.c \ + + GenerateBinaryInclude \ + ${derived_dir}/kDartIsolateSnapshotBuffer \ + ${derived_dir}/kDartIsolateSnapshotBuffer.c \ + + + # Remove intermediate build artifacts + RunCommand rm -f ${derived_dir}/kDartVmIsolateSnapshotBuffer + RunCommand rm -f ${derived_dir}/kDartIsolateSnapshotBuffer + + return $? +} + +SnapshotProject $1