| #!/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 |
| |
| # For dart:vmservice_sky |
| local vm_service_path="$(readlink ${packages}/sky_engine)/../sdk_ext/core/script/dart_service_isolate/main.dart" |
| 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 |
| |
| echo "Precompilation snapshot successfully created for ${project_path} ..." |
| |
| return $? |
| } |
| |
| SnapshotProject $1 |